I want to create multiple windows and not child window, possible?

I have been trying to create windows like we all do with winMain. However, the first window created using (HMENU) 0 in createwindow works fine, then the next part i am stuck, because when i try to change the value of HMENU for another window the program does nothing visible when tried to run this new window.

follow me??

simple explanation - main window A, creates B window, which in turn creates C 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
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
	//Window class declaration
	static TCHAR szAppName[] = TEXT ("Gaze Tracker program");
	MSG msg;
	WNDCLASS GazeTrackerMouse;

	long Screen_Res_X = GetSystemMetrics ( SM_CXSCREEN );		//Screen size in x-axis
	long Screen_Res_Y = GetSystemMetrics ( SM_CYSCREEN );		//Screen size in y-axis

	GazeTrackerMouse.cbClsExtra	= 0;
	GazeTrackerMouse.cbWndExtra	= 0;
	GazeTrackerMouse.hbrBackground	= (HBRUSH) GetStockObject (WHITE_BRUSH);
	GazeTrackerMouse.hCursor	= LoadCursor (NULL, IDC_ARROW);
	GazeTrackerMouse.hIcon		= LoadIcon (NULL, IDI_APPLICATION);
	GazeTrackerMouse.hInstance	= hInstance;
	GazeTrackerMouse.lpfnWndProc	= WndProc;
	GazeTrackerMouse.lpszClassName	= szAppName;
	GazeTrackerMouse.lpszMenuName	= NULL;
	GazeTrackerMouse.style		= CS_HREDRAW | CS_VREDRAW;

	if (!RegisterClass (&GazeTrackerMouse))
	{
		MessageBox (NULL, TEXT ("Did not register window class"), szAppName, MB_ICONERROR);	
		return 0;
	}

	ehwnd = CreateWindowEx (
				 WS_EX_TOPMOST,
				 szAppName,
				 TEXT ("Gaze Tracker Mouse v2"),
				 WS_OVERLAPPEDWINDOW,
				 Screen_Res_X - 200,
				 Screen_Res_Y - (Screen_Res_Y - 50),
				 200,
				 Screen_Res_Y - 150,
				 NULL,
				 NULL,
				 hInstance,
				 NULL
				);

	hInst = hInstance;

	ShowWindow (ehwnd, iCmdShow);
	UpdateWindow (ehwnd);
	

	while (GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage (&msg);
		DispatchMessage (&msg);
	}

	return msg.wParam;
}


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
void CreateOnScreenKeyboardwin(HWND hwnd, HINSTANCE hInst)
{
	static TCHAR szAppName[] = TEXT ("GTKeyboard");
	WNDCLASS Scroll;
	
	Scroll.lpszClassName		= szAppName;
	Scroll.lpfnWndProc		= OnScreenKeyboardProc;
	Scroll.hbrBackground		= (HBRUSH) GetStockObject(WHITE_BRUSH);
	Scroll.hIcon			= LoadIcon (NULL, IDI_APPLICATION);
	Scroll.hCursor			= LoadCursor (NULL, IDC_ARROW);
	Scroll.hInstance		= hInst;
	Scroll.style			= CS_HREDRAW | CS_VREDRAW;
	Scroll.cbClsExtra		= 0;
	Scroll.cbWndExtra		= 0;
	Scroll.lpszMenuName		= NULL;

	RegisterClass (&Scroll);

	int Screen_Res_X = GetSystemMetrics ( SM_CXSCREEN );		//Screen size in x-axis
	int Screen_Res_Y = GetSystemMetrics ( SM_CYSCREEN );		//Screen size in y-axis

	Parenthwnd = hwnd;

	hwndKeyboard = CreateWindowEx (
				 WS_EX_NOACTIVATE,
				 TEXT ("GTKeyboard"),
				 TEXT ("Gaze Tracker Mouse Keyboard"),
				 WS_OVERLAPPEDWINDOW,
				 Screen_Res_X - 835,
				 Screen_Res_Y - 350,
				 825,	//RATIO x:y 2.75
				 300,			
				 hwnd,
				 (HMENU) 0,
				 hInst,
				 NULL
				);
				
	ShowWindow (hwndKeyboard, SW_SHOWNOACTIVATE);
	UpdateWindow (hwndKeyboard);
}

