Nuo writes:
Since Windows Mobile devices will be manufactured from different hardware manufacturers, so I need to adapt my application to devices with different screen sizes.
The first approach I thought to use was to make several fixed cases: 640*480, 320*320, 320*240, and 240*240. Then hard code the window and control size information for these different cases. My reasoning was basically all of the current devices are equipped with these screen sizes so the application will fit well for almost all devices.
However, with some deep thinking and advises from others, I realized this is really a bad approach. As an application developer, I should not assume the application will run on the devices with these specific screen sizes. Nothing should be hard coded, and all window sizes should be determined when the application loads.
The screen layout of the application will look like:
What I need to do is to determine the screen size of the device before this interface is loaded, then determine the location and size of the child windows and controls. The way I get the screen size of the device is to use GetWindowRect() function. For the location and size of the controls, I did quite a bit mathematical calculation, and get the following equations which I believe are fitting all screen sizes.
Size of each of the nine ink window = screen height / 6
Blanks in between each ink window = screen height /32
Status label on the top of user interface (vertical starting point) = (screen width – 3 * ink window size – 2* blanks in between)/2Status label on the top of user interface (horizontal starting point) = screen width /32Label length = screen width – 2 * label vertical starting pointLabel height = screen height /14Height of each button = screen height /16
With these variables, other positions of the windows and controls can be easily calculate without hard coding their values.
In addition to adapt the application to the screen size of the device at the time the application loads, I also need to concern about the orientation change of the screen. Orientation change in Windows Mobile application development is quite like window size change in general Win32 programming. So I specified the WM_SIZE message handler for the main application window, and called MoveWindow() function several times to move the windows and controls to the right place. Exact same equations are used here in MoveWindow() as in CreateWindow() above. So the application will adapt the new screen size if orientation has changed.
However, beside the main application interface, there will be two dialogboxes giving user the choice of playing a user versus user game or user versus computer game. The two dialogboxes loads before the main application window so GetWindowRect() won’t get the correct window size for those dialogboxes. I got stuck here and I thought of a lot of complex ways to make the dialogboxes screen size aware. Luckily, after looking for some resources about this issue, I found a function called GetSystemMetrics() in the SDK which can get the device screen size even before the main application window has loaded. So I declare two int variables height and wdith, then do the following:
height = GetSystemMetrics(SM_CYSCREEN);width = GetSystemMetrics(SM_CXSCREEN);
Then I have the screen size data. I specified WM_INITDIALOG in the dialogbox procedure put the above code under that event handler to get screen size. Then I use MoveWindow() to actually make the dialogbox as big as the screen size. As same as the main application window, I also specified WM_SIZE for the dialogbox procedure for the cases screen orientation changes.
Now the application is screen size/orientation aware. This is easier to implement than I thought, so I can move ahead faster than planned. Next time I will talk about the user versus computer game logic of my application.
P.S. Several days ago all Entertainment & Devices interns went to a cruising event. We cruised between Kirkland WA and downtown Seattle on Lake Washington. Nice food and activities were provided on the boat (or ship). I really had a lot of fun! :-D
Nuo