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); 
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值