Today, I learned to write a C ++ program. I have some problems. The problems and solutions are recorded as follows: # include <windows. h> # Include <stdio. h> lresult callback callwindowproc ( Hwnd, Uint MSG, Wparam, Lparam ); Int winapi winmain ( Hinstance, Hinstance hprevinstance, Lpstr lpcmdline, Int ncmdshow ) { Wndclass wndcls; Wndcls. cbclsextra = 0; Wndcls. cbwndextra = 0; Wndcls. hbrbackground = (hbrush) getstockobject (black_brush ); Wndcls. hcursor = loadcursor (null, idc_arrow ); Wndcls. hicon = loadicon (null, idi_application ); Wndcls. hinstance = hinstance; Wndcls. lpfnwndproc = callwindowproc; Wndcls. lpszclassname = "zhengzhixin1983 "; Wndcls. lpszmenuname = NULL; Wndcls. Style = cs_hredraw | cs_vredraw; Registerclass (& wndcls); hwnd; Hwnd = createwindow ("zhengzhixin1983", "zhengzhixin1983", ws_overlappedwindow, 0, 600,600, null, null, hinstance, null); showwindow (hwnd, sw_shownormal ); Updatewindow (hwnd); MSG; While (getmessage (& MSG, null, 0, 0 )) { Translatemessage (& MSG ); Dispatchmessage (& MSG ); } Return 0; } Lresult callback callwindowproc ( Hwnd, Uint MSG, Wparam, Lparam ) { Switch (MSG) { Case wm_char: Char szchar [20]; Sprintf (szchar, "char is % d", wparam ); MessageBox (hwnd, szchar, "zhengzhixin1983", 0 ); Break; Case wm_lbuttondown: MessageBox (hwnd, "mouse click", "zhengzhixin1983", 0 ); HDC; HDC = getdc (hwnd ); Textout (HDC, 0, 50, "zhengzhixin1983", strlen ("zhengzhixin1983 ")); Releasedc (hwnd, HDC ); Break; Case wm_paint: HDC; Paintstruct pS; HDC = beginpaint (hwnd, & PS ); Textout (HDC, 0, 0, "zhengzhixin1983", strlen ("zhengzhixin1983 ")); Endpaint (hwnd, & PS ); Break; Case wm_close: If (idyes = MessageBox (hwnd, "exit? "," Zhengzhixin1983 ", mb_yesno )) Destroywindow (hwnd ); Break; Case wm_destroy: Postquitmessage (0 ); Break; Default: Return defwindowproc (hwnd, MSG, wparam, lparam );} Return 0; } A problem occurs after compilation: D: \ Vc ++ _ lesson1 \ winmain. CPP (28): Error c2440: '=': cannot convert from 'const char [16] 'to 'lpcwstr' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast D: \ Vc ++ _ lesson1 \ winmain. CPP (35): Error c2664: 'createjavaswexw': cannot convert parameter 2 from 'const char [16] 'to 'lpcwstr' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast D: \ Vc ++ _ lesson1 \ winmain. CPP (63): Error c2664: 'messageboxw': cannot convert parameter 2 from 'Char [20] 'to 'lpcwstr' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast D: \ Vc ++ _ lesson1 \ winmain. CPP (66): Error c2664: 'messageboxw': cannot convert parameter 2 from 'const char [12] 'to 'lpcwstr' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast D: \ Vc ++ _ lesson1 \ winmain. CPP (69): Error c2664: 'textoutw': cannot convert parameter 4 from 'const char [16] 'to 'lpcwstr' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast D: \ Vc ++ _ lesson1 \ winmain. CPP (76): Error c2664: 'textoutw': cannot convert parameter 4 from 'const char [16] 'to 'lpcwstr' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast D: \ Vc ++ _ lesson1 \ winmain. CPP (80): Error c2664: 'messageboxw': cannot convert parameter 2 from 'const char [11] 'to 'lpcwstr' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast are basically strings that cannot be converted. After forced conversion is added, the program runs garbled characters. Solution: Project> Properties> Configuration Properties> General> Character Set> use multi-byte character sets without enhanced conversion. |