【发布时间】:2022-01-08 13:37:55
【问题描述】:
使用 C++ Builder 2009。尝试看看我是否可以改进 Windows 11 的 TPopupMenu(也可以是 TMainMenu)
我的 AdvancedDrawItem 函数永远不会被调用。我不确定为什么。我错过了什么傻事吗?
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// Init done here for the sake of small code sample
PopupMenu1->OwnerDraw = true ;
PopupMenu1->Items->OnAdvancedDrawItem = AdvancedDrawItem ;
PopupMenu1->Popup(Left + Button2->Left + 50, Top + Button2->Top + 50) ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AdvancedDrawItem(TObject *Sender, TCanvas *ACanvas, const TRect &ARect, TOwnerDrawState State)
{
TMenuItem *Item = (TMenuItem*)Sender ;
TTextFormat TF = TTextFormat() << tfVerticalCenter << tfSingleLine << tfEndEllipsis << tfLeft ;
ACanvas->TextRect((TRect&)ARect, (String&)Item->Caption, TF) ;
}
//---------------------------------------------------------------------------
PS。在另一个复杂得多的项目中,我确实让它在继承自TPopupMenu 的对象中触发。我现在对为什么我不能让这个简单的代码工作感到非常困惑。然而,我开始意识到这是一项半任务,因为DrawThemeBackground() 在这次活动中似乎没有做任何事情,我有点依赖它。此外,在绘画时要考虑到快捷方式、图标等,这将是一个 PITA。
【问题讨论】:
标签: c++builder vcl