Have you heard of the MSDN Code Gallery? Well here it is: http://code.msdn.microsoft.com/.
If you are a developer blogger or just want to make some code public for others to enjoy, this is an option to upload stuff without having to have a dedicated public server.
Sunday, November 30, 2008
Targeting WVGA Screens on Windows Mobile/Smartphone
I wrote a post recently here. I showed a simple technique for supporting multiple screen resolutions when writing GDI code on Windows Mobile. The code doesn't change even with the new WVGA screens (640x800) coming to market. I've copied the code here:
private int DESIGNPOINTSPERINCH = 96;
protected override void OnPaint(PaintEventArgs e)
{
Graphics grfx = e.Graphics;
Brush foreColorBrush = new SolidBrush(Color.Black);
Font boldFont = new Font(Font.Name, 20, FontStyle.Bold);
grfx.DrawString("Hello World!",
boldFont, foreColorBrush,
20 * grfx.DpiY / DESIGNPOINTSPERINCH,
20 * grfx.DpiY / DESIGNPOINTSPERINCH);
boldFont.Dispose();
foreColorBrush.Dispose();
}
Wednesday, November 26, 2008
Submitting an IFramed Web App running within Microsoft CRM 4.0 - from CRM
Jan 09 UPDATE: I have written a better way to do this here.
This is a quick tip that might save you hours trying to figure this out (or maybe not) which is to force a page submit when the user clicks save within CRM.
In the JavaScript OnLoad event of the Form in CRM, place the following JavaScript:
document.frames("IFRAME_name").document[0].submit();
Where "IFRAME_name" is the actual name of your IFrame.
Then in your OnLoad event of your ASPX web page, you can write something like:
This is a quick tip that might save you hours trying to figure this out (or maybe not) which is to force a page submit when the user clicks save within CRM.
In the JavaScript OnLoad event of the Form in CRM, place the following JavaScript:
document.frames("IFRAME_name").document[0].submit();
Where "IFRAME_name" is the actual name of your IFrame.
Then in your OnLoad event of your ASPX web page, you can write something like:
if (IsPostBack)Note, for each postback you'll end of saving the form - something to bear in mind.
Save();
Creating a managed configuration service provider API article
UPDATE: Now published on MSDN which has nicer formatting.
I recently wrote an article for MSDN which can be found here about writing a managed configuration service provider API which is extensible.
Microsoft has also published the article on the Microsoft Developer Centre over at http://www.devx.com/MS_DeveloperCentre/Article/40015 but there is no code attachment included with the article as the article refers other than the code in the document. So until the whole thing is published on MSDN I thought I'd upload the code on the MSDN code gallery which can be found here, or if you prefer a direct link to the code here.
Note: This article kind of extends this post to a much greater level. I decided not to label it "Part 2" though.
Tuesday, November 25, 2008
Micro Focus Case Study with COBOL managed support
Way back in the day....I used to work very closely with Micro Focus. If you didn't know Micro Focus develop a COBOL compiler and IDE called NetExpress. Their latest offering includes support for a COBOL compiler than compiles to IL which plugs into Visual Studio 2008 so COBOL developers can write managed code. The latest version of NetExpress is v5.1.
Micro Focus did a case study on the company I worked for at the time here (if you're interested :))
Micro Focus did a case study on the company I worked for at the time here (if you're interested :))
Monday, November 24, 2008
IE 6 on 6
As you've probably heard by now (announced at Tech Ed EMEA) that Windows Mobile 6.1 Pro and Standard emulators have been released and can be downloaded from here.
One thing I thought I'd mention is the support for WVGA screens (800x640) with these new emulators. So you can test for devices such as the new Samsung i900 or the HTC Touch Pro without having to actually own these expensive devices.
Also IE 6 on 6 (Internet Explorer 6 Mobile) is included in these emulator images. If you don't know what 6 on 6 is, it is the IE engine running on the device. I'm not a "web" guy but this is pretty cool stuff. But sadly this version of IE requires a new ROM image which means you will have to buy a new device or wait for your device OEM/carrier to issue a flash upgrade.
Internet Explorer 6 Mobile
One thing I thought I'd mention is the support for WVGA screens (800x640) with these new emulators. So you can test for devices such as the new Samsung i900 or the HTC Touch Pro without having to actually own these expensive devices.
Also IE 6 on 6 (Internet Explorer 6 Mobile) is included in these emulator images. If you don't know what 6 on 6 is, it is the IE engine running on the device. I'm not a "web" guy but this is pretty cool stuff. But sadly this version of IE requires a new ROM image which means you will have to buy a new device or wait for your device OEM/carrier to issue a flash upgrade.
Internet Explorer 6 Mobile
Saturday, November 22, 2008
Extension method support in Compact Framework 2.0 applications
I had a discussion recently with my fellow MVPs and you can use C# 3.0 language features in a CF 2.0 app with VS 2008 and even extension methods with a small hack.
Simply create an ExtensionAttribute class:
Daniel Moth has talked about this in depth here.
Simply create an ExtensionAttribute class:
using System.Runtime.CompilerServicesThen you need to declare this attribute on each extension method in order to implement extension methods. This is because extension methods require the new ExtensionAttribute class introduced in System.Core.dll in .NET 3.5.
{
public class ExtensionAttribute : Attribute{}
}
Daniel Moth has talked about this in depth here.
Action Delegate on the Compact Framework 3.5
I wanted to just raise awareness of the new Action delegate available on the Compact Framework 3.5. It saves the need to explicitly create delegates then assign methods or even using anonymous delegates as in CF 2.0. This shouldn't be confused with the generic Action delegate introduced in .NET 2.0.
I mentioned the Action delegate in a session I did at Tech Ed EMEA recently and it seems not many people are using it or are aware that it even exists, hopefully this post should change that.
In the bad old days of pre .NET CF 2.0 we had to write some code like the following:
The above code is long and complicated. This is where the Action delegate makes this simple. Consider the above refactored to the following:
Of course you only need to use Invoke and Action in the above example if the event was received on a thread other than the one that owns the controls underlying window handle (UI thread).
Take another scenario that uses the Action delegate. In this example it is a situation where you have some code to be executed, but each time it is executed you want to do some other stuff first. This initial stuff might need to be specified by the caller at runtime. Consider the following code:
If we run this code and click the button, the output is as follows:
I mentioned the Action delegate in a session I did at Tech Ed EMEA recently and it seems not many people are using it or are aware that it even exists, hopefully this post should change that.
In the bad old days of pre .NET CF 2.0 we had to write some code like the following:
public MyClassThe above senario is not uncommon for device developers. We are used to writing worker threads to "listen" or just do some work on a separate thread. At some point we need to tell the user that something happend.
{
private delegate void StorageCardRemoved(string message);
private StorageCardRemoved storageCardRemoved = null;
public MyClass()
{
storageCardRemoved =
new StorageCardRemoved(ShowStorageCardRemovedNotification);
}
private void ShowStorageCardRemovedNotification(string name)
{
MessageBox.Show(name);
}
//Event handler from some worker process running somewhere.
private void DeviceManagement_StorageCardRemoved(object sender,
StorageCardChangedEventArgs args)
{
Invoke(storageCardRemoved, args.Name);
}
}
The above code is long and complicated. This is where the Action delegate makes this simple. Consider the above refactored to the following:
public MyClassHow much simpler is that. The only limitation with this is that you can't call anything passing parameters. So you couldn't for example delay the message box processing by calling another delegate as you wouldn't be able to pass it the name (as in this case). This is a limitation within the Invoke method not supporting a paramerterized Action delegate. The action delegate supports upto 4 generic parameters with no returning type. This is the same functionality as per the desktop.
{
//Event handler from some worker process running somewhere.
private void DeviceManagement_StorageCardRemoved(object sender,
StorageCardChangedEventArgs args)
{
Invoke(new Action(() => MessageBox.Show(args.Name)));
}
}
Of course you only need to use Invoke and Action in the above example if the event was received on a thread other than the one that owns the controls underlying window handle (UI thread).
Take another scenario that uses the Action delegate. In this example it is a situation where you have some code to be executed, but each time it is executed you want to do some other stuff first. This initial stuff might need to be specified by the caller at runtime. Consider the following code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var businessClass =
new BusinessClass(() => Debug.WriteLine("Do initialization stuff"));
businessClass.Process(() => Debug.WriteLine("Now do business process"));
}
}
public class BusinessClassWe have a form with a button event handler hooked up to a button. When we click the button the event handler is called. When we construct the BusinessClass, we pass in the constructor an initialization Action delegate that gets executed when the Process method is called and before the Process Action delegate gets executed.
{
public BusinessClass(Action init)
{
Init = init;
}
public Action Init
{
internal get;
set;
}
public void Process(Action action)
{
Debug.WriteLine("Now entered Process");
Init();
action();
}
}
If we run this code and click the button, the output is as follows:
Now entered ProcessAs you can see, it is quite a powerful and easy implementation. Next I'll talk about the Func delegate....
Do initialization stuff
Now do business process
Friday, November 21, 2008
Designed for Windows Mobile 6 - Guidelines
I had a discussion recently regarding the location of the updated "Designed for Windows Mobile handbook". It can be found here, in PDF format.
I thought I'd post this for my own personal reference as well as others, as I'm always losing it, no longer! :)
Subscribe to:
Posts (Atom)