News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

can we center window's caption of text ?

Started by mumin16, June 13, 2009, 07:36:37 AM

Previous topic - Next topic

mumin16

can we center window's caption of  text ?

MichaelW

I know of no window style or similar to do this automatically, but doing it by trial and error, padding the caption with spaces, should be fairly easy and should work for a dialog or an application window. Computing the number of spaces to add from the width of the window, caption, buttons, title bar icon, etc would be more difficult, particularly for a dialog.
eschew obfuscation

zooba

You want to look into handling all or part of the WM_NCPAINT message.

I have no examples of how to do this, so I can't help any more than that.

Cheers,

Zooba :U

jj2007

Quote from: zooba on June 13, 2009, 09:35:31 AM
You want to look into handling all or part of the WM_NCPAINT message.

The easiest way is to chose an empty caption, and then draw your own:

   CASE WM_NCPAINT
      invoke DefWindowProc, hWnd, uMsg, wParam, lParam
      invoke GetWindowDC, hWnd
      invoke TextOut, ...
      invoke ReleaseDC, hWnd, ...
      xor eax, eax
      ret

Vortex

Changing the default caption seems to be a complicated task. Here is an example. It's not perfect and the deactivation of the dialog box is an issue.

    .IF uMsg==WM_NCPAINT

        invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
        invoke  GetClientRect,hWnd,ADDR rc
        mov     rc.top,7
        invoke  GetWindowDC,hWnd
        mov     hDC,eax
        invoke  GetSysColor,COLOR_ACTIVECAPTION
        invoke  SetBkColor,hDC,eax
        invoke  GetSysColor,COLOR_CAPTIONTEXT
        invoke  SetTextColor,hDC,eax
        invoke  DrawText,hDC,ADDR capt,-1,ADDR rc,DT_CENTER
        invoke  ReleaseDC,hWnd,hDC

    .ELSEIF uMsg==WM_NCACTIVATE

        .IF !wParam

            invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
            invoke  GetClientRect,hWnd,ADDR rc
            mov     rc.top,7
            invoke  GetWindowDC,hWnd
            mov     hDC,eax
            invoke  GetSysColor,COLOR_INACTIVECAPTION
            invoke  SetBkColor,hDC,eax
            invoke  GetSysColor,COLOR_INACTIVECAPTIONTEXT
            invoke  SetTextColor,hDC,eax
            invoke  DrawText,hDC,ADDR capt,-1,ADDR rc,DT_CENTER
            invoke  ReleaseDC,hWnd,hDC
            mov     eax,1
            ret

        .ENDIF

[attachment deleted by admin]

ramguru

Vortex, your example shows empty caption barĀ  :'( . Tried to recompile - still no text (using Windows 7 x64)
Later > Tested on laptop with Win XP (x86) the example worked fine there.
Well still such solution should be avoided if you want your app be running on Win 7

Vortex

Hi ramguru,

My development system is Windows XP SP3. Here is a nice example by Ernst Murphy :

Custom Window Captions (and shapes too)

Vortex

Hi ramguru,

I am sorry if the example didn't run on Windows 7 but I guess I am not too late to find another solution as this new operating system is not yet released officialy. ( the RTM version.) Windows 7 is a new area ( at least for me ) and it will take time to study this new OS.

The example runs on Windows XP but the problem is that the caption gets activated if another window hits the client area of the dialog box. This nice tutorial could be studied to find a solution :

http://www.catch22.net/tuts/custom-titlebar

Thanks for testing the application on Windows XP and Windows 7

jj2007

Quote from: ramguru on June 14, 2009, 10:22:19 AM
Vortex, your example shows empty caption barĀ  :'( . Tried to recompile - still no text (using Windows 7 x64)
Later > Tested on laptop with Win XP (x86) the example worked fine there.
Well still such solution should be avoided if you want your app be running on Win 7

Lingo had this problem with my editor on Vista. You might try his solution.