win32 写的程序,加入了资源菜单,可运行是没有菜单显示。大侠帮忙!该如何解决
win32 写的程序,加入了资源菜单,可运行是没有菜单显示。大侠帮忙!
同过加入 resource script 添加的菜单资源,可运行是没有菜单显示,小的实在找不到原因,求大侠帮忙:感激涕零!
.c文件如下:
# include <windows.h>
# include "resource.h "
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK AboutDlgProc(HWND,UINT,WPARAM,LPARAM);
int iCurrentColor = IDC_BLACK,iCurrentFigure = IDC_RECT;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName[] = TEXT( "About2 ");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon = LoadIcon(hInstance,szAppName);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = szAppName;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
hwnd = CreateWindow(szAppName,TEXT( "About Box Demo Program "),WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
void PaintWindow(HWND hwnd,int iColor,int iFigure)
{
static COLORREF crColor[8] = {RGB(0,0,0),RGB(0,0,255),RGB(0,255,0),RGB(0,255,255),
RGB(255,0,0),RGB(255,0,255),RGB(255,255,0),RGB(255,255,255)};
HBRUSH hBrush;
HDC hdc;
RECT rect;
hdc = GetDC(hwnd);
GetClientRect(hwnd,&rect);
hBrush = CreateSolidBrush(crColor[iColor - IDC_BLACK]);
if (iFigure == IDC_RECT)
Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
else
Ellipse(hdc,rect.left,rect.top,rect.right,rect.bottom);
DeleteObject(SelectObject(hdc,hBrush));
ReleaseDC(hwnd,hdc);
}
void PaintTheBlock(HWND hCtrl,int iColor,int iFigure)
{
InvalidateRect(hCtrl,NULL,TRUE);
UpdateWindow(hCtrl);
PaintWindow(hCtrl,iColor,iFigure);
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static HINSTANCE hInstance;
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT)lParam)-> hInstance;
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_APP_ABOUT:
if (DialogBox(hInstance,TEXT( "AboutBox "),hwnd,AboutDlgProc))
InvalidateRect(hwnd,NULL,TRUE);
return 0;
}
break;
case WM_PAINT:
BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
PaintWindow(hwnd,iCurrentColor,iCurrentFigure);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
同过加入 resource script 添加的菜单资源,可运行是没有菜单显示,小的实在找不到原因,求大侠帮忙:感激涕零!
.c文件如下:
# include <windows.h>
# include "resource.h "
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK AboutDlgProc(HWND,UINT,WPARAM,LPARAM);
int iCurrentColor = IDC_BLACK,iCurrentFigure = IDC_RECT;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName[] = TEXT( "About2 ");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon = LoadIcon(hInstance,szAppName);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = szAppName;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
hwnd = CreateWindow(szAppName,TEXT( "About Box Demo Program "),WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
void PaintWindow(HWND hwnd,int iColor,int iFigure)
{
static COLORREF crColor[8] = {RGB(0,0,0),RGB(0,0,255),RGB(0,255,0),RGB(0,255,255),
RGB(255,0,0),RGB(255,0,255),RGB(255,255,0),RGB(255,255,255)};
HBRUSH hBrush;
HDC hdc;
RECT rect;
hdc = GetDC(hwnd);
GetClientRect(hwnd,&rect);
hBrush = CreateSolidBrush(crColor[iColor - IDC_BLACK]);
if (iFigure == IDC_RECT)
Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
else
Ellipse(hdc,rect.left,rect.top,rect.right,rect.bottom);
DeleteObject(SelectObject(hdc,hBrush));
ReleaseDC(hwnd,hdc);
}
void PaintTheBlock(HWND hCtrl,int iColor,int iFigure)
{
InvalidateRect(hCtrl,NULL,TRUE);
UpdateWindow(hCtrl);
PaintWindow(hCtrl,iColor,iFigure);
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static HINSTANCE hInstance;
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT)lParam)-> hInstance;
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_APP_ABOUT:
if (DialogBox(hInstance,TEXT( "AboutBox "),hwnd,AboutDlgProc))
InvalidateRect(hwnd,NULL,TRUE);
return 0;
}
break;
case WM_PAINT:
BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
PaintWindow(hwnd,iCurrentColor,iCurrentFigure);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);