2012-01-12 15 views
0

(すなわち、二重ミドルマウスクリックなど...)ボーランドビルダ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

+0

武器 - ボタンとパネルの両方で試してみましたので、ボタンを押すと、パネルとボタンの両方のイベントが表示されます。ボタンがパネルを覆い隠していても?私はこれがVCLがうまく動作する方法だと思っていますが、これを切り替えることはできますか?そうすることの危険性は何ですか? – Yos

+0

あなたはパネル上でどのようなボタンイベントを見ていますか?実際のコードを表示してください。あなたのWindowProcがメッセージを正しく処理していないような音がします。 –

+0

これは、ボタンとパネルを使用し、VCLのイベントを使用した別の例を嘲笑して、OnClickと同じテストでボタンのクリックがボタン(子)とパネル(親)を示します。私のコードは次のとおりです: – Yos

答えて

2

TAdvToolButtonは、TGraphicControlの子孫です。 TGraphicalControlには独自のウィンドウがないため、ユーザーの入力を直接受け取ることはできません。ユーザーの入力はParentウィンドウに向けられているので、ParentWindowProcが最初にメッセージを表示します。入力が子のクライアント領域内で発生した場合TGraphicControlParentは入力をその子に転送します。そのため、両方のコンポーネントでユーザー入力メッセージが表示されています。 CConfigComponentButtonクラスをTButtonまたはTBitBtnのようなウィンドウ付きボタンを使用するように変更すると、ユーザーの入力が直接ボタンに向けられ、親のTPanelには送られないので、重複メッセージは表示されなくなります。

+0

あああああなたが言っていることを見ている。私は、ボタンやBitBtnでサポートされていない多くのプロパティに対してAdvボタンを使用する必要があります。この問題がなぜ起こっているのか知ることは良いことです!ご回答どうもありがとうございました。よろしく、ジョー – Yos

関連する問題