出问题的地方在下面标出了,大家帮我看看,错误为
error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
源码为
//// Simpwin.h ///////
LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE,int);
char *hello="HELLO WORLD";
/////////////////////////////
///// Simpwin.cpp //////////////////
#include<windows.h>
#include"Simpwin.h"
#include<string.h>HINSTANCE hInst;
HWND hWndMain;int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg; if(!InitApplication(hInstance))
return (FALSE); if(!InitInstance(hInstance,nCmdShow))
return (FALSE); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}
BOOL InitApplication(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 =LoadCursor(NULL,IDI_APPLICATION);
wcSimpwin.hCursor =LoadCursor(NULL,IDC_ARROW);
wcSimpwin.hbrBackground=GetStockObject(WHITE_BRUSH);//问题在这里
wcSimpwin.lpszMenuName =NULL;
wcSimpwin.lpszClassName="SimpwinWClass"; return (RegisterClass(&wcSimpwin));
}BOOL InitInstance(HINSTANCE hInstance,
int nCmdShow)
{
hInst=hInstance; hWndMain=CreateWindow(
"SimpwinWClass",
"ÎҵĴ°¿Ú",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,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);
}/////////////////
error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
源码为
//// Simpwin.h ///////
LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE,int);
char *hello="HELLO WORLD";
/////////////////////////////
///// Simpwin.cpp //////////////////
#include<windows.h>
#include"Simpwin.h"
#include<string.h>HINSTANCE hInst;
HWND hWndMain;int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg; if(!InitApplication(hInstance))
return (FALSE); if(!InitInstance(hInstance,nCmdShow))
return (FALSE); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}
BOOL InitApplication(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 =LoadCursor(NULL,IDI_APPLICATION);
wcSimpwin.hCursor =LoadCursor(NULL,IDC_ARROW);
wcSimpwin.hbrBackground=GetStockObject(WHITE_BRUSH);//问题在这里
wcSimpwin.lpszMenuName =NULL;
wcSimpwin.lpszClassName="SimpwinWClass"; return (RegisterClass(&wcSimpwin));
}BOOL InitInstance(HINSTANCE hInstance,
int nCmdShow)
{
hInst=hInstance; hWndMain=CreateWindow(
"SimpwinWClass",
"ÎҵĴ°¿Ú",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,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);
}/////////////////
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货