MFC easily implement dialog title change

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

[cpp]  view plain copy  
  1. 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.

[cpp]  view plain copy  
  1. BOOL CGameDlg::OnInitDialog()  
  2. {     
  3.     CDialogEx::OnInitDialog();  
  4.     ::SetWindowTextA(m_hWnd, (LPCSTR)"hello");  
  5.     return TRUE;  
  6. }  


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 .



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326740346&siteId=291194637
Recommended