Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GetActiveWindow

GetActiveWindow

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    iayd
    wrote on last edited by
    #1

    Hi, There are many dialog boxes in my project. I want to know that which one is active at a certain time. For example;

        CDlg1 \* dlg1;   // A global object for the dialog box.
    dlg1= new CDlg1;
    dlg1->Create(IDD\_DIALOG1,this);
    

    CWnd * wnd;
    wnd = (CDialog*)GetActiveWindow();
    if(wnd == dlg1)
    wnd->DestroyWindow();

    I wrote this code to close the window. How can I know that which wnidow is active? Thanks

    S J N 3 Replies Last reply
    0
    • I iayd

      Hi, There are many dialog boxes in my project. I want to know that which one is active at a certain time. For example;

          CDlg1 \* dlg1;   // A global object for the dialog box.
      dlg1= new CDlg1;
      dlg1->Create(IDD\_DIALOG1,this);
      

      CWnd * wnd;
      wnd = (CDialog*)GetActiveWindow();
      if(wnd == dlg1)
      wnd->DestroyWindow();

      I wrote this code to close the window. How can I know that which wnidow is active? Thanks

      S Offline
      S Offline
      SandipG
      wrote on last edited by
      #2

      You can use GetFocus() Or GetForeGroundWindow() functions.

      Regards, Sandip.

      I 1 Reply Last reply
      0
      • I iayd

        Hi, There are many dialog boxes in my project. I want to know that which one is active at a certain time. For example;

            CDlg1 \* dlg1;   // A global object for the dialog box.
        dlg1= new CDlg1;
        dlg1->Create(IDD\_DIALOG1,this);
        

        CWnd * wnd;
        wnd = (CDialog*)GetActiveWindow();
        if(wnd == dlg1)
        wnd->DestroyWindow();

        I wrote this code to close the window. How can I know that which wnidow is active? Thanks

        J Offline
        J Offline
        Jijo Raj
        wrote on last edited by
        #3

        iayd wrote:

        CDlg1 * dlg1; // A global object for the dialog box. dlg1= new CDlg1; dlg1->Create(IDD_DIALOG1,this);

        Since you're creating your child dialogs by passing your main dialog as parent, call GetTopWindow() by passing parent window handle. It will give you the top most window of your application. Regards, Jijo.

        _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

        I 1 Reply Last reply
        0
        • S SandipG

          You can use GetFocus() Or GetForeGroundWindow() functions.

          Regards, Sandip.

          I Offline
          I Offline
          iayd
          wrote on last edited by
          #4

          These are not working in my situations.I think the problem is not about GetActiveWindow(). The problem is that when I want to know if this window (active window) is the same window with the dialog box that I created before, it couldn't compare them. This part has problem I think;

          if(dlg == wnd)

          1 Reply Last reply
          0
          • J Jijo Raj

            iayd wrote:

            CDlg1 * dlg1; // A global object for the dialog box. dlg1= new CDlg1; dlg1->Create(IDD_DIALOG1,this);

            Since you're creating your child dialogs by passing your main dialog as parent, call GetTopWindow() by passing parent window handle. It will give you the top most window of your application. Regards, Jijo.

            _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

            I Offline
            I Offline
            iayd
            wrote on last edited by
            #5

            Thanks. That solved the problem.

            1 Reply Last reply
            0
            • I iayd

              Hi, There are many dialog boxes in my project. I want to know that which one is active at a certain time. For example;

                  CDlg1 \* dlg1;   // A global object for the dialog box.
              dlg1= new CDlg1;
              dlg1->Create(IDD\_DIALOG1,this);
              

              CWnd * wnd;
              wnd = (CDialog*)GetActiveWindow();
              if(wnd == dlg1)
              wnd->DestroyWindow();

              I wrote this code to close the window. How can I know that which wnidow is active? Thanks

              N Offline
              N Offline
              Nibu babu thomas
              wrote on last edited by
              #6

              iayd wrote:

              if(wnd == dlg1)

              Use window handles instead of MFC objects to compare. Since MFC window objects are just wrappers around window handles. if( wnd.GetSafeHwnd() == dlg1.GetSafeHwnd() ) ;;//...

              Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups