1 #include<Windows.h> 2 #include<stdio.h> 3 LRESULT CALLBACK WinSunProc( 4 HWND hwnd, 5 UINT uMsg, 6 WPARAM wParam, 7 LPARAM lParam 8 ); 9 int WINAPI WinMain( 10 HINSTANCE hInstance, 11 HINSTANCE hPrevInstance, 12 LPSTR lpCmdLine, 13 int nCmdShow 14 ) 15 { 16 WNDCLASS wndcls; 17 wndcls.cbClsExtra=0; 18 wndcls.cbWndExtra=0; 19 wndcls.hbrBackground=(HBRUSH) GetStockObject(BLACK_BRUSH); 20 wndcls.hCursor=LoadCursor(NULL,IDC_CROSS); 21 wndcls.hIcon=LoadIcon(NULL,IDI_ERROR); 22 wndcls.hInstance =hInstance; 23 wndcls.lpfnWndProc=WinSunProc; 24 wndcls.lpszClassName="aa"; 25 wndcls.lpszMenuName=NULL; 26 wndcls.style=CS_HREDRAW|CS_VREDRAW; 27 RegisterClass(&wndcls); 28 HWND hwnd; 29 hwnd=CreateWindow("aa","哈哈",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL); 30 ShowWindow(hwnd,SW_SHOWNORMAL); 31 UpdateWindow(hwnd); 32 MSG msg; 33 while (GetMessage(&msg,NULL,0,0)) 34 { 35 TranslateMessage(&msg); 36 DispatchMessage(&msg); 37 38 } 39 return 0; 40 } 41 LRESULT CALLBACK WinSunProc( 42 HWND hwnd, 43 UINT uMsg, 44 WPARAM wParam, 45 LPARAM lParam 46 ) 47 { 48 switch(uMsg) 49 { 50 case WM_CHAR: 51 char szChar[20]; 52 sprintf(szChar,"Char is %d",wParam); 53 MessageBox(hwnd,szChar,"aa",0); 54 break; 55 case WM_LBUTTONDOWN: 56 MessageBox(hwnd,"Mouse clicked","aa",0); 57 HDC hdc; 58 hdc=GetDC(hwnd); 59 TextOut(hdc,0,50,"计算机编程语言",strlen("计算机编程语言")); 60 ReleaseDC(hwnd,hdc); 61 62 break; 63 case WM_PAINT: 64 HDC hDC; 65 PAINTSTRUCT ps; 66 hDC=BeginPaint(hwnd,&ps); 67 TextOut(hDC,0,0,"hahahah",strlen("hahahah")); 68 EndPaint(hwnd,&ps); 69 break; 70 case WM_CLOSE: 71 if (IDYES==MessageBox(hwnd,"是否真的结束?","fb",MB_YESNO)) 72 { 73 DestroyWindow(hwnd); 74 } 75 break; 76 case WM_DESTROY: 77 PostQuitMessage(0); 78 break; 79 default: 80 return DefWindowProc(hwnd,uMsg,wParam,lParam); 81 } 82 return 0; 83 }
问题:error C2664: “CreateWindowExW”: 不能将参数 2 从“const char [7]”转换为“LPCWSTR”
可以这样解决(VS2008中),项目->属性—>配置属性->C/C++->预处理器—>预处理器定义->单击浏览按钮,去掉从父级和项目设置继承