code:
#include "stdafx.h"#define WIN32_LEAN_AND_MEAN
#define WINDOW_CLASS_NAME "WINDOWSCLASS1"LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){ PAINTSTRUCT ps;
HDC hdc; switch(msg){
case WM_CREATE:{//Sent when a window first created
return(0);
}break;
case WM_PAINT://Sent when a window need repainting
{
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
}break;
case WM_DESTROY://Sent when a window needs to destroy
{
PostQuitMessage(0);
return(0);
}break;
default:break;
}
return (DefWindowProc(hwnd,msg,wparam,lparam));
}
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASSEX winclass;
HWND hwnd;
MSG msg;winclass.cbSize=sizeof(WNDCLASSEX);
winclass.style=CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
winclass.lpfnWndProc=WindowProc;
winclass.cbClsExtra=0;
winclass.cbWndExtra=0;
winclass.hInstance=hinstance;
winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
winclass.hCursor=LoadCursor(NULL,IDC_ARROW);
winclass.hbrBackground=COLOR_BACKGROUND(BLACK_BRUSH);//error C2064: term does not evaluate to a function //taking 1 arguments
winclass.lpszMenuName=NULL;
winclass.lpszClassName=_T(WINDOW_CLASS_NAME);
winclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);if(!RegisterClassEx(&winclass))
return(0);if(!(hwnd=CreateWindowEx(NULL,
WINDOW_CLASS_NAME,
"Window",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
0,0,
400,400,
NULL,
NULL,
hinstance,
"WINDOWSCLASS1")))//error C2664: 'CreateWindowExW': cannot convert parameter 2 from 'const char[14] to //'LPCWSTR''
return(0);while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
上面的注释就是这个程序的错误解释,搞了半天没有搞出来,这个程序的目的就是创建一个window,背景是黑色。谢谢!
#include "stdafx.h"#define WIN32_LEAN_AND_MEAN
#define WINDOW_CLASS_NAME "WINDOWSCLASS1"LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){ PAINTSTRUCT ps;
HDC hdc; switch(msg){
case WM_CREATE:{//Sent when a window first created
return(0);
}break;
case WM_PAINT://Sent when a window need repainting
{
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
}break;
case WM_DESTROY://Sent when a window needs to destroy
{
PostQuitMessage(0);
return(0);
}break;
default:break;
}
return (DefWindowProc(hwnd,msg,wparam,lparam));
}
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASSEX winclass;
HWND hwnd;
MSG msg;winclass.cbSize=sizeof(WNDCLASSEX);
winclass.style=CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
winclass.lpfnWndProc=WindowProc;
winclass.cbClsExtra=0;
winclass.cbWndExtra=0;
winclass.hInstance=hinstance;
winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
winclass.hCursor=LoadCursor(NULL,IDC_ARROW);
winclass.hbrBackground=COLOR_BACKGROUND(BLACK_BRUSH);//error C2064: term does not evaluate to a function //taking 1 arguments
winclass.lpszMenuName=NULL;
winclass.lpszClassName=_T(WINDOW_CLASS_NAME);
winclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);if(!RegisterClassEx(&winclass))
return(0);if(!(hwnd=CreateWindowEx(NULL,
WINDOW_CLASS_NAME,
"Window",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
0,0,
400,400,
NULL,
NULL,
hinstance,
"WINDOWSCLASS1")))//error C2664: 'CreateWindowExW': cannot convert parameter 2 from 'const char[14] to //'LPCWSTR''
return(0);while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
上面的注释就是这个程序的错误解释,搞了半天没有搞出来,这个程序的目的就是创建一个window,背景是黑色。谢谢!
_T("WINDOWSCLASS1")
_T("WINDOWSCLASS1");