Default
Google

How can I create a Start Menu-like application?

Applies To: C++Builder 1 or higher
Category: Knowledge Base

I would like to create an application bar (as the Start Menu), which will automatically push all the other windows aside.
 
 1.
  Start a new project using File | New Application.
 
 2.
  Set the BorderStyle of your form to bsNone.
 
 3.
  Open the header file and insert:
 
private:
    APPBARDATA data;
 
Also make sure to add #include <shellapi.h>.
 
 4.
  Double-click the OnShow event:
 
void __fastcall TForm1::FormShow(TObject *Sender)
{
    ClientWidth = 30;
    // Don't list this program in the Start Menu
    ShowWindow(Application->Handle, SW_HIDE);
 
    data.cbSize = sizeof(data);
    data.hWnd = Handle;
    data.uCallbackMessage = WM_USER;
    // Left application bar
    data.uEdge = ABE_LEFT;
    data.rc = Rect(0, 0, Width, Height);
    data.lParam = 0;
 
    // Create new application bar
    int res = SHAppBarMessage(ABM_NEW, &data);
    if(res)
    {
        SHAppBarMessage(ABM_QUERYPOS, &data);
        SHAppBarMessage(ABM_SETPOS, &data);
 
        Application->ProcessMessages();
        // Position in the middle
        SetWindowPos(Handle, HWND_BOTTOM, 0,
            (Screen->Height-Height)/2,
            Width, Height, SWP_NOREDRAW);
    }
    else
        // Error - close application
        Close();
}
 
 5.
  Edit the OnClose event:
 
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction
    &Action)
{
    // Delete application bar
    SHAppBarMessage(ABM_REMOVE, &data);
}

C++Builder Developer's Network
Copyright © Yoto Yotov



Acquiring image from ProHosting Banner Exchange