首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

如何样在窗口中加上菜单

2012-02-17 
怎么样在窗口中加上菜单 - C++ Builder / Windows SDK/API本人刚学API,想在窗口左上角加上菜单,但运行时始

怎么样在窗口中加上菜单 - C++ Builder / Windows SDK/API
本人刚学API,想在窗口左上角加上菜单,但运行时始终不显示,为什么哦,请高手指点。



#include "stdafx.h"
#include "resource.h"
ATOM myRegisterClass( HINSTANCE hInstance);
HINSTANCE htae;
LRESULT CALLBACK MYPROC(HWND hnwd,UINT umsg,WPARAM wparam,LPARAM lparam);
LRESULT CALLBACK About(HWND hwnd,UINT umsg,WPARAM wparam,LPARAM lparam);

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
htae = hInstance;
HWND hwnd;
MSG msg;
HACCEL hAccelTable;

myRegisterClass(hInstance);

hwnd = CreateWindow(TEXT("我的窗口类"),
TEXT("我的窗口"),
WS_OVERLAPPEDWINDOW,
100,100,666,444,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDR_MENU1);

while (GetMessage(&msg,NULL,0,0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}


ATOM myRegisterClass( HINSTANCE hInstance)
{
WNDCLASSA wc;

wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_ACTIVEBORDER);
wc.hCursor = LoadCursor(hInstance,(LPCTSTR)IDC_ROUND);
wc.hIcon = LoadIcon(hInstance,(LPCTSTR)IDI_ICON1);
wc.hInstance = htae;
wc.lpfnWndProc = (WNDPROC)MYPROC;
wc.lpszClassName = TEXT("我的窗口类");
wc.lpszMenuName = TEXT("我的菜单");
wc.style = CS_HREDRAW;

return RegisterClass(&wc);
}

LRESULT CALLBACK MYPROC(HWND hnwd,UINT umsg,WPARAM wparam,LPARAM lparam)
{
HDC hdc;
TCHAR szBuf[] = "我的窗口我做主";
PAINTSTRUCT ps;
int nA,nB;
switch(umsg)
{
case WM_COMMAND:
{
nA = LOWORD(wparam);
nB = HIWORD(wparam);
switch( nA )
{
case IDM_ABOUT:
DialogBox(htae,(LPCTSTR)IDD_ABOUT1,hnwd,(DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hnwd);
break;
default:
return DefWindowProc(hnwd, umsg, wparam ,lparam);
}

}
break;

case WM_PAINT:
hdc = BeginPaint(hnwd,&ps);
TextOut(hdc,222,222,szBuf,strlen(szBuf));
EndPaint(hnwd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
/*case WM_CREATE:
MessageBox(hnwd,TEXT("想创建窗口吗?"),TEXT("还没创建窗口"),1);
break;
*/default:
return DefWindowProc(hnwd,umsg,wparam,lparam);

}
return 0;
}

LRESULT CALLBACK About(HWND hwnd,UINT umsg,WPARAM wparam,LPARAM lparam)

{
switch(umsg)
{
case WM_COMMAND:
if (LOWORD(wparam) == IDOK)
{
EndDialog(hwnd,LOWORD(wparam));
return true;
}
break;
case WM_INITDIALOG:
return true;

}
return false;
}

[解决办法]
wc.lpszMenuName = TEXT("我的菜单"); 就是在这一句中加入菜单,就是你的菜单资源的ID号
[解决办法]
比如我的菜单ID是IDC_SS ,那么加载菜单应该是 : wcex.lpszMenuName=(LPCSTR)IDC_SS;

热点排行