Win32 API Create pop up window

Could someone please point me to a decent tutorial on how to create a pop up window.

All the tutorials I have found are about maintaining a single window, or they are questions on how to create secondary windows with no real explanation( to me ) as I don't know as much as they do!

If you don't know any decent tutorials, and are willing to help me learn this, here's what I have:

I have an about button, and I want a pop-up window to appear when I click the button.
http://s749.photobucket.com/albums/xx132/Bigdave876/Cpp/?action=view&current=me.jpg

I just want a popup to cover what's already in the window.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
case IDC_ABOUT_BUTTON:
	{
		HWND about = CreateWindowEx( WS_EX_TOPMOST,
					szWindowClass, //I know this is the Parent window, and it displays a copy of that window.
					L"About",
					WS_POPUP,
					150, 150,// not yet set correctly
					200, 200,// just testing until I get the correct window
					hWnd, NULL,
					hInst, NULL );

		if( ! about )
		{
			MessageBox( hWnd, L"Error creating window\nPop-Up", L"Error", MB_ICONEXCLAMATION );
			PostQuitMessage(0);
		}

		ShowWindow( about, SW_SHOW );
		UpdateWindow( about );

		break;
	}


How do I go about creating another instance/class( if I need to? ) to display the pop up window?

Thanks for any help!
Last edited on
Dialog boxes are basically designed to be child or popup windows. Here's a short example:

resource.h
1
2
3
4
5
6
7
8
#include <windows.h>

// Dialog id
#define DLG_ABOUT   1000

// Control ids
#define ED_ABOUT    1001
#define BTN_OK      1002 


resource.rc
1
2
3
4
5
6
7
8
#include "resource.h"

DLG_ABOUT DIALOGEX 100,100,350,150
STYLE WS_VISIBLE
BEGIN
  CONTROL "",ED_ABOUT,"Static",WS_CHILD|WS_VISIBLE|SS_CENTER,4,4,340,115
  CONTROL "&OK",BTN_OK,"Button",WS_VISIBLE|WS_CHILD,155,120,50,15
END


main.cpp
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
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "resource.h"

BOOL CALLBACK DialogProc(HWND H,UINT M,WPARAM W,LPARAM L)
{
  switch(M)
  {
    case WM_INITDIALOG:
    {
      SetDlgItemText(H,ED_ABOUT,"\n\nThis is my about dialog.\nPress OK to Quit.");
      return TRUE;
    }
    case WM_COMMAND:
    {
      switch(LOWORD(W))
      {
        case BTN_OK:
        {
          EndDialog(H,0);
          return TRUE;
        }
      }
    }
  }
  return FALSE;
}

int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdStr, int CmdInt)
{
  return DialogBox(hInst,MAKEINTRESOURCE(DLG_ABOUT),0,DialogProc); // If you want a parent window to own the dialog box put its HWND as the 3rd parameter
}
If all you want is a simple text message you could always use MessageBox() as well to keep it ultra simple.
Thanks for the replys. I never thought about using a message box :/

I'm done with this program now, so I'll just use the message box for now. But I'll implement the other code in to the next program I'm making.

Again, thanks for the info, it's greatly appreciated!
Last edited on
This one really helped me. It's pretty much the default WIN32 tutorial around. It's written in C but the API is in C so it's completely compatible.

http://www.winprog.org/tutorial/
Topic archived. No new replies allowed.