Nuo Yan

Problem Solved

Recent Posts

Tags

News


  • Follow me on twitter: @nuoyan
    Make a donation to this Blog by PayPal. Thanks!






    Nuo is currently a Software Development Engineer in a Seattle-based software company.




    Locations of visitors to this page

    The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my school or employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.


Community

Email Notifications

Archives

July 2007 - Posts

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. 

Using Remote Spy++ To Check Window Messages in Windows Mobile Applications

Windows programming in native C++ is generally considered far more complex than in managed code. Programming for Windows Mobile devices is very similar with Windows programming. Sometimes we need to figure out which Window message is sent so we can write the corresponding event handling code. However, we can't use Spy++ to do so because we are either debugging our application in the device emulator which is a virtual machine or an actual device.

Visual Studio has a tool called Remote Spy++ (with an array of other remote tools), which provides us the functionality to work with device emulators and/or  actual connected devices. So if you don't know this guy yet and want to use Spy++ for your device application, you can go ahead and try. It's pretty cool and may save you a lot of work to watch for the right messages.

Posted: Wed, Jul 4 2007 10:30 by Nuo Yan | with 3 comment(s) |
Filed under: