Win32程序中如何添加菜单?

我想问各位高手一个问题,现在我创建了一个win32 Application的程序并编写了主窗口的代码,然后想在我显示的主窗口中添加一个菜单,怎么加也显示不了,是什么原因啊?已经困惑我好几天了。谢谢指教!!! 
(我先用insert/resource/Menu/new创建了一个新的菜单,然后在主程序中添加代码) 
#include <windows.h> 
#include <string.h> 
#include"Simpwin.h" 
#include"resource.h" //菜单资源的头文件 

#pragma comment( linker, "/subsystem:/"windows/" /entry:/"WinMainCRTStartup/"" ) 


HINSTANCE hInst; 
HWND hWndMain;  

int APIENTRY WinMain(          
HINSTANCE hInstance, 
HINSTANCE hPrevInstance, 
LPSTR lpCmdLine, 
int nCmdShow) 
{ 
MSG msg; 
if(!InitApplicaion(hInstance)) 
return (FALSE); 

if(!InitInstance(hInstance,nCmdShow)) 
return FALSE; 

while(GetMessage( 
      &msg, 
  NULL, 
  0, 
  0)) 
{ 
TranslateMessage(&msg); 
DispatchMessage(&msg); 
} 

return msg.wParam; 
} 

BOOL InitApplicaion(HINSTANCE hInstance)//当前实例句柄 
{ 
WNDCLASS wcSimpwin; 

wcSimpwin.style = CS_HREDRAW | CS_VREDRAW; 
wcSimpwin.lpfnWndProc = (WNDPROC)MainWndProc; 
wcSimpwin.cbClsExtra = 0; 
wcSimpwin.cbWndExtra = 0; 
wcSimpwin.hInstance = hInstance; 
wcSimpwin.hIcon = LoadIcon(NULL, IDI_APPLICATION); 
wcSimpwin.hCursor = LoadCursor(NULL, IDC_ARROW); 
wcSimpwin.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 
wcSimpwin.lpszMenuName = "IDR_MENU1"; 
wcSimpwin.lpszClassName = "SimpwinWClass"; 

return RegisterClass(&wcSimpwin); 

} 

//保存实例句柄,并创建主窗口 
BOOL InitInstance( 
    HINSTANCE hInstance, 
int nCmdShow) 
{ 
hInst = hInstance; 
HMENU hMenu;  //菜单句柄 
hMenu=LoadMenu(hInstance,(LPCSTR)IDR_MENU1); //在resource.h中有:#define IDR_MENU1  101 
hWndMain = CreateWindow( 
          "SimpwinWClass", 
  "我得窗口", 
  WS_OVERLAPPEDWINDOW, 
  CW_USEDEFAULT, 
  CW_USEDEFAULT, 
  CW_USEDEFAULT, 
  CW_USEDEFAULT, 
  NULL, 
  hMenu, 
  hInstance, 
  NULL); 
if(!hWndMain) 
return FALSE; 
ShowWindow(hWndMain, nCmdShow); 
UpdateWindow(hWndMain); 

return TRUE; 
} 

//处理主窗口消息 
LRESULT CALLBACK MainWndProc( 
HWND hWnd, 
UINT message, 
WPARAM wParam, 
LPARAM lParam) 
{ 
HDC hdc; 
PAINTSTRUCT ps; 

switch(message) 
{ 
case WM_PAINT: 
hdc = BeginPaint(hWnd,&ps); 
TextOut(hdc, 20, 10, hello, lstrlen(hello)); 
EndPaint(hWnd, &ps); 
break; 
case WM_DESTROY: 
PostQuitMessage(0); 
break; 

default: 
return DefWindowProc(hWnd, message, wParam, lParam); 
} 

return 0; 
} 

红色的代码就是我为了显示菜单而添加的代码,为什么添加了这些代码还是无法显示我插入的菜单呢?是不是哪里漏了什么了啊?

我用的就是VC6.0么。 
不过谢谢各位指点!我总算解决了,原来只要从Project/Add To Project/Files中把我的资源Script4.rc加载一下就能显示菜单了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值