Link to home
Start Free TrialLog in
Avatar of jessicalim
jessicalim

asked on

GetSystemMetics

I am building an interface by windows programming in C. I want my interface can be displayed beautifully in any pc's resolution (640x480, 800x600, 1024x768 etc). So, I used GetSystemMetrics to get the winWidth n winHeight. But, the problem is when I change all the components' location and structure of the interface into fraction like

hButton = createWindow("BUTTON",...,...,...,...,....,... 3*winWidth/16, 4*winHeight/25, 18*winWidth/80,....,....);  

the interface can't be displayed well in other pc. The structure of the interface destroy if the interface been displayed in other resolution. My pc's resolution is 800x600.

How am I want to display the interface well in any pc's resolution?
I create some graphics components (buttons, radion buttons, track bars etc) in resource file. The position of the components in the interface is set by numbers. But now I want to change it to
n*winWidth/m, x*winHeight/y which, n, m, x, y is any numbers so that the graphics components also can be displayed well in other pc's resolution also.

What should I do?
 
ASKER CERTIFIED SOLUTION
Avatar of AlexVirochovsky
AlexVirochovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jessicalim
jessicalim

ASKER

Alex,
How about the components which I created by using CreateWindow("Button",......) in the main window? How should I make them as flexible as possible by following the different resolution?
Can I use any ratio which is counted from the window width and window height?
In you oun window you can use this mechanism, i hope.
But you must react to message WM_CHANGERESOLUTION,
if user change current resolution.This reaction , i think,
must be : delete and rebuid all controls.
Alex,
I need your help again.
There is no WM_RESOLUTIONCHANGE, but the WM_DISPLAYCHANGE.

Below is part of the source code:
case WM_DISPLAYCHANGE:
fChanged = (BOOL)wParam;
szScreen.cx = LOWORD(lParam);
szScreen.cy = HIWORD(lParam);
winWidth = szScreen.cx;
winHeight = szScreen.cy;
if (fChanged) {
      // I tried to do something here. I want the interface change       
             //the size here. But, what should I add?
}
else {
      MessageBeep(0);
}
break;            

The components like buttons, status bar, ownerdraw button, bitmap displaying... are created in different function. How should I call the functions to redraw?
I think, if you don't want delete/create, use function
MoveWindow

BOOL MoveWindow(

    HWND  hWnd,      // handle of of you control
    int  X,      // horizontal position
    int  Y,      // vertical position
    int  nWidth,      // width
    int  nHeight,      // height
    BOOL  bRepaint = TRUE       // repaint flag
   );      
For define old Position
use GetWindowRect(hWnd, &lpRect);
and , for Example, make scaling old Position to new with
float koeef = (float)nNewXScreen/(float)nOldXScreen;
Can be, it helps.
Best Regards, Alex