1 Star 1 Fork 0

gxzxh/win32编程

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
09__显示右键菜单.cpp 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
gxzxh 提交于 2023-06-12 19:23 +08:00 . windows窗口程序
#include <windows.h>
#include "resource.h"
//窗口处理函数(自定义,处理消息)
LRESULT CALLBACK WinProc(HWND hWnd,UINT msgID, WPARAM wParam, LPARAM lParam){
HINSTANCE hAppInst = GetModuleHandle(NULL);
HMENU hMain = LoadMenu(hAppInst, (char *)IDR_MENU1);
HMENU hPopup = GetSubMenu(hMain, 0);//获取子菜单
switch (msgID){
case WM_CONTEXTMENU://处理弹出式菜单
TrackPopupMenu(hPopup,TPM_CENTERALIGN | TPM_VCENTERALIGN,
LOWORD(lParam), HIWORD(lParam),0,hWnd,NULL);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd,msgID,wParam,lParam);
}
//入口函数
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ipCmdLine, int nCmdShow){
//hAppInst = hInstance;
//注册窗口类
WNDCLASSEX wc;
memset (& wc, 0, sizeof wc); //将 wc 清零
wc.cbSize = sizeof (WNDCLASSEX); //变量所占字节数
wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; //窗口风格
wc.hInstance = hInstance; //当前进程实例句柄
wc.lpszClassName = "Main"; //窗口类名
wc.lpfnWndProc = WinProc; //窗口处理函数
wc.hbrBackground = GetSysColorBrush (COLOR_WINDOW); //窗口的背景
wc.lpszMenuName = (char *)IDR_MENU1;
if (!RegisterClassEx (& wc)) return 0;
//创建窗口
HWND hWnd = CreateWindowEx(0, "Main", "Window", WS_OVERLAPPEDWINDOW,
100, 100, 500, 500, NULL, NULL, hInstance, NULL);
//显示窗口
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
//消息循环
MSG nMsg = {0};
while(GetMessage(&nMsg, NULL, 0, 0)){
TranslateMessage(&nMsg);
DispatchMessage(&nMsg);//将消息交给窗口处理函数
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/gxzxh/Windows-programming.git
git@gitee.com:gxzxh/Windows-programming.git
gxzxh
Windows-programming
win32编程
master

搜索帮助

371d5123 14472233 46e8bd33 14472233