sinat_38530713 2017-04-30 12:42 采纳率: 0%
浏览 1235

是哪句代码创建了菜单

windows程序设计第十章的MenuDemo.c程序中是哪句代码让菜单显示在了窗口上.
我按照源程序自己写了个简单的程序 但是菜单不能被正常显示. 以下是源代码

#include
#include "resource.h"

#define UNICODE
#define ID_TIMER 1

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

TCHAR szAppName[] = TEXT ("MenuDemo") ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
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  = szAppName ;
 wndclass.lpszClassName = szAppName ;

 if (!RegisterClass (&wndclass))
 {
      MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                  szAppName, MB_ICONERROR) ;
      return 0 ;
 }

 hwnd = CreateWindow (szAppName, TEXT ("Menu Demonstration"),
                      WS_OVERLAPPEDWINDOW,
                      CW_USEDEFAULT, CW_USEDEFAULT,
                      CW_USEDEFAULT, CW_USEDEFAULT,
                      NULL, NULL, hInstance, NULL) ;

 ShowWindow (hwnd, iCmdShow) ;
 UpdateWindow (hwnd) ;
    以上是书中源代码.
查了资料提示说.
    wndclass.lpszMenuName = NULL;部分,改成:wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);或者

ShowWindow之前添加如下代码:
HMENU hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
SetMenu(hwnd, hMenu);

这两种方法我试过的确可以 但书中的方式显然不同.
  • 写回答

4条回答 默认 最新

  • threenewbee 2017-04-30 15:35
    关注

    LoadMenu装入资源里面的菜单,而资源可以在资源编辑器里编辑

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