News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Drawing in non-client area of window (win32)

Started by Ben, June 08, 2012, 03:27:18 PM

Previous topic - Next topic

Ben

Hi there  ;)

I don't suppose anyone knows how to do this?

I've tried to process the WM_NCPAINT message, but the friggin thing won't let me paint in the title bar.

Googled everywhere for solutions with no luck yet.

BTW - Please go easy on me. I can barely program in C let alone MASM  :(

hutch--

Hi Ben,

In the masm32 example code there is an example called skins3 that takes one approach to drawing its own non-client area (titlebar and borders) but its not simple code. Perhaps one of the members has a simpler technique once they know what you are trying to do.

jj2007

Win XP or Win7? Aero activated or not??

Normally you let the system do its WM_NCPAINT stuff, then grab the window DC and do your painting afterwards. There are severe problems with Aero, see http://delphihaven.wordpress.com/2010/04/19/setting-up-a-custom-titlebar/
If you want to see a working example, RichMasm (\Masm32\RichMasm\RichMasm.exe after unzipping the MB attachment) has menus in the title bar, and it works even on Win7 with Aero. But it's definitely not trivial.

CASE WM_NCPAINT
invoke DefWindowProc, hWin, uMsg, wParam, lParam
call PaintOnTitleBar
m2m eax, 1
ret

Ben

Thanks Hutch and jj2007,

Na, I'm not using Aero. I'm just trying to create a custom title bar like they do in applications like Chrome and Itunes.

Anyway, I tried sticking a region from GetWindowRect into GetDCEx and it actually worked! I checked WPARAM in the debugger which said it was equal to 1 when it should have held a region. So maybe there is a bug in windows for WM_NCPAINT? In any case, It seems to work now.

Thanks again.

dedndave

yah - but you want your program to work for users that do use aero   :P

Ben

Thanks Dave,

I hadn't thought of that. Can I disable Aero? Like is there an option in win32 to disable it? I want the gui of my app to be done in direct2d, including the tile bar. The app should look the same regardless of whether the user is using aero or not. I'm using Win Server 2008, so I don't think I can test it in aero.

I'll have to have a look at that RichMasm example jj2007 posted since it works in aero.

Thank you.

Mr Hippy

I would create all window instances without any borders. Create a template that be drawn for the parent window and all child windows. Then you can go from there in drawing your elements with Direct2D.

Ben

Cheers Mr Hipppy,

I still need it to have borders so it can be resized though (I don't want to have to implement this myself!). When I paint them myself in WM_NCPAINT I still have to paint the non-client area where the borders were, which is a pain because I want to use a linear gradient painting scheme that will cover the entire window.

What I really need is a DC that can access the entire window, including the borders, but with border functionality still intact.

jj2007

Modify \masm32\examples\exampl01\generic\generic.asm:
.elseif uMsg == WM_PAINT
invoke DefWindowProc, hWin, uMsg, wParam, lParam
invoke GetWindowDC, hWin
push eax

.data
include \masm32\include\gdi32.inc
includelib \masm32\lib\gdi32.lib
txHello db "Hello"
.code

invoke TextOut, eax, 200, 5, offset txHello, 5 ; needs gdi32

pop eax
invoke ReleaseDC, hWin, eax


This works for non-Aero Windows only.

Greenhorn

If you want to draw in the title bar with Aero enabled you should take a look at this:
Custom Window Frame Using DWM
http://msdn.microsoft.com/en-us/library/bb688195%28v=VS.85%29.aspx

Firefox and Thunderbird are using this technique, for example.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

dedndave

i developed a method to get a handle under win 7 Aero

http://www.movsd.com/board/index.php?topic=16931.msg154917#msg154917

i don't think it was ever tested under Aero, but it may help
here is the attachment...

Ben

Thanks for the replies everyone!

I'll definitely check all these suggestions out, but I have to put everything down for exams that are comming up next week <groan>  :( :( :(.

Thanks again everyone.