Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Can any one please guide me, how to get the handle of a TextBox of one Dialog in another Dilog's source-code. And here both Dialog windows are belongs to same application.

Kindly please help me soon.Thanks
Posted

1 solution

If you have the handle to the dialog, you can simply use a SendMessage() call and return the handle cast as an LRESULT.

Using pseudo-code:
//in target dialog (message catcher) include the message id
#define MSG_GETHANDLE (WM_APP+1)
//...include in message map
BEGIN_MESSAGE_MAP( TargetDialog, CDialog )
	ON_MESSAGE( MSG_GETHANDLE, OnGetHandle)
END_MESSAGE_MAP()
//...define method
LRESULT TargetDialog::OnGetHandle(WPARAM,LPARAM)
{
  ...
  return (LRESULT) handleTextBox;
}

//Within your second dialog, just send the request message and interpret response
CEdit *textbox = (CEdit *)TargetDialog->SendMessage(MSG_GETHANDLE,0,0);
//now you can use textbox


I should say however, that it can be considered bad practice to write directly to another dialog's internal controls. A better method would be to send a request for data or for a change in the GUI and let the parent dialog change the controls.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900