Windows Mobile: Getting Screen Size Information Before Main Window Is Loaded
I wanted to develop a screen size aware application, which will draw all application dialogboxes and windows dynamically depends on the actual screen size of the device. It will not be that hard to adapt the main application window to the screen size because GetWindowRect() or GetClientRect() functions can be used to get the screen size when the main window is loaded.
However, if the application has a pop-op dialogbox for user to do some selections before the main window is loaded, how can I make the dialogbox aware of the screen size? Since main application window hasn't loaded yet so GetWindowRect() and GetClientRect() won't get the correct value for screen size.
I thought about it, asked people around me and looked for some related resources, then I found two solutions.
The first way of doing it is to use GetSystemMetrics() function. It can get the screen size even the main application window hasn't been loaded yet. So if I define two int variables height and width, then I can set:
height = GetSystemMetrics(SM_CYSCREEN);
width = GetSystemMetrics(SM_CXSCREEN);
Then I can use MoveWindow() under WM_INITDIALOG message handler to make the dialogbox aware of screen size.
The second way of doing it can be delaying the display of the dialogbox until main window is initialized (not necessarily shown). To implement it this way, I need to have a global integer variable storing the state of the application. It can be set to a specific value, then as the main window has been initialized, set the global integer to another value. Then have a test of the value, to judge when to display the dialogbox. At the time the dialogbox can be displayed, main application window is already initialized so GetWindowRect() function can return the appropriate screen size information.