(すなわち、二重ミドルマウスクリックなど...)ボーランドビルダ2007子VCLコントロールとのWindowProc方法
トラブルがあります私が子コンポーネントWindowProcをオーバーライドすると、親はまだイベントを取得します。
私の場合、私はそれに親のボタンを持つパネルを持っています。ボタンはパネルの一部を隠しますが、ボタンをクリックすると、親(パネル)もイベントを取得します(ボタンがイベントを取得することはテストされていませんが、最初に解決策があるかどうかを確認したい)。
イベントを受信する親をプログラムで停止する方法や、そのイベントが親ではなく親であるかどうかを判断する方法はありますか。
問題は、ユーザーがボタンを押すと、パネルイベントとボタンイベントがトリガーされるということです。
ご褒美をいただければ幸いです。
ジョー
コード例:パネルとボタンがm_kOldComponentWndMethodとComponentWndProc方法が住んでいる場所であるConfigComponentクラスから派生していること 注意。
パネルをオーバーライド
//---------------------------------------------------------------------------
CConfigComponentPanel::CConfigComponentPanel(TObject* pkParent,
const CConfigComponentDimensions& rkConfigComponentDimensions,
const CConfigComponentPos& rkConfigComponentPos,
const CConfigSelect::SelectCollection& rkSelectCollection,
TColor kBackgroundColour,
TColor kForegroundColour,
const std::string& rstrDisplayText,
const CConfigFontRef& rkConfigFontRef,
const CConfigComponent::ConfigComponentCollection& rkConfigComponentCollection)
: CConfigComponent(rkConfigComponentDimensions, rkConfigComponentPos, kBackgroundColour, kForegroundColour),
m_pkPanel(new TPanel((TComponent*)NULL)),
m_kConfigComponentCollection(),
m_kSelectCollection(),
m_kConfigFontRef(rkConfigFontRef),
m_strDisplayText(rstrDisplayText)
{
// Set the parent.
m_pkPanel->Parent = dynamic_cast<TWinControl*>(pkParent);
if (rkSelectCollection.size() > 0)
{
// Store the old window proc method before overriding.
m_kOldComponentWndMethod = m_pkPanel->WindowProc;
m_pkPanel->WindowProc = ComponentWndProc;
}
// Add selects to collection
AddSelectsToCollection(rkSelectCollection);
// Add components to collection
AddConfigComponentsToCollection(rkConfigComponentCollection);
}
//---------------------------------------------------------------------------
ボタンをオーバーライド
//---------------------------------------------------------------------------
CConfigComponentButton::CConfigComponentButton(TObject* pkParent,
const CConfigSelect::SelectCollection& rkSelectCollection,
const CConfigComponentDimensions& rkConfigComponentDimensions,
const CConfigComponentPos& rkConfigComponentPos,
TColor kBackgroundColour,
TColor kForegroundColour,
const CConfigButtonBGProperties& rkConfigButtonBGProperties):
CConfigComponent(rkConfigComponentDimensions, rkConfigComponentPos, kBackgroundColour, kForegroundColour),
m_kConfigButtonBGProperties(rkConfigButtonBGProperties),
m_pkButton(new TAdvToolButton(NULL)),
m_kSelectCollection(rkSelectCollection)
{
m_pkButton->Parent = dynamic_cast<TWinControl*>(pkParent);
// Store the old window proc method before overriding.
m_kOldComponentWndMethod = m_pkButton->WindowProc;
m_pkButton->WindowProc = ComponentWndProc;
}
//---------------------------------------------------------------------------
[コンポーネントWND PROC方法(ボタンの二回に一度パネル用、一度ここに来て)
//---------------------------------------------------------------------------
void __fastcall CConfigComponent::ComponentWndProc(TMessage& rkMessage)const
{
if (rkMessage.Msg == WM_MBUTTONDBLCLK)
{
(void)Application->MessageBox("CConfigComponent::ComponentWndProc", "");
}
if (rkMessage.Msg == WM_LBUTTONDBLCLK)
{
(void)Application->MessageBox("ComponentWndProc::Left Button", "");
}
if (m_kOldComponentWndMethod)
{
m_kOldComponentWndMethod(rkMessage);
}
}
//---------------------------------------------------------------------------
感謝、 Joe
武器 - ボタンとパネルの両方で試してみましたので、ボタンを押すと、パネルとボタンの両方のイベントが表示されます。ボタンがパネルを覆い隠していても?私はこれがVCLがうまく動作する方法だと思っていますが、これを切り替えることはできますか?そうすることの危険性は何ですか? – Yos
あなたはパネル上でどのようなボタンイベントを見ていますか?実際のコードを表示してください。あなたのWindowProcがメッセージを正しく処理していないような音がします。 –
これは、ボタンとパネルを使用し、VCLのイベントを使用した別の例を嘲笑して、OnClickと同じテストでボタンのクリックがボタン(子)とパネル(親)を示します。私のコードは次のとおりです: – Yos