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. SetWindowPos() basic question

SetWindowPos() basic question

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorialworkspace
11 Posts 6 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.
  • P PatrykDabrowski

    I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.

    P Offline
    P Offline
    PJ Arends
    wrote on last edited by
    #2

    In your OnInitDialog() override are you calling the base class' OnInitDialog() first before calling SetWindowPos()?


    You may be right
    I may be crazy
    -- Billy Joel --

    Within you lies the power for good, use it!!!

    P 1 Reply Last reply
    0
    • P PatrykDabrowski

      I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #3

      PatrykDabrowski wrote:

      How to setup window's position before it is shown?

      You could override PreCreateWindow(). In the override, call the base class PreCreateWindow() then change the x,y,cx,cy members of the passed CREATESTRUCT. Or not for a dialog :) Mark -- modified at 13:51 Sunday 14th January, 2007

      1 Reply Last reply
      0
      • P PatrykDabrowski

        I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #4

        PatrykDabrowski wrote:

        SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE);

        Actually the above call works fine (as it should do...) inside OnInitDialog() on my system (Win2k). I made a test using the CAboutDlg :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        P 1 Reply Last reply
        0
        • P PJ Arends

          In your OnInitDialog() override are you calling the base class' OnInitDialog() first before calling SetWindowPos()?


          You may be right
          I may be crazy
          -- Billy Joel --

          Within you lies the power for good, use it!!!

          P Offline
          P Offline
          PatrykDabrowski
          wrote on last edited by
          #5

          Yes, I'm calling SetWindowPos() just before final 'return TRUE;' statement. This dialog window is created form new thread in this way: .... CMyDialog m_lister(CDialog::FromHandle(GetDesktopWindow())); m_pMainWnd=(CWnd *)&m_lister; m_lister.DoModal(); .... Thanks for Your help.

          1 Reply Last reply
          0
          • C CPallini

            PatrykDabrowski wrote:

            SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE);

            Actually the above call works fine (as it should do...) inside OnInitDialog() on my system (Win2k). I made a test using the CAboutDlg :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            P Offline
            P Offline
            PatrykDabrowski
            wrote on last edited by
            #6

            In my CAboutDlg it is working too, but not in main dialog...(?!?) My CDialog derived class is created on a new thread form CWinThread::InitInstance() using code like this: .... CListerDialog m_lister(CDialog::FromHandle(GetDesktopWindow())); m_pMainWnd=(CWnd *)&m_lister; m_lister.DoModal(); .... hmmm, any idea why simple SetWindowPos() call doesnt work?? Thanks for help.

            C 1 Reply Last reply
            0
            • P PatrykDabrowski

              In my CAboutDlg it is working too, but not in main dialog...(?!?) My CDialog derived class is created on a new thread form CWinThread::InitInstance() using code like this: .... CListerDialog m_lister(CDialog::FromHandle(GetDesktopWindow())); m_pMainWnd=(CWnd *)&m_lister; m_lister.DoModal(); .... hmmm, any idea why simple SetWindowPos() call doesnt work?? Thanks for help.

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #7

              PatrykDabrowski wrote:

              CListerDialog m_lister(CDialog::FromHandle(GetDesktopWindow())); m_pMainWnd=(CWnd *)&m_lister; m_lister.DoModal();

              Hu....Wy are you doing that....:confused: Anyway, I think you have to use ::GetDesktopWindow() insted of GetDesktopWindow(). :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              P 1 Reply Last reply
              0
              • C CPallini

                PatrykDabrowski wrote:

                CListerDialog m_lister(CDialog::FromHandle(GetDesktopWindow())); m_pMainWnd=(CWnd *)&m_lister; m_lister.DoModal();

                Hu....Wy are you doing that....:confused: Anyway, I think you have to use ::GetDesktopWindow() insted of GetDesktopWindow(). :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                P Offline
                P Offline
                PatrykDabrowski
                wrote on last edited by
                #8

                "that" - You mean, setting parent window to Desktop?? I set it to have "full thread separated" dialogs. When I pass NULL to the constructor then my 'child' window minimize when I minimize my main dialog window. When I set Desktop window as its parent, I can minimize both windows independently (plus, my 'child' window has its own entry in taskbar;) Isn't that right?

                1 Reply Last reply
                0
                • P PatrykDabrowski

                  I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.

                  M Offline
                  M Offline
                  Michael Dunn
                  wrote on last edited by
                  #9

                  MFC determines whether it should auto-center a dialog by comparing its RECT before and after your OnInitDialog() runs. (See _AfxPreInitDialog() and _AfxPostInitDialog().) If the RECT is the same before and after, then MFC centers it. If the dialog's default position is (0,0) then your SetWindowPos() call won't move it, and it will be centered. You can either use another position, or call ShowWindow(SW_SHOW) in OnInitDialog() so _AfxPostInitDialog() won't do its auto-centering logic.

                  --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ");

                  P 1 Reply Last reply
                  0
                  • M Michael Dunn

                    MFC determines whether it should auto-center a dialog by comparing its RECT before and after your OnInitDialog() runs. (See _AfxPreInitDialog() and _AfxPostInitDialog().) If the RECT is the same before and after, then MFC centers it. If the dialog's default position is (0,0) then your SetWindowPos() call won't move it, and it will be centered. You can either use another position, or call ShowWindow(SW_SHOW) in OnInitDialog() so _AfxPostInitDialog() won't do its auto-centering logic.

                    --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ");

                    P Offline
                    P Offline
                    PatrykDabrowski
                    wrote on last edited by
                    #10

                    WOW, thanks:) Nice trick with this (0,0) window position;) Now it works fine. Thanks again:)

                    1 Reply Last reply
                    0
                    • P PatrykDabrowski

                      I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.

                      realJSOPR Offline
                      realJSOPR Offline
                      realJSOP
                      wrote on last edited by
                      #11

                      Use MoveWindow in OnInitDialog().

                      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                      -----
                      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                      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