Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to preserve the default popup menu for a component Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
09-Oct-02
Category
VCL-Menu
Language
Delphi 2.x
Views
41
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Is there a way to keep the default popup menus for e.g. TMemo, TEdit if there is an 
explicit popup menu for the parent control?

Answer:

You have to trap the WM_CONTEXTMENU message on the level of the parent. Assuming 
the parent is the form you would add a message handler to the form:

1   { ... }
2   private
3   
4   procedure WMContextMenu(var message: TWMContextMenu); message WM_CONTEXTMENU;
5   { ... }


and implement it like this:
6   
7   procedure TForm1.WMContextMenu(var message: TWMContextMenu);
8   var
9     wnd: HWND;
10    ctrl: TWinControl;
11  begin
12    if message.XPos > 0 then
13    begin
14      wnd := WindowFromPoint(Mouse.CursorPos);
15      if wnd <> handle then
16      begin
17        ctrl := FindControl(wnd);
18        if Assigned(ctrl) and (ctrl is TCustomEdit) then
19          Exit;
20      end;
21    end
22    else if ActiveControl is TCustomEdit then
23      Exit;
24    inherited;
25  end;


Doing the same if the parent with the menu is a panel or tabsheet or such is a bit more difficult, you have to subclass it via WindowProc, or make a descendent class to be able to trap the message.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC