新手提问:为什么加了对话框后,MessageBox显示不出来?

long33 long33 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
以下是源程序,*********夹着的是要显示的MessageBox
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include "resource.h"


HWND hDlg;
HINSTANCE hInst;

//declarations
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK DlgProc(HWND,UINT,WPARAM,LPARAM);


//WinMain function
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG msg;
HACCEL hAccel;
WNDCLASS wndclass;

char lpszClassName[] = "Dialog";
char lpszTitle[] = "Dialog";
char lpszMenuName[] = "Menu";

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

RegisterClass(&wndclass);


hwnd = CreateWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);

hInst = hInstance;
hAccel = LoadAccelerators(hInst,lpszMenuName);


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

}

return msg.wParam;
}

//message function
LRESULT CALLBACK WndProc( HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_NEW:
//////////**********************************************************
///////// 就这里,加载了,但是显示不出来,这是为什么?
MessageBox(hwnd,"Open","Open",MB_OK);
/////////***********************************************************
break;
case IDM_EXIT:
SendMessage(hwnd,WM_DESTROY,0,0);
break;
case IDM_ABOUT:
DialogBox(hInst,"About",hwnd,(DLGPROC)DlgProc);
break;
}
break;

case WM_PAINT:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}

BOOL CALLBACK DlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
return true;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hdlg,0);
return true;
}
break;
case WM_CLOSE:
EndDialog(hdlg,0);
return true;
}
return false;
}
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
long33
VC/MFC 16,550 成员 421,606 内容