Screen co-ords for dialog box

This is a discussion on Screen co-ords for dialog box within the Windows Programming forums, part of the Platform Specific Boards category; After having created a dialog box using CreateDialogParam(), how should I specify the location where it should be on the ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    22

    Screen co-ords for dialog box

    After having created a dialog box using CreateDialogParam(),
    how should I specify the location where it should be on the screen e.g If I want it to always be at the centre of the screen.
    When I call ShowWindow(), it seem to use some kind of random system co-ordinates. e.g it may once appear at the top-left, the next time at the top-right, etc...

    Thanx
    -------------------------
    Gerald.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    I use this to set the dlg in the center of the parents screen.
    send in the child dlg's HWND
    Code:
    int DialogCenter(HWND hWnd)
    {
    	RECT rDialog, rParent;
    	
    	GetWindowRect(hWnd, &rDialog);
    	GetWindowRect(GetParent(hWnd), &rParent);
    	MoveWindow(hWnd, (rParent.right - rParent.left - (rDialog.right - rDialog.left)) / 2,
    			(rParent.bottom - rParent.top - (rDialog.bottom - rDialog.top)) / 2,
    			rDialog.right - rDialog.left, rDialog.bottom - rDialog.top, FALSE);
    
    	return 0;
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    centering dialog

    What about if the dialog has not parent? Will this still work?


    SM_CXFULLSCREEN, SM_CYFULLSCREEN

    int iScreenWidth = GetSystemMetrics(
    SM_CXFULLSCREEN
    );

    int iScreenHeight = GetSystemMetrics(
    SM_CYFULLSCREEN
    );


    now you can center from there.....
    zMan

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>What about if the dialog has not parent? Will this still work?

    There has to be a parent unless that is your main dlg / window.

    I would use

    hdcTemp=GetDC(NULL);
    iWidth =GetDeviceCaps(hdcTemp,HORZRES);
    iHeight =GetDeviceCaps(hdcTemp,VERTRES);
    ReleaseDC(hWnd,hdcTemp);

    or

    hDesktop=GetDesktopWindow();
    GetWindowRect(hDesktop,&DesktopRect);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    add the DS_CENTER style to your dialog resource
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  2. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 09:34 PM
  3. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 03:41 AM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21