Changing the color of MainMenu - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Changing the color of MainMenu

AsAdiAsAdi Posts: 117Member
I would likt to change the color of MainMenu control in a MDI form using Windows API,so I derived a FMainMenu class from MainMenu and added one method named SetMenuBkColor.Here is my code

public class FMainMenu : System.Windows.Forms.MainMenu
{
[DllImport("GDI32.DLL")]
private static extern long SetBkColor(int hdc,long color);
[DllImport("USER32.DLL")]
private static extern int GetDC(int hwnd);

public void SetMenuBkColor(long ColorRef)
{
try
{
int hdc=GetDC((int)(this.CreateMenuHandle()));
SetBkColor(hdc,ColorRef);
}
catch(System.Exception e)
{
MessageBox.Show(e.Message); }
}
}
And I call this method later in my form load event like this:
myMenu.SetMenuBkColor(0xffffff);
to make the menu color white.But it doesn't work properly and the color doesn't change.I know there is a problem with calling API,maybe casting isn't correct or something else.

Any one can tell me what happens with this code and what's wrong with it?

Thanks alot
Reza
Sign In or Register to comment.