?
Solved

WINDOWPLACEMENT with different screen Resolutions

Posted on 2005-04-26
7
Medium Priority
?
277 Views
Last Modified: 2013-11-20
I store the windowplacement information(which I am obtaining from a file) in the WINDOWPLACEMENT structure with all the necessary values.
I am also able to use the SetWindowPlacement(&wp) that loads the template in the correct position.

Now, If I want to load the window on a different screen resolution, things get messed up. I want to way to figure out if the Windowplacement values are not suited with the screen reolsution.
If they are not suited with the current screen resolution, then i want to be able to place them at a default location(like Center of Screen).

Can anyone please attach a snippet, if they have tried a similar problem ??

i tried to use the following code, but it did not help

        wp.rcNormalPosition.left = min (wp.rcNormalPosition.left,
            ::GetSystemMetrics (SM_CXSCREEN) -
            ::GetSystemMetrics (SM_CXICON));
        wp.rcNormalPosition.top = min (wp.rcNormalPosition.top,
            ::GetSystemMetrics (SM_CYSCREEN) -
            ::GetSystemMetrics (SM_CYICON));

       SetWindowPlacement(&wp);


Please Help me with this and attach a snippet that i can try

Thanks
0
Comment
Question by:hari4130
  • 4
  • 2
7 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 1600 total points
ID: 13869456
Hi hari4130,
You can use EnumDisplaySettings API function to get desktop screen resolution.

Check out the following wrapper functions:
DWORD  GetDesktopScreenWidthResulotion()
{
    DEVMODE my_DEVMODE;
    EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &my_DEVMODE);
    return my_DEVMODE.dmPelsWidth;
}

DWORD  GetDesktopScreenHeightResulotion()
{
    DEVMODE my_DEVMODE;
    EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &my_DEVMODE);
    return my_DEVMODE.dmPelsHeight;
}

You can also use it to setup temporary screen resolution settings.
bool SetDesktopScreenColorResulotion(DWORD BitsPerPel, DWORD PelsWidth = 1024, DWORD PelsHeight = 768)
{
    DEVMODE my_DEVMODE;
    EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &my_DEVMODE);
    my_DEVMODE.dmBitsPerPel        = BitsPerPel;
    if (my_DEVMODE.dmPelsWidth < PelsWidth) my_DEVMODE.dmPelsWidth        = PelsWidth;
    if (my_DEVMODE.dmPelsHeight < PelsHeight) my_DEVMODE.dmPelsHeight        = PelsHeight;
    return (ChangeDisplaySettings(&my_DEVMODE, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);
}

DWORD  GetDesktopScreenWidthResulotion()
{
    DEVMODE my_DEVMODE;
    EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &my_DEVMODE);
    return my_DEVMODE.dmPelsWidth;
}



David Maisonave :-)
Cheers!
0
 
LVL 30

Expert Comment

by:Axter
ID: 13869485
hari4130,

You can then use SetWindowPos API function to put the window in the desired location.
SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
Or
::SetWindowPos(MyWhnd, NULL, 0, 0, 0, 0, SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);

David Maisonave :-}
0
 

Author Comment

by:hari4130
ID: 13869561
I am already using the WINDOWPLACEMENT Structure in my code in several places. that structure has the (left, top, bottom and right positions). I can obtain the width and height from these values.

Is there a way where i can still use GetSystemMetrics ?

Thanks
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Axter
ID: 13869592
>>Is there a way where i can still use GetSystemMetrics ?

I had problems using GetSystemMetrics in my code, and that's why I resorted to use EnumDisplaySettings API, which works great.
0
 
LVL 30

Expert Comment

by:Axter
ID: 13869612
Can you give more details as to the problems you're currently having with existing code?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 400 total points
ID: 13869647
I'd suggest

RECT rect;
SystemParametersInfo(SPI_GETWORKAREA,0,(LPVOID)&rect,0);

       wp.rcNormalPosition.left = min (wp.rcNormalPosition.left,rect.left);
       wp.rcNormalPosition.top = min (wp.rcNormalPosition.top,rect.top);
0
 

Author Comment

by:hari4130
ID: 13870137
I tried using the SystemParametersInfo but it did not work. it messed up the original window placement when i checked it on the same screen resolution.

Do you think this would  work? I tried it, but it does not work in some cases...

int WPwidth = wp->rcNormalPosition.right - wp->rcNormalPosition.left;
int WPheight = wp->rcNormalPosition.bottom - wp->rcNormalPosition.top;
                      
int SCwidth = GetSystemMetrics(SM_CXFULLSCREEN);
int SCheight = GetSystemMetrics(SM_CYFULLSCREEN);
                  
if((SCwidth > WPwidth) && (SCheight > WPheight)) pFrame->SetWindowPlacement(wp);
else  // show default windpwplacement....

Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question