win32 popup dialog


I just want a popup to cover what's already in the window.

	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?
 

Dialog boxes are basically designed to be child or popup windows. Here's a short example:

resource.h

 
#include <windows.h>

// Dialog id
#define DLG_ABOUT   1000

// Control ids
#define ED_ABOUT    1001
#define BTN_OK      1002 
 
#include <windows.h> 
// Dialog id 
#define DLG_ABOUT 1000 
// Control ids 
#define ED_ABOUT 1001 
#define BTN_OK 1002



resource.rc

#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

#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) {
    // If you want a parent window to own the dialog box put its HWND as the 3rd parameter 
    return DialogBox(hInst,MAKEINTRESOURCE(DLG_ABOUT),0,DialogProc); 
}

 

Guess you like

Origin blog.csdn.net/mzr122/article/details/102911573