#include<windows.h>
#include"7_3.h"
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.cbClsExtra=0;
wndclass.cbWndExtra=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(lpszzClassName,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(!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:
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_CUT:
break;
case IDM_COPY:
break;
case IDM_PASTE:
break;
case IDM_DELETE:
break;
case IDM_ABOUT:
DialogBox("hInst,"About",hwnd,(DLGPROC)DlgProc);//创建对话框
break;
}
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_INITDLADLG:
return 1;
//处理对话框消息
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
//关闭对话框
EndDialog(hdlg,0);
return 1;
}
break;
case WM_CLOSE:
EndDialog(hdlg,0);
return 1;
}
return 0;
}