Reprinted from: http://blog.csdn.net/davidliangyc/article/details/71275284
The experimental content of the school is to make a Lianliankan mini game, and take this opportunity to learn about MFC.
I encountered a problem today. When I changed the title of the dialog box, I only found the function SetWindowTextW in the system. After looking at the function parameters, I needed to pass in a string of type LPCTSTR, so I wrote this
- this->SetWindowText((LPCTSTR)"hello");
However, the title of the dialog box shows garbled characters after running. Looking for information, I found that the parameters passed to the SetWindowTextW function should be double-byte characters, and the character type in the solution created by VS is single-character, so set the character set in the project properties. This problem can be solved after multi-character bytes, but this solution is not good enough, and the program interface is not as beautiful as before, so I found another solution, using the SetWindowTextA function, which must be used in front of it. :: means that the reference is to a global function, otherwise it will prompt that there is no such function.
- BOOL CGameDlg::OnInitDialog()
- {
- CDialogEx::OnInitDialog();
- ::SetWindowTextA(m_hWnd, (LPCSTR)"hello");
- return TRUE;
- }
Override the OnInitDialog method of the parent class in the dialog class. m_hWnd represents the current window handle, which is a member variable of the class. After the program runs, the dialog title can be displayed normally .