[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).
Re: [win32] - how get the main window inside a class? and some advices
Re: [win32] - how get the main window inside a class? and some advices
Quote:
Originally Posted by
2kaud
i'm sorry, i mean before create the control
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
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.
Re: [win32] - how get the main window inside a class? and some advices
Quote:
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
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.
Re: [win32] - how get the main window inside a class? and some advices
Quote:
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
. . .
};
Re: [win32] - how get the main window inside a class? and some advices
i see what you(both) mean. thanks for all