Setting the initial position of a dialog-based application

void CAppDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { if (lpwndpos->cx = -1) if (lpwndpos->cy = -1) // is init time { lpwndpos->x = 0; // change here if you want to move left or right the window. lpwndpos->y = 0; // change here if you want to move top or bottom the window. } CDialog::OnWindowPosChanging(lpwndpos); }

Explanation

After CreateDialogIndirect, the MFC call CenterWindow. The last line of this function call SetWindowPos with position of window, and with -1, -1, as width and height of window. So the WM_WINDOWPOSCHANGING is obviously.

Date Last Updated: April 19, 1999



Comments

  • Fixed Position Dialog?

    Posted by Legacy on 09/25/2003 12:00am

    Originally posted by: Jon Ha

    Hey Xiaolong Li (or anybody who can answer),
    
    

    What is the actual code that can be used to fix the position of a dialog box? I do not want the dialog to be movable, even when the mouse drags the top title bar of the dialog. is this possible??

    thanks very much!

    Jon

    Reply
  • Works Great

    Posted by Legacy on 04/09/2003 12:00am

    Originally posted by: Trent

    I added the code to my program and it works well.

    Thanks a lot

    Reply
  • Modeless

    Posted by Legacy on 12/25/2002 12:00am

    Originally posted by: Dep

    In the modeless option this solution doesn't work...

    Reply
  • Hiding a modal dialog on startup

    Posted by Legacy on 04/30/2002 12:00am

    Originally posted by: Bosyotik

    You can hide a modal dialog on startup like this:
    
    

    1) Add a BOOL member variable on your CDialog class and intialize it to TRUE

    class CYourDialod: public CDialog
    {
    // ...
    private:
    BOOL m_bHideOnStart;
    }

    CYourDialog::CYourDialog(CWnd* pParent /*=NULL*/)
    : CDialog(CUpgraderDlg::IDD, pParent), m_bHideOnStart(TRUE);
    {
    //...
    }

    2) Handle WM_WINDOWPOSCHANGING message

    void CYourDialog::OnWindowPosChanging(WINDOWPOS* lpwndpos)
    {
    CDialog::OnWindowPosChanging(lpwndpos);
    if((lpwndpos->flags & SWP_SHOWWINDOW) && m_bHideOnStart){
    lpwndpos->flags &= ~SWP_SHOWWINDOW;
    m_bHideOnStart=FALSE;
    }
    }

    Reply
  • Setting position

    Posted by Legacy on 10/17/2000 12:00am

    Originally posted by: Wayne Irons

    Setting the initial position of the dialog is working fine, but how can I also set the initial size? It seems that even if I set lpwndpos->cx and ->cy, they're ignored because SetWindowPos was called with SWP_NOSIZE as a flag...

    Reply
  • How to begin Application with a maximised window size?

    Posted by Legacy on 05/17/2000 12:00am

    Originally posted by: Manish

    If u have developed a dialog based or any SDI/MDI application ,
    
    what should be done in order to open it in maximised window size..??
    my addy ,Logmanish@yahoo.com

    Reply
  • Use DialogBox's properties if the position is fixed

    Posted by Legacy on 04/20/1999 12:00am

    Originally posted by: Xiaolong Li

    Easier way:

    1. Select your DialogBox from resource, get "Properties"
    2. "General" Tab: fill "X Pos" and "Y Pos"
    3. "More Styles" Tab: check "Absolute Align".

    Reply
  • SetWindowPos() works

    Posted by Legacy on 04/19/1999 12:00am

    Originally posted by: Joselito Santana

    Sure you can use SetWindowPos().  You can call it in OnInitDialog. All you have to do is
    
    

    SetWindowPos(NULL, X, Y, NULL, NULL, SWP_NOSIZE |
    SWP_NOZORDER | SWP_SHOWWINDOW);

    where X and Y are values in pixels.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds