📄 menuid.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MenuID.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormCapturingMenuID *FormCapturingMenuID;
//---------------------------------------------------------------------------
__fastcall TFormCapturingMenuID::TFormCapturingMenuID(TComponent* Owner)
: TForm(Owner)
{
TotalMenuItems = 0; // TPoint
for( int i=0; i<ComponentCount; i++ )
if( dynamic_cast< TMenuItem * >( Components[ i ] ) )
{
MenuItemArray[ TotalMenuItems++ ] = dynamic_cast< TMenuItem * >( Components[ i ] )->Command;
}
}
//---------------------------------------------------------------------------
void TFormCapturingMenuID::WMCommand( TMessage &Message )
{
AnsiString Str1( IntToStr( Message.WParam ) );
AnsiString Str2;
for( int i=0; i<TotalMenuItems; i++ )
if( Message.WParam == MenuItemArray[ i ] )
{
for( int j=0; j<ComponentCount; j++ )
{
if( dynamic_cast< TMenuItem * >( Components[ j ] ) )
if( dynamic_cast< TMenuItem * >( Components[ j ] )->Command == MenuItemArray[ i ] )
Str2 = dynamic_cast< TMenuItem * >( Components[ j ] )->Caption;
}
Str1 = "You clicked ID: " + Str1 + "\rName: " + Str2;
MessageBox( Handle, Str1.c_str(), "Menu Item Info", MB_OK );
}
TForm::Dispatch( &Message );
}
//---------------------------------------------------------------------------
void __fastcall TFormCapturingMenuID::ButtonShowClick(TObject *Sender)
{
int Command;
AnsiString Name;
MemoInfo->Lines->Clear();
for( int i=0; i<ComponentCount; i++ )
{
if( dynamic_cast< TMenuItem * >( Components[ i ] ) )
{
Command = dynamic_cast< TMenuItem * >( Components[ i ] )->Command;
Name = dynamic_cast< TMenuItem * >( Components[ i ] )->Caption;
MemoInfo->Lines->Add( Name + " = " + IntToStr( Command ) );
}
}
}
//---------------------------------------------------------------------------
void HandleMessages( TMessage &Msg )
{
AnsiString Str;
switch( Msg.Msg )
{
case WM_PAINT:
Str = "WM_PAINT";
FormCapturingMenuID->StatusBarInfo->SimpleText = Str;
break;
case WM_MOUSEMOVE:
Str = "WM_MOUSEMOVE ";
Str += IntToStr( Msg.LParamLo ) + " " + IntToStr( Msg.LParamHi );
FormCapturingMenuID->StatusBarInfo->SimpleText = Str;
break;
case WM_LBUTTONDOWN:
Str = "WM_LBUTTONDOWN";
Str += IntToStr( Msg.LParamLo ) + " " + IntToStr( Msg.LParamHi );
FormCapturingMenuID->StatusBarInfo->SimpleText = Str;
break;
case WM_RBUTTONDOWN:
Str = "WM_RBUTTONDOWN";
Str += IntToStr( Msg.LParamLo ) + " " + IntToStr( Msg.LParamHi );
FormCapturingMenuID->StatusBarInfo->SimpleText = Str;
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TFormCapturingMenuID::WndProc( Messages::TMessage &Message )
{
if( Message.Msg == WM_CLOSE )
ShowMessages = false;
if( ShowMessages )
HandleMessages( Message );
TForm::WndProc( Message );
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -