#include<windows.h>
#include<"7_4.h"
HWND hdlg;//对话框句柄
HINSTANCE hInst;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK DlgProc(HWND,UINT,WPARAM,LPARAM);//定义消息框处理函数
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
HACCEL hAccel;
WNDCLASS wndclass;
char lpszMenuName[]="Menu";
char lpszClassName[]="非模态对话框";
char lpszTitle[]="非模态对话框演示程序";
wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbWndExtra=0;
wndclass.cbClsExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=lpszMenuName;
wndclass.lpszClassName=lpszClassName;
if(!RegisterClass(&Wndclass))
{
MessageBeep(0);
return FALSE;
}
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))
{
//截获非模态对话框消息并发往处理函数
if(!IsDialogMessage(hdlg,&Msg))
{
if(!TranslateAccelerator(hwnd,hAccel,&Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_NEW:
MessageBox(hwnd,"文件创建成功!","文件创建",MB_OK);
break;
case IDM_OPEN:
MessageBox(hwnd,"文件打开成功!","文件打开",MB_OK);
break;
case IDM_SAVE:
MessageBox(hwnd,"文件保存成功"!","文件保存",MB_OK);
break;
case IDM_SAVEAS:
break;
case IDM_CLOSE:
break;
case IDM_EXIT:
SendMessage(hwnd,WM_DESTROY,0,0);
break;
case IDM_ABOUT:
//调用函数CreateDialog创建非模态对话框
hdlg=CreateDialog(hInst,"About",hwnd,(DLGPROC)DlgProc);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
brak;
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 1;
//处理消息框消息
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
//关闭消息框
DestroyWindow(hdlg);
return 1;
}
break;
case WM_CLOSE:
DestroyWindow(hdlg);
return 1;
}
return 0;
}