-
January 29th, 2014, 06:31 AM
#1
[RESOLVED] [win32] - how get the main window inside a class? and some advices
how can i get the main window without use the GetForegroundWindow()?
what i need is, when i create the instance of label, is get the parent automatic(in these case the main window).
-
January 29th, 2014, 07:02 AM
#2
Re: [win32] - how get the main window inside a class? and some advices
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 29th, 2014, 07:06 AM
#3
Re: [win32] - how get the main window inside a class? and some advices
Originally Posted by 2kaud
i'm sorry, i mean before create the control
-
January 29th, 2014, 07:49 AM
#4
Re: [win32] - how get the main window inside a class? and some advices
Have a look at GetGuiThreadInfo(). It can return window info about the current thread.
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 29th, 2014, 01:35 PM
#5
Re: [win32] - how get the main window inside a class? and some advices
I don't see how GetGuiThreadInfo may be better than GetForegroundWindow.
The thing OP needs to understand is: there's no "main window" thing in Windows program. A program is allowed to have any number of threads owning any number of top level windows each. And only program developer knows for sure what window matters more than others.
Bottom line is: control design that tries to make any assumptions about "mainness" of particular window is bad design.
More than that, I really fail to understand how main window, whatever it is, may have anything to do with controls. Maybe we need to get a definition of main window here to understand the problem better.
Last edited by Igor Vartanov; January 29th, 2014 at 01:39 PM.
Best regards,
Igor
-
January 29th, 2014, 01:46 PM
#6
Re: [win32] - how get the main window inside a class? and some advices
Originally Posted by Igor Vartanov
I don't see how GetGuiThreadInfo may be better than GetForegroundWindow.
The thing OP need to understand is: there's no "main window" thing in Windows program. A program is allowed to have any number of threads owning any number of top level windows each. And only program developer knows for sure what window matters more than others.
Bottom line is: control design that tries to make any assumptions about "mainness" of particular window is bad design.
More than that, I really fail to understand what main window, whatever it is, may have anything to do with controls. Maybe we need to get a definition of main window here to understand the problem better.
sorry: 'main window', like i have seen is the 1st window... but maybe you have right.
when i execute the program, 1 window(form) is created. i call it the 'main window'. it's the child controls\windows parent. what i wanted is get the hwnd of the parent window, without use the GetForegroundWindow() or GetParent() or use the hwnd of the child control
Last edited by Cambalinho; January 29th, 2014 at 01:50 PM.
-
January 30th, 2014, 07:33 AM
#7
Re: [win32] - how get the main window inside a class? and some advices
If the program creating the windows is your own (you're writing the source).
Then the proper solution is to pass the window pointer/handle/reference, along from the thread that created that window along to the thread(s) that need it.
If the program creating the window is not under your control...
then "it's all just a big bunch of guesses and assumptions", and your guesses and assumptions are as good as anyone else's.
-
January 31st, 2014, 04:13 AM
#8
Re: [win32] - how get the main window inside a class? and some advices
Originally Posted by Cambalinho
what i wanted is get the hwnd of the parent window, without use the GetForegroundWindow() or GetParent() or use the hwnd of the child control
The only reliable approach is: your control class design makes user to explicitly specify the parent window handle.
Code:
class MyCoolestStatic
{
private:
HWND m_hwndParent;
public:
// constructor requires parent window handle
MyCoolestStatic(HWND hwndParent): m_hwndParent(hwndParent) ...
// no default constructor allowed
. . .
};
Best regards,
Igor
-
January 31st, 2014, 07:21 AM
#9
Re: [win32] - how get the main window inside a class? and some advices
i see what you(both) mean. thanks for all
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|