Wednesday, 21 November 2007

Adding a new mailbox to you exchange settings in Outlook 2003

How to open another inbox to add to your mail folders in Outlook 2003. Make sure first you are delegate or have access to the box.

1. On the Tools menu, click E-mail Accounts.
2. Click View or change existing e-mail accounts, and then click Next.
3. Click the Exchange Server account, and then click Change.
4. Click More Settings.
5. On the Advanced tab, under Mailboxes, click Add.
6. Type the other user's name, and then click OK twice.
7. Click Next, and then click Finish.

Friday, 16 November 2007

Greenfish Icon Editor Pro

I found this really useful 'free' icon editor from a company in Hungary called Greenfish Corporation. Very handy.

NB: All over icon utilities I found on the net were shareware crap and didn't work that well.

Greenfish Icon Editor Pro

This program is a professional, yet easy to use tool for creating icons, cursors, and other small pixelgraphic images. It has a wide range of features, including:

* Opening and saving in ICO, CUR, PNG, XPM, BMP and JPEG formats
* Creating icons up to 256x256 @ 32-bit
* Creating Vista(tm)-compatible, PNG compressed icons
* Sophisticated selecting tools like marquee, lasso and magic wand, as in a professional photo editor
* Creating and testing cursors
* Extracting icons and cursors from executable files
* Dynamic color depth: you do not have to specify it explicitly, Greenfish Icon Editor will determine it for you.
* Painting easily in 32-bit
* Drawing lots of kinds of gradients
* Lots of filters including Remove matte, Drop shadow, Inner/Outer glow and Bevel
* Sample icons are included
* No installation required, Greenfish Icon Editor Pro is absolutely portable
* It is FREE!

Can get it from here.
Greenfish Corporation: "Lots of filters including Remove matte, Drop shadow, Inner/Outer glow and Bevel"

Thursday, 15 November 2007

Disabling the Window Close Button and System Close menu in a Windows Form

A useful snippet for disabling the X button on a window form in c#:

1. Use an api call to user32.api

Basically, this call uses GetSystemMenu() to get a handle to the menu with the close, maximize and minimize buttons. Then, the EnableMenuItem() call comes along and sets it so that the close button is greyed out (i.e. disabled).

NB. The code needs to go in the Paint handler because otherwise the changes to the close button will not be retained when the form is repainted (e.g. when you minimise and then restore).

C# Source:


Use these constants

///
/// Windows constant that represents the X button on a window
///
private const int SC_CLOSE = 0xF060;

///
/// Menu API Constant: Enables the menu item so that it can be selected and restores it from its grayed state.
///
private const int MF_ENABLED = 0;

///
/// Menu API Constant: Disables the menu item and grays it so it cannot be selected.
///
private const int MF_GREYED = 0x1;

///
/// Menu API Constant: Identifies menu item position by command.
///
private const int MF_BYCOMMAND = 0;

Then add references to the api windows methods:

///
/// Windows api call to get the system menu
///
/// hWnd Handle of window

/// revert Specifies the action to be taken. If this parameter is FALSE, GetSystemMenu returns a handle to the copy of the window menu currently in use. The copy is initially identical to the window menu, but it can be modified. If this parameter is TRUE, GetSystemMenu resets the window menu back to the default state. The previous window menu, if any, is destroyed.
/// returns variable: if the bRevert parameter is FALSE, the return value is a handle to a copy of the window menu. If the bRevert parameter is TRUE, the return value is NULL.
[DllImport("user32")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, int revert);

///
/// Windows api call to enabling a menu item
///
/// hWndMenu handle to the window menu
/// itemID item to enable
/// enable enable/disable/greyed
/// returns variable: The return value specifies the previous state of the menu item (it is either MF_DISABLED, MF_ENABLED, or MF_GRAYED). If the menu item does not exist, the return value is -1.
[DllImport("user32")]
private static extern int EnableMenuItem(IntPtr hWndMenu, int itemID, int enable);

This private field to represent if the close x is enabled/disabled

///
/// Flag to represent if a form window close x is enabled/disabled
///
private bool closeEnabled = false;

and finally a public property - so we can access this outside the form if required.

///
/// Property manages the visibility of the X close button on this form window
///
public bool CloseEnabled
{
get { return closeEnabled; }
set
{
//Decide on the state to pass based on the value being set
int setting = (value) ? MF_BYCOMMAND | MF_ENABLED : MF_BYCOMMAND | MF_GREYED;

try
{
EnableMenuItem(GetSystemMenu(this.Handle, 0), SC_CLOSE, setting);
}
catch { }
closeEnabled = value;
}
}


2) Set the 'ControlBox' property on the form to false

this.ControlBox = false;

However this disables the entire system menu strip - i.e. icon drop down etc. so may not be of use.

Also by holding down ALT-F4 - this often closes an application window and therefore you would need to capture this in the form_closing event - and set event args e to cancel.

i.e. e.cancel = false;