#include <Windows.h>
HINSTANCE g_hInstance;
HANDLE g_hStdOut;
void OnCreate(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
HMENU hMainMenu = CreateMenu();
HMENU hFileMenu = CreatePopupMenu();
AppendMenu(hFileMenu,MF_STRING|MF_CHECKED,1001,TEXT("新建(&N)"));
AppendMenu(hFileMenu,MF_STRING,1002,TEXT("保存(&S)"));
AppendMenu(hFileMenu,MF_SEPARATOR,0,NULL);
AppendMenu(hFileMenu,MF_STRING,1003,TEXT("退出(&X)"));
AppendMenu(hMainMenu,MF_STRING|MF_POPUP,(UINT)hFileMenu,TEXT("文件(&F)"));
HMENU hEditMenu = CreatePopupMenu();
AppendMenu(hEditMenu,MF_STRING,1004,TEXT("编辑(&T)"));
AppendMenu(hEditMenu,MF_STRING,1005,TEXT("复制(&C)"));
AppendMenu(hEditMenu,MF_STRING,1006,TEXT("粘贴(&P)"));
AppendMenu(hMainMenu,MF_STRING|MF_POPUP,(UINT)hEditMenu,TEXT("编辑(&E)"));
HMENU hHelpMenu = CreatePopupMenu();
AppendMenu(hHelpMenu,MF_STRING,1007,TEXT("注册(&H)"));
AppendMenu(hHelpMenu,MF_STRING,1008,TEXT("关于(&A)"));
AppendMenu(hMainMenu,MF_STRING|MF_POPUP,(UINT)hHelpMenu,TEXT("帮助(&H)"));
SetMenu(hWnd,hMainMenu);
}
void OnCommand(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(wParam)
{
case 1003:
{
PostMessage(hWnd,WM_QUIT,0,0);
break;
}
}
}
LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch(uMsg)
{
case WM_CREATE:
OnCreate(hWnd,uMsg,wParam,lParam);
break;
case WM_COMMAND:
OnCommand(hWnd,uMsg,wParam,lParam);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
void RegisterWnd(LPCTSTR lpClassName)
{
WNDCLASSEX wce;
wce.style = CS_HREDRAW|CS_VREDRAW;
wce.lpfnWndProc = WndProc;
wce.cbSize = sizeof(WNDCLASSEX);
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hInstance = g_hInstance;
wce.hIcon = 0;
wce.hCursor = 0;
wce.hIconSm = 0;
wce.hbrBackground = HBRUSH(COLOR_BTNFACE);
wce.lpszClassName = lpClassName;
wce.lpszMenuName = 0;
if(!RegisterClassEx(&wce))
{
MessageBox(NULL,TEXT("注册失败"),TEXT("提示"),MB_OK);
}
}
HWND CreateWnd(LPCTSTR lpClassName)
{
HWND hWnd = CreateWindowEx(0,lpClassName,L"鱼C记事本",
WS_OVERLAPPEDWINDOW,500,200,
600,400,NULL,NULL,g_hInstance,NULL);
return hWnd;
}
void DisplayWnd(HWND hWnd)
{
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
}
void Message()
{
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
g_hInstance = hInstance;
RegisterWnd(L"拈花小仙");
HWND hWnd = CreateWnd(L"拈花小仙");
DisplayWnd(hWnd);
Message();
return 0;
}