One-day Windows API training (41) find?wex Function

Source: Internet
Author: User

To control an existing window program, you need to obtain the window handle of the program. For example, some hacker software needs to find the window and modify the window title. In today's popular plug-ins, we are surprised to find that they can also modify the text in the input window. In this case, you need to use the findwindowex function to locate the window. The following describes how to use this function to control the calculator program in windows. Open the calculator program, minimize the status, run this example, click the create button, and you can click the button to display the calculator at the beginning.

The findjavaswex function declaration is as follows:

# If (winver> = 0x0400)
Winuserapi
Hwnd
Winapi
Find?wexa (
_ In_opt hwnd hwndparent,
_ In_opt hwnd hwndchildafter,
_ In_opt lpcstr lpszclass,
_ In_opt lpcstr lpszwindow );
Winuserapi
Hwnd
Winapi
Find1_wexw (
_ In_opt hwnd hwndparent,
_ In_opt hwnd hwndchildafter,
_ In_opt lpcwstr lpszclass,
_ In_opt lpcwstr lpszwindow );
# Ifdef Unicode
# Define find1_wex find1_wexw
# Else
# Define find1_wex find1_wexa
# Endif //! Unicode
Hwndparent is the parent window handle of the query window. If the parent window is a desktop, it can be set to null.
Hwndchildafter is the start position of the subwindow.
Lpszclass is the type of window registration.
Lpszwindow is the title of the window.

An example of calling this function is as follows:

#001 //
#002 // response command.
#003 // Cai junsheng 2007/09/20 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 {
#022 // find the calculator window.
#023 hwnd = find1_wex (null, _ T ("Calculator "));
#024 if (hwnd! = NULL)
#025 {
#026 // whether the window is minimized.
#027 if (isiconic (hwnd ))
#028 {
#029 // restore window.
#030 showwindow (hwnd, sw_restore );
#031}
#032 else
#033 {
#034 // display window.
#035 showwindow (hwnd, sw_shownormal );
#036}
#037
#038 // display the window to the front.
#039 bringwindowtotop (hwnd );
#040
#041 outputdebugstring (_ T ("click/R/N "));
#042}
#043}
#044 break;
#045 default:
#046 return ccaiwin: oncommand (NID, nevent );
#047}
#048
#049 return 1;
#050}

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.