50% OFF!!!

Showing posts with label windows mobile. Show all posts
Showing posts with label windows mobile. Show all posts

Monday, April 6, 2009

Compact Framework | debugger and monitoring

.NET Compact Framework Power Toys 3.5

The Power Toys for .NET Compact Framework 3.5 provides several tools for evaluating performance, obtaining diagnostic information, configuring and working with the .NET Compact Framework.


The Tools
NETCF CLR Profiler – CLR Profiler is an instrumenting allocation profiler for NETCF applications. It provides detailed allocation visualizations, allocation callstacks and other views of the managed heap for diagnosing various memory management issues.
NETCF ServiceModel Metadata Tool – The .NET Compact Framework ServiceModel Metadata Tool (netcfsvcutil.exe) allows you to generate a Windows Communication Foundation (WCF) client proxy to help developers consume WCF services on device. Like svcutil.exe, which is the desktop version of the utility, netcfsvcutil.exe is a command-line tool that generates service model code from metadata documents and generates metadata documents from service model code.
App Configuration Tool - On-device tool for specifying what version of NETCF an application will run against (ie. Create config file), displaying installed versions of NETCF and displaying info about DLLs in the GAC.
Remote Logging Configuration Tool– The Logging Configuration Tool enables users to easily configure logging options on a NETCF device including: loader, interop, network, error and finalizer logs. (used to be a part of RPM)
Remote Performance Monitor and GC Heap Viewer – Provides real time counter data (ranging from Garbage Collector activity to type loading info) on a running NETCF application. The GC Heap Viewer feature allows you to capture the managed heap at any moment your app is running to view live references, and allows you to compare multiple snapshots to find memory leaks.
NETCF Network Log Viewer – A utility for viewing NETCF network log data.

download link:

http://www.microsoft.com/downloads/details.aspx?FamilyID=c8174c14-a27d-4148-bf01-86c2e0953eab&displaylang=en

Sunday, December 7, 2008

Windows Mobile | Get current displayed window


Find which window is running right now.
Used for determining if OUR window is on background or not.



[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr GetForegroundWindow();




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...

Monday, August 25, 2008

Picture with transparent label


A picturebox object that supports a label (transparent).
this allow to create a piture button and add text it.
This control tested and working :)

use it with wisdom... or not:
have fun:



public class PictureText : PictureBox, ISupportInitialize
{
#region #region Private Data-Members

private string _textDisplayed = string.Empty;

private Font _textFont = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Bold);

private Color _textForeColor = Color.Black;

#endregion

public string TextDisplayed
{
get { return _textDisplayed; }
set
{
_textDisplayed = value;
this.Invalidate();
}
}
public Font TextFont
{
get { return _textFont; }
set
{
_textFont = value;
this.Invalidate();
}
}
public Color TextForeColor
{
get { return _textForeColor; }
set
{
_textForeColor = value;
this.Invalidate();
}
}

//protected override void OnPaintBackground(PaintEventArgs e)
//{
// base.OnPaintBackground(e);

// //HorizontalAlignment.
// if (string.IsNullOrEmpty(TextDisplayed) == false)
// {
// e.Graphics.DrawString(this.TextDisplayed, this.TextFont, new SolidBrush(this.TextForeColor), this.Location.X, this.Location.Y);
// }
//}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

if (string.IsNullOrEmpty(TextDisplayed) == false)
{
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;

e.Graphics.DrawString(this.TextDisplayed, this.TextFont, new SolidBrush(this.TextForeColor), this.Width / 2, this.Height / 2, sf);
}
}
}

#region ISupportInitialize Members
public void BeginInit()
{
}
public void EndInit()
{
}
#endregion
}




Tuesday, August 19, 2008

Making control RTL or LTR

As many people asked me for making rtl or ltr controls on the compactframework.
My best solution for this question is:

public const int GWL_EXSTYLE = (-20);
public const int WS_EX_LAYOUTRTL = 0x400000;
public static void SetControlDirection(Control c, bool p_isRTL)
{
int style = GetWindowLong(c.Handle, GWL_EXSTYLE);

// set default to ltr (clear rtl bit)
style &= ~WS_EX_LAYOUTRTL;

if (p_isRTL == true)
{
// rtl
style = WS_EX_LAYOUTRTL;
}

SetWindowLong(c.Handle, GWL_EXSTYLE, style);
c.Invalidate();
}


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

[DllImport("coredll.dll")]
static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);





CE OS supported:

I tried on "Windows Mobile 6 Classic" emulator and it worked. (CE OS = 5.2)

On "Windows Mobile 5.0 Pocket PC" emulator, also worked. (CE OS = 5.1)


On "Pocket PC 2003 SE" emulator, it did NOT worked! (CE OS = 4.21)


Free Image Hosting at www.ImageShack.us

Download sample test





I hope it will be helpful for you... :)

Tuesday, August 12, 2008

Auto Sized Label for cf

Auto Sized Label control for the compact framework:

I noticed that there is no solution for an autosized label (auto width & height)

so i build my example for this control:




public class AutoSizeLabel : Label
{
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
ReCalculateSize();
}
}
public override System.Drawing.Font Font
{
get
{
return base.Font;
}
set
{
base.Font = value;
ReCalculateSize();
}
}
private void ReCalculateSize()
{
using (Control control = new Control())
{
using (Graphics g = control.CreateGraphics())
{
SizeF size = g.MeasureString(base.Text, base.Font);
base.Width = (int)size.Width + 1;
base.Height = (int)size.Height + 1;
}
}
}
}


i hope it will help you...