One-day Windows API training (36) setwindowtext Function
Source: Internet
Author: User
One-day Windows API training (36) setwindowtext Function
In software development, you sometimes need to change the title text in the window. For example, the text on the button needs to be changed to adapt to the display in multiple languages. In this case, you need to use the setwindowtext function to modify its content. The following example shows how to change the button title.
The setwindowtext function declaration is as follows:
Winuserapi
Bool
Winapi
Setwindowtexta (
_ In hwnd,
_ In_opt lpcstr lpstring );
Winuserapi
Bool
Winapi
Setwindowtextw (
_ In hwnd,
_ In_opt lpcwstr lpstring );
# Ifdef Unicode
# Define setwindowtext setwindowtextw
# Else
# Define setwindowtext setwindowtexta
# Endif //! Unicode
Hwnd is the handle of the window.
Lpstring is the text to be displayed.
An example of calling this function is as follows:
#001 //
#002 // response command.
#003 // Cai junsheng 2007/09/14 QQ: 9073204
#004 //
#005 lresult ccaiwinmsg: oncommand (int nid, int nevent)
#006 {
#007 // menu option command response:
#008 switch (NID)
#009 {
#010 case idc_createbtn:
#011 // display a button.
#012 if (! M_hbtn)
#013 {
#014 m_hbtn = createwindow (_ T ("button"), _ T ("button "),
#015 ws_visible | ws_child | bs_pushbutton,
#016 50,50, 100,32,
#017 m_hwnd, (hmenu) idc_btn, m_hinstance, null );
#018}
#019 break;
#020 case idc_btn:
#021 outputdebugstring (_ T ("click/R/N "));
#022 {
#023 static bool bchangetext = true;
#024 if (bchangetext)
#025 {
#026 // set the text of the button.
#027 setwindowtext (m_hbtn, _ T ("change it "));
#028}
#029 else
#030 {
#031 // set the text of the button.
#032 setwindowtext (m_hbtn, _ T ("button "));
#033}
#034
#035 // changes each time.
#036 bchangetext =! Bchangetext;
#037}
#038 break;
#039 default:
#040 return ccaiwin: oncommand (NID, nevent );
#041}
#042
#043 return 1;
#044}
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