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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the control name from handle

Status
Not open for further replies.

hennep

Programmer
Dec 10, 2000
429
How can I get the name of a control and a pointer to the click function when I only have the window handle of the control ?
 
So you only have the window Handle of the control but want to get all of the information from that control...hmmm...

You would probably have to go through all of the controls in that control's parent, find out which component has the same Handle as the one you are given, then use that pointer to get the other information.

Chris
 
you might find this useful.

void __fastcall TMain::Close2Click(TObject *Sender)
{
// Get the active richedit
GetEdit ();

SaveModifiedText ();

if(dynamic_cast<TTabSheet *>(Tab) != 0)
{
dynamic_cast<TTabSheet *>(Tab)->TabVisible = false;
dynamic_cast<TTabSheet *>(Tab)->Caption = &quot;&quot;;
pages--;

// Get the active richedit
GetEdit ();
if(dynamic_cast<TTabSheet *>(Tab) != 0)
dynamic_cast <TRichEdit *>(REdit)->SetFocus ();
}
}

tomcruz.net
 
Your solution would work when the form is in the same project, but it's not.
I am trying to get rid of the annoying popups from outlook when the address book is opened by other programs. (msaccess in my case)
I gave the problem a little more attention and I don't need the controls name. Using the PostMessage API it should be possible to click on the button.


 
Hi hennep.

Yep you can use SendMessage to send a BM_CLICK to the button. If its a speedbutton you need to send it WM_LBUTTONDOWN and then WM_LBUTTONUP to simulate a click. To get the handle of the main window you can use FindWindow, then use FindWindowEX to get the handle of the parent window of the button ,if needed or if the the main form is the parent just use FindWindowEX to get the HWND(Handle) of the button.
 
I already have a program that more or less works. EnumWindows searches for the outlook dialog and EnumChildWindows searches the checkbox and the button.
Instead of SendMessage I have used the PostMessage api.
PostMessage does not wait until the message is processed.

thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top