实现结果:
方法一:通过CreateWindowsEx函数实现
HMENU m_hMenu1; m_hMenu1 = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU1));//IDR_MENU1是你资源文件的菜单ID hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"WindowClass", L"Carrot", WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 720, 580, NULL, m_hMenu1 , hInstance, NULL);方法二
通过SetMenu函数实现
通过这种方式可以动态设置菜单
HMENU m_hMenu1; m_hMenu1 = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU1)); hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"WindowClass", L"Carrot", WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 720, 580, NULL, NULL , hInstance, NULL); SetMenu(hwnd, m_hMenu1);方法三
通过WNDCLASSEX类实现
WNDCLASSEX wc; memset(&wc, 0, sizeof(wc)); wc.style = 0; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.cbSize = sizeof(WNDCLASSEX); wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszClassName = L"WindowClass"; wc.lpszMenuName = L"IDR_MEMU1"; //你的菜单ID if (!RegisterClassEx(&wc)) { //注册Windows类 MessageBox(NULL, L"Window Registration Failed!", L"Error!", MB_IConEXCLAMATION | MB_OK); return 0; }
如果有什么问题,欢迎讨论。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)