新手提问:为什么加了对话框后,MessageBox显示不出来?
以下是源程序,*********夹着的是要显示的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;
}