C++ method to obtain information in other program form controls

  • 2020-04-02 03:07:28
  • OfStack

This article illustrates how C++ can obtain information in other program form controls. Share with you for your reference. Specific analysis is as follows:

Here's how to get information about other application form controls,

Use the FindWindow API to find the text box handle and use the SendMessage(WM_GETTEXT) to get the text


#include <windows.h> 
BOOL CALLBACK EnumChildProc(HWND hWnd,LPARAM lParam); 
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) 
{ 
  char className[]="notepad"; 
  HWND hWnd=::FindWindow(className,NULL);   
    if(hWnd) 
  { 
    ::EnumChildWindows(hWnd,EnumChildProc,0); 
    return 0; 
  } 
  MessageBox(NULL,"fail!","fail",MB_OK); 
  return 0; 
} 
BOOL CALLBACK EnumChildProc(HWND hWnd,LPARAM lParam) 
{ 
  char temp1[256],temp2[256]; 
  ::GetClassName(hWnd,temp1,255); 
  if(!::strcmp(temp1,"Edit")) 
  { 
    ::SendMessage(hWnd,WM_GETTEXT,sizeof(temp2)/sizeof(char),(LPARAM)temp2);
    //Handle to EDIT, message, receive buffer size, receive buffer pointer
    ::MessageBox(NULL,temp2,"get",MB_OK);  
    return 0; 
  } 
  ::wsprintf(temp2,"classname: %s",temp1); 
  MessageBox(NULL,temp2,"cwnd",MB_OK); 
  return true; 
}

Hope that the article described in the C++ programming to help you.


Related articles: