Customize XP style menu

Source: Internet
Author: User

This is the code I wrote earlier. I used to customize the XP style menu. After the hard disk is broken, I thought it was gone. The last software I wrote was to customize the style, I finally found an application example on my cute antique host ^_^. Put it on the blog to share and use it as a backup.
Point onmeasureitem in the main menu to measuremainitem, onadvanceddrawitem to drawmainitem, onmeasureitem in the sub menu to measuresubitem, onadvanceddrawitem to drawsubitem, adjust the color or use the default color to achieve the effect.

// Adjust the size of the main menu item
Procedure measuremainitem (Sender: tobject; acanvas: TCanvas; var width, height: integer );
Begin
Width: = width + 6;
Height: = height + 2;
End;

// Adjust the sub-menu item size
Procedure measuresubitem (Sender: tobject; acanvas: TCanvas; var width, height: integer );
Begin
Width: = width + 20;
Height: = height + 2;
End;

// Draw the main menu content
Procedure drawmainitem (Sender: tobject; acanvas: TCanvas; arect: trect; State: townerdrawstate );
Const
Mainmenubackcolor: tcolor = $ deedef;
Mainmenubordercolor: tcolor = $ deedef;
Mainmenuselectedbackcolor: tcolor = $ dfa988;
Mainmenuselectedbordercolor: tcolor = $ c08000;
Mainmenuhotlightbackcolor: tcolor = $ deedef;
Mainmenuhotlightbordercolor: tcolor = $800080;
Mainmenugrayedbackcolor: tcolor = $ deedef;
VaR
Brushcolor, pencolor: tcolor;
Textrect: trect;
Begin
If odgrayed in State then
Begin
Brushcolor: = mainmenugrayedbackcolor;
Pencolor: = mainmenugrayedbackcolor;
End
Else
If odhotlight in State then
Begin // move the cursor over
Brushcolor: = mainmenuhotlightbackcolor;
Pencolor: = mainmenuhotlightbordercolor;
End
Else
If odselected in State then
Begin
Brushcolor: = mainmenuselectedbackcolor;
Pencolor: = mainmenuselectedbordercolor;
End
Else
Begin
Brushcolor: = mainmenubackcolor;
Pencolor: = mainmenubackcolor;
If tmenuitem (sender). Caption = 'help (& H) 'Then arect. Right: = arect. Right + 1600;
End;
Acanvas. Brush. Color: = brushcolor;
Acanvas. Pen. Color: = pencolor;
// Acanvas. fillrect (arect );
Acanvas. rectangle (arect );
Acanvas. Brush. Style: = bsclear;
// Draw text
If odgrayed in State then
Acanvas. Font. Color: = clbtnshadow
Else
Acanvas. Font. Color: = clblack;
Setrect (textrect, arect. Left + 10, arect. Top + 3, arect. Right, arect. Bottom );
Drawtext (acanvas. Handle, pchar (tmenuitem (sender). Caption), length (tmenuitem (sender). Caption ),
Textrect, dt_left );
End;

// Draw sub-menu content
Procedure drawsubitem (Sender: tobject; acanvas: TCanvas; arect: trect; State: townerdrawstate );
Const
Submenubackcolor: tcolor = $ f7f8f9;
Submenubordercolor: tcolor = $ deedef;
Submenuselectedbackcolor: tcolor = $ eed2c1;
Submenuselectedbordercolor: tcolor = $ c08000;
Submenulinecolor: tcolor = $ c8d0d4;
// Submenuhotlightbordercolor: tcolor = $ c08000;
Submenugrayedbackcolor: tcolor = $ f7f8f9; // $ deedef;
VaR
Brushcolor, pencolor: tcolor;
Textrect: trect;
STR: string;
Imagelist: tcustomimagelist;
Begin
If (odgrayed in state) and not (tmenuitem (sender). isline) then
Begin
Brushcolor: = submenugrayedbackcolor;
{If odselected in State then
Pencolor: = submenuselectedbordercolor
Else}
Pencolor: = submenugrayedbackcolor;
End
Else
If odselected in State then
Begin
Brushcolor: = submenuselectedbackcolor;
Pencolor: = submenuselectedbordercolor;
End
Else
Begin
Brushcolor: = submenubackcolor;
Pencolor: = submenubackcolor;
End;
Acanvas. Brush. Color: = brushcolor;
Acanvas. Pen. Color: = pencolor;
Acanvas. rectangle (arect );
If not (odselected in State) or (odgrayed in State) then
Begin
Acanvas. Brush. Color: = submenubordercolor;
Acanvas. fillrect (rect (arect. Left, arect. Top, arect. Left + 20, arect. Bottom ));
End;
// Draw text and shortcuts
If tmenuitem (sender). isline then
Begin
Acanvas. Brush. Color: = submenulinecolor;
Acanvas. Pen. Color: = submenulinecolor;
Acanvas. fillrect (rect (arect. Left + 23, arect. Top + (arect. Bottom-ARect.Top) Div 2-1,
Arect. Right-2, arect. Top + (arect. Bottom-ARect.Top) Div 2 ));
End
Else
Begin
Acanvas. Brush. Style: = bsclear;
If odgrayed in State then
Acanvas. Font. Color: = clbtnshadow
Else
Acanvas. Font. Color: = clblack;
STR: = tmenuitem (sender). Caption;
Setrect (textrect, arect. Left + 24, arect. Top + 3, arect. Right, arect. Bottom );
Drawtext (acanvas. Handle, pchar (STR), length (STR), textrect, dt_left );
STR: = shortcuttotext (tmenuitem (sender). Shortcut );
Setrect (textrect, arect. Left + 24, arect. Top + 3, arect. Right-10, arect. Bottom );
Drawtext (acanvas. Handle, pchar (STR), length (STR), textrect, dt_right );
//
If tmenuitem (sender). Checked then
Begin
Acanvas. Font. charset: = default_charset;
Acanvas. Font. Name: = 'webstring ';
If tmenuitem (sender). radioitem then
Acanvas. textout (arect. Left + 4, arect. Top, '= ')
Else
Begin
Acanvas. Font. Height: =-16;
Acanvas. textout (arect. Left + 2, arect. Top, 'A ');
End;
End;
End;
// Draw an image
Imagelist: = tmenuitem (sender). getimagelist;
If imagelist <> nil then
If (odselected in state) and not (odgrayed in State) then
Imagelist. Draw (acanvas, arect. Left + 2, arect. Top + 2, tmenuitem (sender). imageindex)
Else
Imagelist. Draw (acanvas, arect. Left + 3, arect. Top + 3,
Tmenuitem (sender). imageindex, tmenuitem (sender). enabled );
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.