50% OFF!!!

Booking.com

Monday, September 8, 2008

Single instance of Windows Form application (WinCE)


How to create a single instance application on Win CE?
-----------------------------------------------------------
this example run a single instance of application on WinCE operation systems (devices).

On WindowMobile 6 (Pocket PC) operation systems,
by default, only one instance of the app will run!


here a sample code for Unique application running (starting):



static class Program
{
///
/// The main entry point for the application.
///

[MTAThread]
static void Main()
{
IntPtr eventHandle = IntPtr.Zero;
try
{
String appName = "UniqueAppName_Event";
eventHandle = CreateEvent(IntPtr.Zero, true, false, appName );
bool isFirstInstance = Marshal.GetLastWin32Error() == 0;

if (isFirstInstance == true)
{
Application.Run(new Form1());
}
}
finally
{
if (eventHandle != IntPtr.Zero)
{
CloseHandle(eventHandle);
}
}
}

#region Imports
[DllImport("Coredll.dll", SetLastError = true)]
static extern IntPtr CreateEvent(IntPtr alwaysZero, bool manualReset, bool initialState, string name);

[DllImport("Coredll.dll", SetLastError = true)]
static extern int CloseHandle(IntPtr handle);
#endregion
}



this ensure a single instance of Windows Form application...

Tuesday, September 2, 2008

Compact Framework | Scrolling on control



Scrolling inside a control from the code is very simple.
All you have to do is to give the control the new location (Point: x,y)
and it will scroll to the new point...

My generic method scrolls the item each time by ~66% of its size (2/3)
Note: in my example, the scrolling obect is this!



int changeHeight = this.Height * 2 / 3;
if (p_pressedKey == Keys.Down)
{
this.AutoScrollPosition = new Point(this.AutoScrollPosition.X, -this.AutoScrollPosition.Y + changeHeight);
}
else if (p_pressedKey == Keys.Up)
{
this.AutoScrollPosition = new Point(this.AutoScrollPosition.X, -this.AutoScrollPosition.Y - changeHeight);
}