Search This Blog

Wednesday, May 6, 2009

How to change the "Start Menu" Text in Windows (Win32 VC++)


Intro

Windows Users must be familiar with the Start button -> the button on the lower left corner of Windows desktop placed on the Windows Taskbar. Windows versions from Windows95 to WindowsXP have a text "Start" labelled on the button. From Windows Vista onwards, this text from the Start button is discontinued.

Now for WindowsXP/2000/9x users, i'm showing a trick using the Windows API to change the Text named "Start" from the start button.
How to Do?

The Windows uses Messages to pass over informations among them. To set a text content on a Window, the Windows passes WM_SETTEXT message to the target Window. Each window are Uniquely identified using their Session Handles called HWND Handle. If we have a HWND handle of any window, we can easily send Messages and notifications to that Window using the SendMessage() API Call.

here, i need to set the text for Start Button. Since windows treats every control as a Window, the Button is also a Window. I can therefore, change the Window Text of Start button by sending WM_SETTEXT Message. But i dont have the handle of Satrt Button! There it is.. i have FindWindow() API which can easily retrive me a Handle of a Window with provided Class Name.

The classname of Taskbar, in which the Button is situated is "Shell_TrayWnd". See the Code Snippet. Its only 2 lines of Code to go. Pretty simple! :-)
Code Snippet


int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{


  // 0x130 is the ID of StartButton
  HWND StartButton = GetDlgItem( FindWindow( "Shell_TrayWnd", NULL ), 0x130 ); 
  //Setting Start text to "Hello"
SendMessage( StartButton, WM_SETTEXT, NULL, ( LPARAM )"Hello" ); 
  return 0;
}

Thats it... Include windows.h and compile.. Cool.. huh? Dont forget to Post Feedback :-)

1 comment:

  1. Nice code.. I knew the API FindWindow() but it can change start button text, it's really a great one to me..

    ReplyDelete