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

FindWindow c# Please Help Before I Cry 3

Status
Not open for further replies.

sodiumpaul

Programmer
Jun 30, 2007
17
GB

I've been trying to get the handle of a Button within my application. The main form launches another form ( floating toolBox).

I've used the following code with the Ms Calc app to prove this code works - it does:

int hwnd;
int comp;
hwnd = FindWindow(null, "Calculator");
comp = FindWindowEx(hwnd, 0, "Button", "1");
MessageBox.Show(comp.ToString()); //works

However, when I do the same with my app (main form finding button on floating toolbox started from main form (therefore, not a child form), it does not work. hwnd = FindWindow(null, "toolbox"); -> finds handle. FindWindowEx section does not find the button on my toolbox (label "1"). I've also created a simple, independent, form with one button, started this app and run my main app to test....this also did not work. Is this something to do with VS?


Please, please help!

Thankyou.
 
It turns out that I can get the handle of all components on all other forms, just not the one I've authored. I can, however, get the form handle of the app I've authored.

Any ideas?

Many thanks.
 
Sorry about the repetition as I've pasted this from one of my posts to a friend.

Here's the real problem. I'm making an app that has a floating toolbox (a separate form, not child). I'm trying to get the handle of a label component on the toolbox form. However at compile, the class name changes every time. If I use an exe I created for testing with a label component, the class name remains static. The problem is that under VS debug/release the class name keeps changing, therefore I can't use this as an ID. The only way around (with my limited knowledge) this would be to pre-compile the toolbox app and start the toolbox exe before the main app. This seems very clanky and would cause other issues for me.

Many thanks all.
 
Why are you trying to get the handle of a label?

Why wouldn't you just expose the label property via the form.


public Label GetSomeLabel()
{
return this.Label1;
}

I initially didn't want to reply to this post because I've seen other developers try to hack other forms and it bothers me...
 
No, I understand, this is all down to being a newby, I guess.

The main form, on start up, resizes itself to fit screen resolution (Primary or Virtual screen). I have a label in the float form (form2) that will display the resolution that the main form has set it's self to as an event (dependent on if an extended desktop is being used). I did get your reply to one of my lasts posts and that was very useful. I would just like to get to the bottom of this, it's bugging me. If it were not for VS doing this, I got all my other ducks in line.

Thanks yet again for your help and reply.
 
Yes they are.

The resizing event on form1 needs to display as text in a label on form2, the resolution that form1 has taken up as a result of detecting an extended desktop.

Many thanks.

 
Hi sodiumpaul,

Here's an interesting article how the framework manages window creation and registration:


As you will read, a lot of things happen under the hood. Try instead to look other ways to accomplish the same task you want for FindWindow(). In your case, it's as simple as JurkMonkey's suggestion.

2cents [wink]
 
Thanks all. I didn't explain things well enough, sorry.

In the end I used events as I needed to change the label text in the event the main screen was resized.

All your help, however, was very useful and will find its way into my "How To" docs.

Thanks again.

This info is very valuable to a newbie.

The site 2cents sent me to was very interesting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top