Simple question - creating a new window

Newbie to the win32api, what I'm trying to do is have my app replace the contents of a window, or create a new popup window when a button is pressed.

What I do is get the wparam that gets sent to WM_COMMAND to identify which button was pushed, and then I try to run a CreateWindow function, but nothing happens. I've confirmed that message boxes and dialog boxes work, but the CreateWindow function doesn't.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
                {
		case BUTTON_ID:
			//DialogBox(hInst, MAKEINTRESOURCE(Newswin), hWnd, Newswin);
			NewWin = CreateWindow( L"label", L"text",
                        WS_CHILD | WS_POPUP,
                        CW_USERDEFAULT, CW_USERDEFAULT, 
                        800, 400,
                        hWnd, NULL,
                        hInst, NULL );
			break;


What is it that I'm not understanding?
According to MSDN documentation,
WS_CHILD
0x40000000L



The window is a child window. A window with this style cannot have a menu bar. This style cannot be used with the WS_POPUP style.


http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600%28v=vs.85%29.aspx
Hi, thanks for the reply.

I've done some further investigating into this matter, and found that while that is an issue, it's not the source of the error. I'll post what I did to get the window to pop up, but I'm still having multiple problems such as : The menu bar doesn't show (and yes i changed WS_CHILD to WS_CHILDWINDOW), the exit code closes both the main window and the child window (regardless of which window sends the command), and the new window has all the properties of the parent window (I wanted a fresh window).

My changes :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		case BUTTON_ID:
			//DialogBox(hInst, MAKEINTRESOURCE(Newswin), hWnd, Newswin);
			if (!InitNewwin (hInst, 1))
			{
				return FALSE;
			}
			break;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
BOOL InitNewwin(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   static TCHAR szTitle[] = _T("Title of my window");

   hWnd = CreateWindow(szWindowClass, L"Window", WS_POPUPWINDOW | WS_CHILDWINDOW| WS_CAPTION,
      100, 100, 820, 400, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}
Topic archived. No new replies allowed.