Jul 20, 2010

Determine how big an array can be allocated.

long FreeBytes = New System.Diagnostics.PerformanceCounter("Memory", "Available Bytes").NextValue();

This means that you can allocate new byte[FreeBytes];

Jul 6, 2010

Simulate Click on PDA (.Net Compact Framework)

It turns out that to simulate a click in .NET Compact Framework is indeed a difficult problem. The normal way of using mouse_event() and SetCursorPos() does not work because SetCursorPos() does not work. Therefore, a click event always occurs on (0,0).

There is a workaround, though it is not quite comfortable as the normal way. This is because you need a Form object on which you want to click on.

Here is the source code.


[DllImport("coredll.dll")]
public extern static int SendMessage(IntPtr hwnd, uint msg, uint wParam, uint lParam);

public const int WM_LBUTTONDOWN = 0x0201;
public const int WM_LBUTTONUP = 0x0202;

private static int delay = 100;

private static uint MakeDWord(int hiword,int lowword)
{
return ((uint)hiword * 0x10000) | ((uint)lowword & 0xFFFF);
}

private delegate IntPtr d_GetHandle(Form f);
private static IntPtr GetHandle(Form f)
{
return f.Handle;
}

internal static void LeftClick(Form form, int x, int y)
{
IntPtr handle = (IntPtr)(form.Invoke(new d_GetHandle(GetHandle), new object[] { form }));

SendMessage(handle, WM_LBUTTONDOWN, 1, MakeDWord(y, x));
Thread.Sleep(delay);
SendMessage(handle, WM_LBUTTONUP, 1, MakeDWord(y, x));

}