新手提问:为什么加了对话框后,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;
}
相关推荐
C#实现winform自动关闭MessageBox对话框的方法
主要介绍了C#实现winform自动关闭MessageBox对话框的方法,实例分析了C#中MessageBox对话框的相关操作技巧,需要的朋友可以参考下
Wincc中弹出对话框函数MessageBox参数以及应用
Wincc中弹出对话框函数MessageBox参数以及应用
Extjs Ext.MessageBox.confirm 确认对话框详解
Ext.MessageBox.confirm&#40;&#41;详解 显示一个确认对话框,用来代替JavaScript标准的confirm&#40;&#41;方法,具有两个按钮“是”和“否”如果为其提供一个回调函数,则该函数将在单击按钮后被调用(包括右上角的推出按钮),所单击按钮的id将被作为唯一的参数传递到回调函数中。 调用格式: confirm&#40;String title,String msg,[function fn],[Object scope]&#41; 参数说明: Ext.MessageBox.alert&#40;&#41;;//相关内容 返回值: Ext.MessageBox 代码示例: 代码如下: &lt;script type=”tex
C#版 MessageboxTimeout-自动关闭messagebox 消息对话框
C#版 MessageboxTimeout-自动关闭messagebox 消息对话框 实现了messagebox 对话框自动关闭,可以自由设定等待几秒后自动关闭。 内附使用说明
MFC MessageBox用法及举例
主要讲解如何使用MessageBox显示各种各样的消息,并有详尽的案例,可能遇到的问题,以及解决办法。


