Note the following when writing the first program in Windows:

Source: Internet
Author: User
Tags textout

 

Vs200x Character Problems
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.

Another point is: when creating a project, you should create a Win32 application, instead of a Win32 console program, because the latter's entry function is the main function, and the Win32 application's entry function is the winmain function. This is the difference between the Win32 application and the console program. 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.