SDK菜单创建 CreateMenu的使用 ——如果回复的多的话,小仙努力写个记事本
本帖最后由 拈花小仙 于 2014-11-22 20:03 编辑#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;
}
@Angel丶L {:7_139:}一个简单的界面哈~ 来看看学习下。 {:5_106:}要是有图就更好了~~~~ 小甲鱼的二师兄 发表于 2014-11-22 18:56
要是有图就更好了~~~~
{:7_139:}遵二师伯命,已上传图片,只因太过简单才没上图的~ SDK写这个难度可不是一般的大,麻烦
,mfc还好 qq351317878 发表于 2014-11-22 20:33
SDK写这个难度可不是一般的大,麻烦
,mfc还好
{:7_139:}感觉很容易呀,就是浪时间,MFC不用写,直接鼠标就行哈~ 拈花小仙 发表于 2014-11-22 20:48
感觉很容易呀,就是浪时间,MFC不用写,直接鼠标就行哈~
得记住好多东西 ,太累{:5_96:} 我去,牛逼的嘞!源代码求一份!:lol: 感谢楼主的分享!!!!! :sweat::sweat::sweat: 学习
页:
[1]