Win32问答之菜单篇

    技术2022-05-11  155

    小辉论坛精华贴

    我编辑了一个菜单名字为“GSF”,但在程序中却不显示。在程序中我这样定义:wndclass.lpszMenuName = "GSF" 是不是还有哪个语句没有定义???

    附:原程序#include <windows.h>

    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[] = TEXT ("HelloWin") ;HWND hwnd ;MSG msg ;WNDCLASS wndclass ;

    wndclass.style = CS_HREDRAW | CS_VREDRAW ;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 = (HBRUSH) GetStockObject (WHITE_BRUSH) ;wndclass.lpszMenuName = "GSF" ;wndclass.lpszClassName = szAppName ;

    if (!RegisterClass (&wndclass)){MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ;return 0 ;}hwnd = CreateWindow (szAppName, // window class name"The Hello Program", // window captionWS_OVERLAPPEDWINDOW, // window styleCW_USEDEFAULT, // initial x positionCW_USEDEFAULT, // initial y positionCW_USEDEFAULT, // initial x sizeCW_USEDEFAULT, // initial y sizeNULL, // parent window handleNULL, // window menu handlehInstance, // program instance handleNULL) ; // creation parametersShowWindow (hwnd, iCmdShow) ;UpdateWindow (hwnd) ;while (GetMessage (&msg, NULL, 0, 0)){TranslateMessage (&msg) ;DispatchMessage (&msg) ;}return msg.wParam ;}

    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){HDC hdc ;PAINTSTRUCT ps ;RECT rect ;switch (message){

    case WM_PAINT:hdc = BeginPaint (hwnd, &ps) ;GetClientRect (hwnd, &rect) ;DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;EndPaint (hwnd, &ps) ;return 0 ;case WM_DESTROY:PostQuitMessage (0) ;return 0 ;}return DefWindowProc (hwnd, message, wParam, lParam) ;}

    ------------------

    cipher_answer:

    如果你是用Visual Studio的resouce编辑器来编的,就把菜单的名字由GSF改成"GSF",因为GSF是一个整型的常量。假设对应于资源文件的那个头文件是resouce.h:你可以在resouce.h中找到#define GSF ....这样的一句。

    ------------------双肩,正长出骨质的双翼。

    dave_answer:

    如果我没搞错的话,应该写为 wndclass.lpszMenuName =MAKEINTRESOURCE(IDR_MENU1)其中的IDR_MENU1是你制作的菜单的资源标识.你根据实际情况替换一下.

    cipher_answer:

    两种做法都可以,不过如果用整数常量作为资源标识的话。程序中要#include"resouce.h"(假设对应于资源文件的那个头文件是resouce.h)我只说一种方法是怕说得太多,会把人的头弄晕。

    Q:非常感谢cipher和dave,问题解决了!!


    最新回复(0)