Blond Mobile


Archive for the ‘Windows Mobile How To's’ Category

Windows Mobile: How to take screenshots of your device or emulator

Wednesday, July 16th, 2008

In order to take a screen shot of your handset or of the emulator you should do the following:

1- Open the “Remote Zoom In” application from the “Visual studio Remote Tools”

WM screenshot

2- Select to what device or emulator you want to connect. In case your connecting to a device make sure its connected to the PC with the USB cable.

windows mobile screenshot

3- the application will connect to the device/emulator  and you will see the screenshot. if you would like to take another screenshot, just click the “Refresh” button

4 - To save the screenshot, select “Save as”.

Windows Mobile, C#: How to stop a thread after calling CeRunAppAtEvent / WaitForSingleObject

Thursday, April 17th, 2008

In a previous post, I wrote about how to run a method when the device wakes up, or comes back from sleep mode. In that post I wrote about calling the CeRunAppAtEvent native function, which signals a given  event (hEvent) when the device wakes up.  I used the WaitForSingleObject(hEvent, INFINITE) function to wait until the hEvent is signaled.

The problem occurs when wanting to close the application, and a thread, which called the WaitForSingleObject()  is still waiting for the event. In that post, I wrote that in case wanting to close the application the below function should be called in order to terminate the waiting thread.

public static void Close()
{
    _close = true;
    if(_wakeupServiceThread != null)
       _wakeupServiceThread.Abort();
}

Unfortunately, The wakeupServiceThread could not be aborted, since it was waiting due to the call to WaitForSingleObject function.

The solution was to stop waiting on the WaitForSingleObject function,  and for that the _nativeWakupEvent event needed to be signaled.

Here is the code:

[DllImport("coredll.dll", SetLastError = true)]
        public static extern bool EventModify(IntPtr hEvent,
            [In, MarshalAs(UnmanagedType.U4)] int dEvent);
private const int NATIVE_EVENT_SET = 3;

public static void Close()
{
     _close = true;
     if (_hEvent != IntPtr.Zero)
             SetEvent(_hEvent);
}
private static bool SetEvent(IntPtr hEvent)
{
     return EventModify(hEvent, NATIVE_EVENT_SET);
}

Windows Mobile,C#: How to minimize your application/Send it to the background

Friday, April 11th, 2008

I wanted to send my application to the background. Simple enough, I just wrote Form.Hide() (or Form.visible = false). this did the job, my application was minimized and running at the background. At some point I wanted to use my application again, I clicked the applications icon, but nothing happend, I went to the running programs list in the settings, but my application was not there! my application was running in the background, and there was no way for me to close or access it!

Lucky enough, I used the Remote Process Viewer to find my application and kill it.

It seems that when Hiding a form (form.Hide()), The form is hidden from the user, and not only minimized. Funny that when clicking the “x” (which for some reason is called smart minimize), the application is minimized and sent to the background, where as using the hide() or visible=false, the application is hidden from the user and is not accessible.

The  Form class has a property which is called WindowsState. This property indicates the visual state of the form. unfortunately, the states that Windows Mobile/ .Net compact framework supports are ‘Normal’ and ‘Maximized’ and there is no support for the ‘Minimized’ state.

The solution for this problem is to call the Native function ShowWindow() with the ‘Minimized’ property:

[DllImport("coredll.dll")]
        static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

        const int SW_MINIMIZED = 6;

        public void Hide()
        {
            ShowWindow(_form.Handle, SW_MINIMIZED);
        }

Hiding the application this way, will not “hide” the application from the user, but only minimize it and the application will be  “reachable” from the running programs list.

Windows Mobile: How to view processes on a Windows Mobile Device or Emulator

Wednesday, April 9th, 2008

In a windows mobile device you can only view the running applications, and this is only if the application has a form. This means that you cannot view various processes that are running on a WM device, like you would be able to do on you PC, or Laptop using the “Task Manager’. fortunately, Visual Studio, has a solution for this problem:

Go to Visual Studio ->Remote Tools and select Remote Process Viewer

visual studio remote process viewer

Select the device which you would like to see its processes.

image

you will get a window, with all process that are running on your Windows Mobile device. In this window you will be able to view the processes and kill them, just like you would be able to do with the regular Windows “Task Manager”  :)

In addition to a list of processes, you can also see other info as threads, and from what module is the process.

image

Jajah is the VoIP player that brought you web-activated telephony.