Click here to Skip to main content
Click here to Skip to main content

Subclassing menu without hooks

, 17 Jun 2003
Rate this:
Please Sign up or sign in to vote.
Subclassing menu without hooks
<!-- Add the rest of your HTML here -->

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 Wink | ;)

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

Share

About the Author

Kancleris
Web Developer
Lithuania Lithuania
No Biography provided

Comments and Discussions

 
GeneralOverride Menu class Pinmemberthucnh29-May-05 22:07 
GeneralAbout not using hooks PinmemberDanG26-Feb-03 12:30 
GeneralRe: About not using hooks PinmemberKancleris27-Feb-03 5:30 
GeneralRe: About not using hooks PinmemberKancleris27-Feb-03 5:30 
GeneralA few points PinmemberChopper26-Feb-03 0:50 
GeneralRe: A few points PinmemberErnest Laurentin26-Feb-03 4:01 
GeneralRe: A few points PinmemberKancleris26-Feb-03 4:18 
GeneralRe: A few points PinsussP. Ple Trawler26-Feb-03 17:14 
GeneralRe: A few points Pinmembersnakeware2-Mar-03 21:51 
GeneralRe: A few points PinsussAnonymous18-Jun-03 6:58 
GeneralRe: A few points PinmemberErnest Laurentin26-Feb-03 18:48 
GeneralRe: A few points PinmemberSimon Steele26-Feb-03 5:06 
GeneralRe: A few points PinmemberKancleris26-Feb-03 4:17 
GeneralRe: A few points PinmemberFuran26-Feb-03 9:53 
GeneralRe: A few points PinmemberRoman Nurik26-Feb-03 15:42 
GeneralRe: A few points PinsussAnonymous1-Dec-03 5:37 
GeneralRe: A few points PinmemberYoSilver28-Jan-04 4:27 

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.

| Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 18 Jun 2003
Article Copyright 2003 by Kancleris
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid