求助:VC++菜单编程背景
我写的程序调试运行都没有错,但是窗口背景是花的(应该是白色才对啊),并且用了VC插入一个菜单资源,有打开和关闭功能,在image7.h里定义:#define IDM_OPEN 1
#define IDM_EXIT 2
但是调试完结果背景
//wcApp.hbrBackground = (HBRUSH) GetStockObjec(WHITE_BRUSH);
却不是白色的,而是从窗口截取的,这是为什么啊,请高手们指点一下。谢谢啊
以下是image.cpp源代码:
// image2.cpp : Defines the entry point for the application.
//
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <math.h>
#include <windows.h>
#include "image7.h"
int WindowInitial(HINSTANCE hInstance,HINSTANCE hPrevInstance,int nCmdShow);
long FAR PASCAL WndProc(HWND,WORD,WORD,LONG);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow);
HWND hwnd;
char *szAppName="NewWindows";
char *szMenuName="新建窗口";
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
if (lpCmdLine==0) return 0;
WindowInitial(hInstance,hPrevInstance,nCmdShow);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
int WindowInitial(HINSTANCE hInstance,
HINSTANCE hPrevInstance,int nCmdShow)
{
HWND hWnd=NULL;
WNDCLASS wcApp;
HMENU hMenu;
HINSTANCE hIns;
hIns=hInstance;
hMenu = LoadMenu (hInstance,szAppName) ;
if (!hPrevInstance) {
wcApp.style = CS_HREDRAW | CS_VREDRAW;
wcApp.cbClsExtra = 0;
wcApp.cbWndExtra = 0;
wcApp.hInstance = hInstance;
wcApp.lpfnWndProc = (WNDPROC)WndProc;
wcApp.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wcApp.hCursor = LoadCursor(NULL,IDC_ARROW);
wcApp.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wcApp.lpszMenuName = szAppName;
wcApp.lpszClassName = szAppName;
RegisterClass(&wcApp);
}
hWnd = CreateWindow(szAppName,
szMenuName,
WS_OVERLAPPEDWINDOW,
0,0,
600,400,
NULL,NULL,hInstance,NULL);
if(NULL==hWnd) return 0;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return 1;}
long FAR PASCAL WndProc(HWND hWnd,WORD message,
WORD wParam,LONG lParam)
{ PAINTSTRUCT ps;
HDC hdc;
hwnd=hWnd;
switch(message) {
case WM_CREATE:
return 0L;
case WM_CHAR:
char ch[20];
// sprintf(ch,"char is %d",wParam);
MessageBox(hWnd,ch,"windows",MB_OK);
break;
case WM_LBUTTONDOWN:
// MessageBox(hWnd,"鼠标按下","New Pragram",MB_OK);
hdc=GetDC(hWnd);
TextOut(hdc,60,60,"按下鼠标",strlen("按下鼠标"));
ReleaseDC(hWnd,hdc);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hWnd,"是否要退出程序?","New Pragram",MB_YESNO))
{DestroyWindow(hWnd);}
break;
case WM_COMMAND:
switch (wParam) {
case IDM_OPEN:
return 0;
case IDM_EXIT:
SendMessage(hWnd,WM_CLOSE,0,0L);
return 0;
}
break;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc,55,20,"first wondows",strlen("first wondows"));
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default :
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}