[RESOLVED] [win32] - how get the main window inside a class? and some advices
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: [RESOLVED] [win32] - how get the main window inside a class? and some advices

  1. #1
    Join Date
    Apr 2009
    Posts
    636

    [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).

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,361

    Re: [win32] - how get the main window inside a class? and some advices

    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Apr 2009
    Posts
    636

    Re: [win32] - how get the main window inside a class? and some advices

    Quote Originally Posted by 2kaud View Post
    i'm sorry, i mean before create the control

  4. #4
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,361

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,970

    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 12:39 PM.
    Best regards,
    Igor

  6. #6
    Join Date
    Apr 2009
    Posts
    636

    Re: [win32] - how get the main window inside a class? and some advices

    Quote Originally Posted by Igor Vartanov View Post
    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 12:50 PM.

  7. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,877

    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.

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,970

    Re: [win32] - how get the main window inside a class? and some advices

    Quote Originally Posted by Cambalinho View Post
    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

  9. #9
    Join Date
    Apr 2009
    Posts
    636

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center