Solved

Window taking over my WM_NCPAINT message!

Posted on 2002-07-19
4
828 Views
Last Modified: 2011-08-18
Dear programming buddies!

      I have written a class that customizes the caption titlebar of my main application window. It stretchblt's  it of a series of tileable bitmaps. As a result, the close, minimize and restore buttons are also drawn of a small bitmap.

      The effect desired is a titlebar that appears more alive, one that responds to mouse movement where caption buttons light up when moving the cursor over them, as well as WM_LBUTTONDOWN bitmaps etc. That sort of thing.

I have handled WM_NCPAINT, and WM_NCACTIVATE in order to achieve this. But I have come accross a HUGE bug which I can't find to solve.

IN WINDOWS '98 THE FOLLOWING HAPPENS:

      After I have received a WM_CONTEXTMENU message, invoked by either mouse or keyboard events, the three buttons as well as the background bitmap around the region of the caption buttons disappear after clicking inside the caption titlebar.

       I have used Spy++ to take a look at my messages, and quite strangely Windows performs default processing by drawing your ordinary button type caption buttons as well as a part of the caption bar around the region of the caption buttons. It appears that Windows simply erases my bitmap with its own default button drawing mechanism.

      The reason why this puzzles me is the fact that I have not received a WM_NCPAINT message at all, meaning that there is no invalid region on the non-client area. I even tried calling my OnNcPaint() function in between the messages sent on button clicks and mouse movements and after receiving WM_CONTEXTMENU, but only to cause unwanted flickering.

      Windows can't be doing DefWindowProc() for drawing default buttons, as this would only happen after I have received WM_NCPAINT, and I am not calling DefWindowProc() in my WM_NCPAINT message handler. My OnNcPaint() message handler is fully responsible for drawing the caption titlebar as well as the window frame.

      When I move the window with the caption buttons out of the desktop boundaries, and move it back to a viewable spot, my bitmap buttons reappear, only to disappear mysteriously after you click on the titlebar, or quite so often after a mousemove/hittest message.

IN WINDOWS 2000, SOMETHING SIMILAR HAPPENS:

      The whole insident as mentioned above happens with only one difference, Windows only takes over after I have minimized the application by clicking on the taskbar button, WM_CONTEXTMENU has no effect. When I click the minimize button beforehand, it does not affect the application in this way either, only clicking the taskbar causes Windows to take over. After "taskbar minimizing" Windows starts redrawing my caption buttons and the background region around them, thus erasing my blt'ed bitmap. Drawing is done, and WM_NCPAINT is not even in sight in Spy++ (and I am filtering out ALL messages, if you were wondering) !!!

      Please note: This all happens in Win32 API code, I'm not using MFC at all.

      Please, please, please take a look at this and help me find a solution. If you would like to have the source code, email me at josamoto@hotmail.com.

MY PRESUMPTION IS AS FOLLOWS:

      I thought that somewhere along the line, I lost a DC or forgot to restore to the previously selected HGDIOBJ. This was not the matter however, I made dead sure that all my device contexts are restored and my GDI objects are deleted from memory after I have used them and unselected them from their DC's. I think I'm just not catching the right message somewhere along the line, or Windows sets a flag which I know not where to find to reset.

! ! ! PLEEZ HELP ME, I'M HOPELESSLY NOT SURE WHAT TO DO ANYMORE, AND I AM NOT GIVING UP ! ! !
0
Comment
Question by:josamoto
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 335 total points
ID: 7212141
I believe this issue (or at least a set of similar problems relating to custom NC painting) is covered in this article:

   http://search.microsoft.com/gomsuri.asp?n=1&c=rp_Results&siteid=us/dev&target=http://www.microsoft.com/MSJ/0197/c++/C++0197.htm

Don't be put off by the mention of MFC.  The painting and flicker-elimination issues are the same with MFC or straight Win32.

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7212143
I just tried that link and it seems to be broken.  You can find the Paul Dilascia article in MSDN by searching for this phrase:
    "The instant your poor title bar"
(including the quote marks).
-- Dan
0
 
LVL 11

Expert Comment

by:griessh
ID: 7378261
Dear josamoto

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "DanROllins"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7419935
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now