On screen keyboard 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
void WebBrowser(HWND hwnd, HINSTANCE hInst, LPARAM lParam)
{
	static TCHAR szAppName[] = TEXT ("WebBrowser");
	WNDCLASS WebBrowser;

	long Screen_Res_X = GetSystemMetrics ( SM_CXSCREEN );		//Screen size in x-axis
	long Screen_Res_Y = GetSystemMetrics ( SM_CYSCREEN );		//Screen size in y-axis

	hwndParent = hwnd;

	WebBrowser.lpszClassName	= szAppName;
	WebBrowser.lpfnWndProc		= WebBrowserProc;
	WebBrowser.style		= CS_HREDRAW | CS_VREDRAW;
	WebBrowser.hbrBackground	= (HBRUSH) GetStockObject ( WHITE_BRUSH);
	WebBrowser.hCursor		= LoadCursor (NULL, IDC_ARROW);
	WebBrowser.hIcon		= LoadIcon (NULL, IDI_APPLICATION);
	WebBrowser.hInstance		= hInst;
	WebBrowser.cbClsExtra		= 0;
	WebBrowser.cbWndExtra		= 0;
	WebBrowser.lpszMenuName		= NULL;

	RegisterClass (&WebBrowser);


	hwndWebBrowser = CreateWindowEx(
					WS_EX_NOACTIVATE,
					szAppName,
					TEXT ("Gaze Tracker Mouse - WebBrowser"),
					WS_OVERLAPPEDWINDOW,
					0,
					25,
					Screen_Res_X,
					65,
					hwnd,
					(HMENU) 0,
					hInst,
					NULL
					);

	ShowWindow (hwndWebBrowser, SW_SHOWNORMAL);
	UpdateWindow (hwndWebBrowser);
}

window for easier browsing on IE

main opens browser window which then can open on screen keyboard window. but i cant open keyboard. however, it opens fine without the browser window

ps sorry forgot to put the code in :P
Last edited on
wheres the problem?... where is your code?:P...
(HMENU)0 is the id you use for a top level window. You can create as many of these as you can stand. You can create 'em in a loop if you want; all with (HMENU)0 for the HMENU parameter. zero is the equate for the desktop. HWND_DESKTOP=0 or something like that, just off the top of my head.

Just remember, if you do it in a loop with the same coordinates they'll all stack on top of one another in the z order.
Last edited on
That is true freddie1. However, it is only true when you create the same window. eg i click a button to open keyboard, and a couple more times, it opens a few keyboards depending on how many. When u try to create two different windows, the my program freezes somehow. On task manager it reads 100%load on cpu ???
I think freddie1 comment is incorrect.
That particular parameter is one of two things:

1. If the window being created is a child window (WS_CHILD style) that parameter is the child window ID.
2. If the window being created is a toplevel window (for example WS_OVERLAPPEDWINDOW), then it is the handle of the menu for the window.

To jcylam - can you post all of your code???? - then we can run it and see.
ermm i would but it would took up three to four pages of codes, as i have 5, 6 source and headers each.

i will try minimize the code so only essentials are posted. give me sometime.
What are you after ???
creating 3 frame windows?
you need to create them before you start the message loop, or when you process WM_CREATE of the first window.
Your post is very unclear

P.S. guestgulkan is right, HMENU is a menu if you are creating a top level window (not a child)
"simple explanation - main window A, creates B window, which in turn creates C window."

so zippo do i register all of the wndclass in the winmain? then create them but have them hidden?
Last edited on
hi, i just want to check with you guys, is there anything wrong with my WNDCLASS and registering and CreateWindow functions?

i was trying to minimize the code to upload, and discovered that i used to be able to open multiple keyboards and now it freezes when tried to open a second.
very weird thing, i copied my codes to a new project solution bits by bits to check which codes are messing up the program. funny thing is the copied codes works fine.
Topic archived. No new replies allowed.