I want to customize the titlebar color and buttons (minimize, maximize and close). I found some samples on the web:
- customcaptions (somewhere on codeproject or codeguru)
- captionbutton (somewhere on codeproject or codeguru)
- shadecap (http://www.microsoft.com/msj/0697/c0697.aspx)
But they all suffer the same thing when using windows XP theme: the buttons are overpainted, but their clickregion is not right. When you click (mousepressed), you clearly see the old (classic) buttons.
Are there any nice (working) samples of code of this?
Your app's main window will recv WM_NCPAINT when it needs to draw the caption/buttons/frame (the non-client area). Just paint as you wish. Pretty simple.
sulu
Yay 100+ rep! Thnx all for Rating my Posts and deeming them worthy
I think SetWindowText would have better result than your code snippet.
Am I missing something?
Your code paints text with dc background (most likely white) on the top of original window text using system font, not default font.
I fail to see setting title bar color and button drawing as requirement state.
Anyway, is this code for Win32 application?
There are only 10 types of people in the world: Those who understand binary and those who do not.
I was just demonstrating (Microsoft-style, i.e. "hello world", bleh ) that you can use the WM_NCPAINT to draw your own title bar. I could have just as easily drawn a big rectangle over the titlebar... Just wanted to show that you can either draw the entire non-client area or, the better option, call DefWindowProc (as I demonstrated) and then redraw the border or the buttons or whatever.
[edit]In MFC... You can use the ClassWizard to catch WM_NCPAINT, or use your CWinApp's PreTranslateMessage. I used API because it demonstrates the actual message interpretation.[/edit]
sulu
Last edited by mistersulu; July 8th, 2005 at 05:27 PM.
Yay 100+ rep! Thnx all for Rating my Posts and deeming them worthy
The code you gave is pretty straightforward but didn't answer my question. I did already try to paint in the nonclient area. The painting itself isn't too hard, I think. You can see it e.g. in the code of shadecap (http://www.microsoft.com/msj/0697/c0697.aspx). Also see attachment and click on the buttons, you'll see what I mean.
The problem is I don't know how to solve these bad effects.
With some bugfixes, this code works great.
At least already in classic theme, but when using a winxp theme, problems arise when resizing. The problem are the borders of a window. The coder used code like
Code:
void CBeeMainFrame::OnNcPaint()
{
CMDIFrameWnd::OnNcPaint();//first normal painting
... //here he starts overpainting the caption, and not the borders
Off course this causes flickering, and also the effect with the borders is not so good. I added a screenshot of this problem.
How to solve this 'bug' in this code? Or better, how to draw the borders in OnNcPaint() so I can paint it in my own color?
Since the flickering is caused by essentially "painting" the non-client area twice, the only option is to control all of the painting yourself (although the nonclient area should not have to be refreshed very often... are you Invalidating the entire window rect manually?) It would be nice if you could provide an HDC to the NCPaint function, so that you could backbuffer it's operations, do your stuff, THEN blit to the screen, but you can only do that with a bit of hacking.
Although, I the MFC code for OnNCPaint is easy enough to find (In the 'SRC' directory for my VS6 Install). You could just copy that code, paste it into yours, and draw the border yourself in there... and never have to call the default (i.e. remove the line "CMDIFrameWnd::OnNcPaint();"). From what I can see, you'll just need to change 'COLOR_WINDOWFRAME' to your own color.
sulu
Yay 100+ rep! Thnx all for Rating my Posts and deeming them worthy
Actually now, it looks quite good.
One problem is that when I click the min/max/close buttons (put my left mouse button down) the 'old' buttons are painted :-( Like in the screenshot.
I tried to find where this painting happens, but I don't understand.
I have a similar problem when maximising a window: while it's maximising you can see the original (color of the) titlebar.
How to fix these two issues?
I have a similar problem when maximising a window: while it's maximising you can see the original (color of the) titlebar.
How to fix these two issues?
I still have this question.
Or perhaps it is possible to make this effect disappear using some windowstyle? (I'm talking about the color of the titlebar while it is minimizing/maximizing)
----
to be complete: about the previous post: the problem with the captionbuttons has to be solved with WS_SYSMENU
I have the exactly the same problem of yours.
Can you let me know how you solved the problem?
I have also two more problems.
One is that I can't make the corners of titlebar transparent to look round.
And the other is that I also have to add bitmap background in toolbar like the titlebar.
If you solved the problem please provide any samples or snippets.
Thanks
I don't have a solution for the color while resizing.
I also have no idea how to make the bar transparent at some places, I'm sorry.
About this: "And the other is that I also have to add bitmap background in toolbar like the titlebar." -> Do you mean you want to have a toolbar with a background? If so, you can find articles of that on codeguru.
About the old buttons showing up while clicking: You need to paint everything yourself, so do not call the baseclass' ::OnNcPaint(); U also have to do that without the WS_SYSMENU style
Code:
//something like: (you can do it in precreatewindow or oninitdialog)
long gwl = GetWindowLong(this->m_hWnd,GWL_STYLE);
gwl = gwl & ~WS_SYSMENU;
SetWindowLong(this->m_hWnd,GWL_STYLE,gwl);
//or just do this before painting:
ModifyStyle(WS_SYSMENU,0);
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.