Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing other application's object values. Pls. help.

Status
Not open for further replies.

coolphilboy

Technical User
Aug 19, 2001
19
0
0
PH
I would like to change a textbox values and properties of another application, is it possible? I have an existing application i don't have the source code and i would like to change the value of one of its textboxes, is it possible?

thanks for any help extended.
 
I know it's possible because Visual Test does it.
First you would need to use FindWindow() or FindWindowEx() to get a handle to the window. After that I'm not sure how to get to the right edit control other than tabbing.
Does anyone know what the next step is?
 
?here are also call GetWindowByName() to find parent window of the control. Then GetChildWindow() could be used - in case if you know exact order number of the control - it could be found experimentally. Then you could send any Windows messages like SET_TEXT to that control window.
 
I can't find a GetWindowByName() or GetChildWindow() in the MSDN. Are those newer APIs? (They sound familiar)
Where can I find info about them? Thanks.
 
Sorry, these were my internal things :):

Code:
HWND GetWindowByName(const unsigned char *lpszWinName, bool bFullName)
{
HWND cur_wnd;
unsigned char str_buf[KP_MAX_FNAME_LEN+1];

   cur_wnd=GetTopWindow(NULL);

   while(cur_wnd!=NULL)
   {
      if(GetWindowText(cur_wnd, (char *)str_buf, KP_MAX_FNAME_LEN)>0)
      {
         if(bFullName)
         {
            if(strcmp(str_buf, lpszWinName)==0)
               break;
         }
         else
         {
            if(strstr(str_buf, lpszWinName)!=NULL)
               break;
         }
      }
      
      cur_wnd=GetWindow(cur_wnd, GW_HWNDNEXT);
   }

return(cur_wnd);
}


HWND GetChildWindow(HWND wParent, int iOrderNumber)
{
HWND cur_wnd=NULL;
int ii;

   if(wParent!=NULL)
   {
      cur_wnd=GetWindow(wParent, GW_CHILD);
      for(ii=0; ii<iOrderNumber; ii++)
      {
         if(cur_wnd!=NULL) cur_wnd=GetWindow(cur_wnd, GW_HWNDNEXT);
         else
         {
// -------------- error
            break;
         }
      }
   }
   else
   {
// ------------ error
   }

return(cur_wnd);
}


void SendStringToWindow(HWND wWindow, const unsigned char *lpszOutStr)
{
const unsigned char *pnts;

   if((wWindow!=NULL) && (lpszOutStr!=NULL))
   {
      pnts=lpszOutStr;
      while(*pnts)
      {
//       SendMessage(wWindow, WM_CHAR, *pnts++, 0);
         PostMessage(wWindow, WM_CHAR, *pnts++, 0);
         Sleep(100);
      }
   }
   else
   {
// ------------ error
   }
}
 
Wow, thanks. I haven't done Windows programming for a while, so I forgot that each component is considered a window too... :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top