Child window ID's not recognized by GetDlgItem()

My code creates some windows that are children of the main app window. The child windows are assigned child-window identifiers through the hMenu parameter of the CreateWindow function. However, only the child windows with a child-window identifier that is a multiple of 4 can be retrieved by a call to GetDlgItem(). It also happens that the HWND's retrieved by GetDlgItem() for child window identifiers 5000,5004,5008 correspond to the three first created children.
If this is how the code should work, is there a way to assign arbitrary child-window IDs to children of the same window?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <windows.h>
#include "stdio.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    LPSTR lpCmdLine, int nCmdShow )
{
  MSG  msg ;    
  HWND hwnd;
  WNDCLASS wc;
	
  wc.style         = CS_HREDRAW | CS_VREDRAW;
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = 0;
  wc.lpszClassName = TEXT( "Window" );
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpszMenuName  = NULL;
  wc.lpfnWndProc   = WndProc;
  wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  
  RegisterClass(&wc);
  hwnd = CreateWindow( wc.lpszClassName, TEXT("Window"),
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                100, 100, 250, 150, NULL, NULL, hInstance, NULL);  

  ShowWindow(hwnd, nCmdShow);
  UpdateWindow(hwnd);

  while( GetMessage(&msg, NULL, 0, 0)) {
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
  switch(msg){
	
	case WM_CREATE:
		
		for(int i=0;i<10;i++){
			HWND hwtemp;
			char buff[80];
			
			sprintf(buff,"Static %d",i);
			CreateWindow(
				TEXT("static"),
				buff,
	    			WS_VISIBLE | WS_CHILD ,
	        		10,10+i*15,100,15,
		       		hwnd,
				(HMENU)5000+i,
				NULL,NULL
			);
			hwtemp=
				GetDlgItem(hwnd,5000+i);
			if(!hwtemp){
				DWORD err=GetLastError();
				sprintf(buff,"Error 0x%x getting window %d",err,i);
				MessageBox(NULL,buff,buff,MB_ICONHAND);
			}
		}
		break;
	
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}

closed account (DSLq5Di1)
1
2
3
4
5
6
7
8
9
			CreateWindow(
				TEXT("static"),
				buff,
	    			WS_VISIBLE | WS_CHILD ,
	        		10,10+i*15,100,15,
		       		hwnd,
				(HMENU)5000+i,
				NULL,NULL
			);

Pointer arithmetic, the c-style cast has priority. Wrap your expression in parentheses. Alternatively, prefer a c++ style cast. http://en.wikipedia.org/wiki/Static_cast
So, HMENU is actually a pointer? I'd never guess it... Thank you very much.
Topic archived. No new replies allowed.