Sign in to follow this  

draw custom menu or dropdown list?

This topic is 4196 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Win32 API: What is the best way to draw something outside the client rect of a window, i.e. to draw menus and dropdown-lists? It tried GetDC(NULL), but the problem is to restore the stuff that was under that area. bye, Chris

Share this post


Link to post
Share on other sites
Top-level windows (i.e. the actual things with borders and captions that you can move around the screen) are not able to draw outside of their client areas, because the OS forces them to have the WS_CLIPSIBLINGS style. If you need to draw outside the client area of a top-level window, you need to actually create a secondary top-level window, which is how menus, drop-downs, tooltips, etc. usually are implemented.

Share this post


Link to post
Share on other sites
If you mean you want to draw something that will draw over the extents of your entire window, then the best (maybe only) way would be to create another window, and draw onto that. That's what most windows controls and popup menus do, from what I can see.

Share this post


Link to post
Share on other sites
Yeah, I already tried it with another top-level window, but the problem is that the parent window (i.e. the window where the custom drop-down control is in) looses the focus and the title bar gets gray. Do you know how to avoid that?

Share this post


Link to post
Share on other sites
Hi,
I tried what you described as "owned window". No luck. The main window still looses the focus and gets gray. I really want to know how that menu and dropdown stuff is implemented!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
one fairly easy way to do it is to have your popup window subclass or hook its parent window and then respond to the WM_NCACTIVATE msg with FALSE, which will leave the parent's window's titlebar, etc., in the active state.

but there's any even easier way to do this as I've done it before for my own popup menu class. i just have to find the code as it was written years ago and I can't remember exactly what was done.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
by parent, i really meant owned, of course :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i found the following code which might do the trick:


// handle if in AOT mode - make sure we're not activated and that we stay on top
case WM_WINDOWPOSCHANGING:
if( rtProps.alwaysOnTop )
{
((LPWINDOWPOS)lParam)->flags |= SWP_NOACTIVATE;
((LPWINDOWPOS)lParam)->flags &= ~(SWP_NOOWNERZORDER | SWP_NOZORDER);
((LPWINDOWPOS)lParam)->hwndInsertAfter = HWND_TOPMOST;
}
return 0; // no default processing so no WM_GETMINMAXINFO msg is sent


i'm not sure if such an app gets keyboard focus though as this code came from an alt+tab replacement and it's using a low-level keyboard hook

Share this post


Link to post
Share on other sites

This topic is 4196 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this