Click here to Skip to main content
Licence 
First Posted 25 Feb 2003
Views 61,615
Bookmarked 13 times

Subclassing menu without hooks

By | 17 Jun 2003 | Article
Subclassing menu without hooks

Subclassing menus without hooks

Hello,

I have read an article "A Revolutionary New Approach to Custom Drawn Menus - DanG". Yes, it seems to be a good article, but why should i use hooks? Can't i find a different way without hooks?

Window gets wm_INITMENUPOPUP, when menu window is already created. Lets try to find that window:

mh:=FindWindow(0,0,'#32768',nil);
If mh=0 then ; // process error

Wow, it seems - mh<>0.

Lets go further.

OldMenuProc:=SetWindowLong(mh,GWL_WNDPROC,Integer(@MenuProc));
If OldMenuProc=nil then ; // process error

There are no errors. Lets go to next step:

Function MenuProc(h:HWND;uMsg:UINT;wp:WPARAM;lp:LPARAM):LRESULT;stdcall;
Begin
  Result:=1;
  Case uMsg of
    482:Begin // just for fun
        SetWindowLong(h,GWL_EXSTYLE,GetWindowLong(h,GWL_EXSTYLE) or WS_EX_LAYERED);
        SetLayeredWindowAttributes(h,0,127,LWA_ALPHA);
    End;
  End;
  If Result=1 then
    Result:=CallWindowProc(OldMenuProc,h,uMsg,wp,lp);
End;

At last, we succeeded. We have mentioned, that this part of code makes menu transparent.

Notes:

1. MenuProc doesnt get all commmon messages. We will not get wm_CREATE and other messages because menu is created already.

2. Messages which came to MenuProc ( menu is being called and killed almost at the same time )

19:23:13 : MenuProc: 482 wParam - 1 lParam - 0
19:23:13 : MenuProc: 124 wParam - -20 lParam - 1243400 // appears only of WS_EX_* style changes
19:23:13 : MenuProc: 125 wParam - -20 lParam - 1243400 // appears only of WS_EX_* style changes
19:23:13 : MenuProc: 70 wParam - 0 lParam - 1243264
19:23:13 : MenuProc: 131 wParam - 1 lParam - 1243220
19:23:13 : MenuProc: 71 wParam - 0 lParam - 1243264
19:23:13 : MenuProc: 5 wParam - 0 lParam - 3342476
19:23:13 : MenuProc: 70 wParam - 0 lParam - 1243628
19:23:13 : MenuProc: 133 wParam - 1 lParam - 0
19:23:13 : MenuProc: 20 wParam - -1392438729 lParam - 0
19:23:13 : MenuProc: 71 wParam - 0 lParam - 1243628
19:23:13 : MenuProc: 15 wParam - 0 lParam - 0
19:23:13 : MenuProc: 485 wParam - -1 lParam - 0
...
19:23:14 : MenuProc: 485 wParam - -1 lParam - 0
19:23:14 : MenuProc: 70 wParam - 0 lParam - 1243628
19:23:14 : MenuProc: 71 wParam - 0 lParam - 1243628
19:23:14 : MenuProc: 2 wParam - 0 lParam - 0
19:23:14 : MenuProc: 130 wParam - 0 lParam - 0

3. Menu should be called with TrackPopUpMenuEx(...,TPM_NOANIMATION,...); // it is used for turning of all effects, which may block your applied changes.

There aren't reviewed all possible variants (WM_NCCALCSIZE, WM_NCPAINT, WM_PAINT and so on), but they all will work properly.

If you want we could discuss with you about viewing all source code to you. You can find me at: 195.22.174.130 6667 #irca Kancleris.

Have a nice day ;)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Kancleris

Web Developer

Lithuania Lithuania

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralOverride Menu class Pinmemberthucnh22:07 29 May '05  
GeneralAbout not using hooks PinmemberDanG12:30 26 Feb '03  
GeneralRe: About not using hooks PinmemberKancleris5:30 27 Feb '03  
GeneralRe: About not using hooks PinmemberKancleris5:30 27 Feb '03  
GeneralA few points PinmemberChopper0:50 26 Feb '03  
GeneralRe: A few points PinmemberErnest Laurentin4:01 26 Feb '03  
GeneralRe: A few points PinmemberKancleris4:18 26 Feb '03  
GeneralRe: A few points PinsussP. Ple Trawler17:14 26 Feb '03  
GeneralRe: A few points Pinmembersnakeware21:51 2 Mar '03  
GeneralRe: A few points PinsussAnonymous6:58 18 Jun '03  
GeneralRe: A few points PinmemberErnest Laurentin18:48 26 Feb '03  
GeneralRe: A few points PinmemberSimon Steele5:06 26 Feb '03  
GeneralRe: A few points PinmemberKancleris4:17 26 Feb '03  
GeneralRe: A few points PinmemberFuran9:53 26 Feb '03  
GeneralRe: A few points PinmemberRoman Nurik15:42 26 Feb '03  
GeneralRe: A few points PinsussAnonymous5:37 1 Dec '03  
GeneralRe: A few points PinmemberYoSilver4:27 28 Jan '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 18 Jun 2003
Article Copyright 2003 by Kancleris
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid