Archive for March 2008
March 31st, 2008
Five years ago, if you wanted to do a screen capture on Windows Mobile devices with .NET Compact Framework, you would look at Screen Capture, I did not count the lines, but looked quiet long. Five years later, I wanted to do the same thing, and my code looked like this:
public static Bitmap ScreenCapture(IntPtr hWnd, Rectangle rect)
{
IntPtr hBitmap;
IntPtr hDC = CoreDll.GetDC(hWnd);
IntPtr hMemDC = CoreDll.CreateCompatibleDC(hDC);
hBitmap = CoreDll.CreateCompatibleBitmap(hDC, rect.Width, rect.Height);
if (hBitmap != IntPtr.Zero)
{
IntPtr hOld = (IntPtr)CoreDll.SelectObject(hMemDC, hBitmap);
CoreDll.BitBlt(hMemDC, 0, 0, rect.Width, rect.Height, hDC, 0, 0, CoreDll.SRCCOPY);
CoreDll.SelectObject(hMemDC, hOld);
CoreDll.DeleteDC(hMemDC);
CoreDll.ReleaseDC(hWnd, hDC);
Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap);
CoreDll.DeleteObject(hBitmap);
return bmp;
}
return null;
}
The CoreDll imports:
[DllImport("Coredll.dll", EntryPoint = "GetDC")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImportAttribute("coredll.dll", EntryPoint = "GetWindowDC")]
internal static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("Coredll.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("coredll.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
[DllImport("coredll.dll")]
public static extern IntPtr CreateDIBSection(IntPtr hdc, IntPtr hdr, uint colors, ref IntPtr pBits, IntPtr hFile, uint offset);
[DllImport("coredll")]
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
[DllImport("coredll")]
public static extern int DeleteDC(IntPtr hdc);
[System.Runtime.InteropServices.DllImportAttribute("coredll.dll", EntryPoint = "ReleaseDC")]
internal static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("coredll")]
public static extern IntPtr DeleteObject(IntPtr hObject);
Posted in .NETCF, Mobile | No Comments »
March 27th, 2008
Let’s say you developed a MSFT Windows mobile software, in the WM5 world, you probably named your product as "XYZ for Windows Mobile 5 Pocket PC edition" and "XYZ for Windows Mobile 5 Smart Phone edition".
These names are fine for people working with WM systems, but for end users, the word "Smart Phone" might create a lot of confusions. The problem is more and more Pocket PC devices have phone functions, are they Pocket PCs or Smart Phones? A lot of users might choose the wrong software for the wrong devices.
I use the following simple method to explain this to the end users, it seems working well:
Looking for the "Start" menu on your device, if it's in the top left corner, choose the Pocket PC software; if it's in the lower left corner, use the Smart Phone software.
|
|
Pocket PC
|
Smart Phone
|
Posted in Mobile | No Comments »
March 24th, 2008
On Windows Mobile devices, there is a Time out setting for the Home or Today screen. When this time out value is reached, WM will hide whatever program is running and display the Home/Today screen.
This causes a problem for one of my project. In my project, if the MessageBox.Show(…) function is called and the home/today screen kicks in before the user closes the message box, my program is hidden, and the user has no way to get back in, except turn the device off then on again.
The reason is obvious, modal dialog boxes, like message boxes, block the UI thread until they are closed. But how do you close a message box while it’s hidden? After some googling plus try and error, I came up with the following solution:
const int WM_DESTROY = 0x02;
[DllImport("coredll.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("coredll.dll", EntryPoint="SendMessage")]
private static extern uint SendMessage(IntPtr hWnd, uint msg, uint wParam, uint lParam);
public static void KillWindow(string className, string title)
{
IntPtr handle = FindWindow(className, title);
SendMessage(handle, WM_DESTROY, 0, 0);
}
public static void CloseMessageBox(string title)
{
IntPtr handle = FindWindow("Dialog", title);
SendMessage(handle, WM_DESTROY, 0, 0);
}
Posted in .NET, Mobile | No Comments »
March 20th, 2008
Both involve MIME type setup on IIS.
1. WCF: If your WCF does not work on your production IIS server, most likely the .svc MIME type is not registered, I used the following command line to fix it:
c:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg -i
2. Silverlight, you need to register the .xap MIME type, for IIS 7, simply using the following command line:
C:\windows\system32\inetsrv\appcmd set config /section:staticContent /+[fileExtension='.xap',mimeType='application\x-silverlight-app']
For both cases, the "C:\Windows\" directory path depends on where your OS is installed.
Posted in ASP.NET, SOA, Silverlight | No Comments »
March 14th, 2008
I am trying to write my first Silverlight application. I need to do data binding, I already have a set of business objects written in an existing project. Naturally, I want to reference that project and reuse the business objects. But VS 2008 won’t allow me to reference the project, says I can only reference Silverlight projects. Fine, how about reference the .dll then? Same thing, VS 2008 complaints the .dll is not built with Silverlight. Why?
It clicked in 10 minutes later while trying different things: a Silverlight application is a client side application, it should never directly using business objects, which sit on the server side. The server side objects and operations should be exposed as services, which then can be consumed by Silverlight applications.
Posted in ASP.NET, SOA, Silverlight | No Comments »
March 10th, 2008
In one of my managed code project, I need to determine if a table exists in SSC. This is pretty easy to do in regular SQL Server with T-SQL:
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[MyTable]') AND type in (N'U'))
SELECT 'Table exists.'
ELSE SELECT 'Table does not exist.'
However, this does not work in SQL Server Compact Edition. First of all, SSC does not have sys.objects, second, SSC does not support conditional T-SQL.
After googling a bit, I found the first problem can be solved by using INFORMATION_SCHEMA.TABLES, how about the second problem? I just could not find any conditional T-SQL reference in SSC.
I ended writing a c# function like this:
public static bool DoesTableExist(string tableName, SqlCeConnection ssceconn)
{
string exsitTSql = @"SELECT COUNT(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='" + tableName + "'";
int cnt = (int) ExecuteScalar(exsitTSql, ssceconn);
return (cnt == 1);
}
Posted in Mobile, SQL | No Comments »
March 8th, 2008
Watched Nigel Eillis’ MIX08 presentation today: http://sessions.visitmix.com/?selectedSearch=BT05. Here is a short summary on what I have learned about SSDS.
- SSDS is a layer of WS been put on top of MSFT’s 18k+ SQL servers.
- Taking Invitation only Beta application now, public Beta within 6 month, go live in Q1, 09.
- SSDS supports REST and SOAP services now, will support more later.
- There are three concepts you need to know:
- Authority
- Container
- Entity
- Authority contains Containers, and Container contains Entities.
- No schema is needed for Containers and Entities.
- Entities have two kinds of properties:
- Fixed properties. There are three so far: ID, Kind, Version. They are referenced as SomeEntity.ID, SomeEntity.Kind, SomeEntity.Version.
- Flex properties. Can be any number if them. Referenced as SomeEntity["SomeProperty"]. Same property name on different entities needs not to be the same type. E.g. “DatePublished” on EntityA can be a datetime, but on EntityB could be a string.
- Queries are in LINQ like syntax.
- Product Page: http://www.microsoft.com/sql/dataservices/default.mspx.
- Team Blog: http://blogs.msdn.com/ssds
Posted in SQL | No Comments »
March 7th, 2008
If you don’t get to go to MIX, this years sessions are available here. Lots of good stuff and good too see they built the whole thing with Silverlight. So far, there are more than 60 sessions available, will take days if you go through them all.
Posted in .NET, ASP.NET, Silverlight | No Comments »
March 5th, 2008
Another beta release from MSFT: ASP.NET MVC Preview 2.
I mainly using MonoRail for my MVC stuff, have not looked at ASP.NET MVC yet, I only know ASP.NET MVC will support NVelocity view engine, which is the engine I use.
Posted in .NET, ASP.NET | No Comments »
March 5th, 2008
I just got access to Amazon SimpleDB last Friday, yet get a chance to look at it. Today, Microsoft announced Microsoft SQL Server Data Services (MSSDS).
“The service is designed for developers building Web-based applications that need a scalable, easily programmable and highly available utility-based data store.”
You can pre-register for the beta here.
I am anxious to take a look at this, since I already know a lot about MS SQL Server, I might use this a lot more than Amazon SimpleDB.
Posted in SOA, SQL | No Comments »
March 5th, 2008
I like source code, I like to read them, tweak them, and break them.
Here is the source code package for Silverlight 2.0 controls.
http://download.microsoft.com/download/6/5/e/65e6d2b0-8f7e-4e08-ae62-31f03d664f73/Silverlight2Beta1Controls.exe
Posted in Silverlight | No Comments »
March 5th, 2008
Microsoft announced silverlight for mobile today.
http://silverlight.net/learn/mobile.aspx
It will be a plugin for browsers, starts out with WM6, will go on Nokia phones as well.
Wondering if they are going to port WPF to mobile as well.
Posted in Mobile, Silverlight | No Comments »