Jump to content

Recommended Posts

Posted

Hi to all,

Is it possible to set titles at the center of created GUI?

Or better, if it will be some function that use hWnd to set titles in center of window, it will be great.

I have no idea how even to start such a function... maby a DllCall's? :whistle:

Thanks.

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  MsCreatoR said:

Hi to all,

Is it possible to set titles at the center of created GUI?

Or better, if it will be some function that use hWnd to set titles in center of window, it will be great.

I have no idea how even to start such a function... maby a DllCall's? :whistle:

Thanks.

Are you talking about centering the window caption text or just writing centered text in the window itself?
Auto3Lib: A library of over 1200 functions for AutoIt
Posted

  Hello Me You said:

Any better solution?

Grab Auto3Lib for the API calls:

CODE
#include <A3LWinAPI.au3>
#include <GUIConstants.au3>

Global Const $COLOR_ACTIVECAPTION       = 2
Global Const $COLOR_INACTIVECAPTION     = 3

Global Const $DT_TOP                    = 0x00000000
Global Const $DT_LEFT                   = 0x00000000
Global Const $DT_CENTER                 = 0x00000001
Global Const $DT_RIGHT                  = 0x00000002
Global Const $DT_VCENTER                = 0x00000004
Global Const $DT_BOTTOM                 = 0x00000008
Global Const $DT_WORDBREAK              = 0x00000010
Global Const $DT_SINGLELINE             = 0x00000020
Global Const $DT_EXPANDTABS             = 0x00000040
Global Const $DT_TABSTOP                = 0x00000080
Global Const $DT_NOCLIP                 = 0x00000100
Global Const $DT_EXTERNALLEADING        = 0x00000200
Global Const $DT_CALCRECT               = 0x00000400
Global Const $DT_NOPREFIX               = 0x00000800
Global Const $DT_INTERNAL               = 0x00001000

$hGUI = GUICreate("", 400, 300)
GUISetState()

GUIRegisterMsg($WM_NCACTIVATE, "WM_NCACTIVATE")
GUIRegisterMsg($WM_NCPAINT   , "WM_NCPAINT"   )
_API_RedrawWindow($hGUI, 0, 0, BitOR($RDW_FRAME, $RDW_INVALIDATE))

do
until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NCACTIVATE($hWnd, $iMsg, $iwParam, $ilParam)
  if $iwParam = 0 then
    DrawCaption($hWnd, $iMsg, $iwParam, $ilParam, _API_GetSysColor($COLOR_INACTIVECAPTION))
    Return True
  else
    DrawCaption($hWnd, $iMsg, $iwParam, $ilParam, _API_GetSysColor($COLOR_ACTIVECAPTION  ))
    Return True
  endif
EndFunc

Func WM_NCPAINT($hWnd, $iMsg, $iwParam, $ilParam)
  if $iwParam = 1 then
    DrawCaption($hWnd, $iMsg, $iwParam, $ilParam, _API_GetSysColor($COLOR_ACTIVECAPTION))
  else
    DrawCaption($hWnd, $iMsg, $iwParam, $ilParam, _API_GetSysColor($COLOR_INACTIVECAPTION))
  endif
  Return 0
EndFunc

Func _API_DefWindowProc($hWnd, $iMsg, $iwParam, $ilParam)
  Local $aResult

  $aResult = DllCall("User32.dll", "int", "DefWindowProc", "hwnd", $hWnd, "int", $iMsg, "int", $iwParam, "int", $ilParam)
  Return $aResult[0]
EndFunc

Func _API_SetBkColor($hDC, $iColor)
  Local $aResult

  $aResult = DllCall("GDI32.dll", "int", "SetBkColor", "hwnd", $hDC, "int", $iColor)
  Return $aResult[0]
EndFunc

Func _API_SetTextColor($hDC, $iColor)
  Local $aResult

  $aResult = DllCall("GDI32.dll", "int", "SetTextColor", "hwnd", $hDC, "int", $iColor)
  Return $aResult[0]
EndFunc

Func DrawCaption($hWnd, $iMsg, $iwParam, $ilParam, $iColor)
  _API_DefWindowProc($hWnd, $iMsg, $iwParam, $ilParam)
  $hDC = _API_GetWindowDC($hWnd)
  $tRect2 = _API_GetWindowRect($hWnd)
  $iX = _API_GetSystemMetrics($SM_CXSIZE ) + _API_GetSystemMetrics($SM_CXBORDER) + _
        _API_GetSystemMetrics($SM_CXFRAME)
  $iY = _API_GetSystemMetrics($SM_CYFRAME)
  $tRect1 = _tagRECT()
  _tagSetData($tRect1, "Left"  , $iX)
  _tagSetData($tRect1, "Top"   , 2 * $iY)
  _tagSetData($tRect1, "Right" , _tagGetData($tRect2, "Right") - _tagGetData($tRect2, "Left" ) - _
                                (2 * $iX) - _API_GetSystemMetrics($SM_CXFRAME))
  _tagSetData($tRect1, "Bottom", _API_GetSystemMetrics($SM_CYCAPTION))
  _API_SetBkColor($hDC, $iColor)
  _API_SetTextColor($hDC, 0xFFFFFF)
  _API_DrawText($hDC, "My Caption", $tRect1, BitOR($DT_CENTER, $DT_VCENTER))
  _API_ReleaseDC($hWnd, $hDC)
EndFunc
Auto3Lib: A library of over 1200 functions for AutoIt
Posted (edited)

Valuater

  Quote

Simple to understand... and as a simple solution

Thanks, but i tried this, and as eHrgo say, on vista (or windows with some addition styles) it will be useless.

PaulIA

  Quote

Grab Auto3Lib for the API calls:

OK! thanks you very much! it' s work... but... how can i make the background of title to be transparent? (just like the original title)?

Edit: Correct some serious spelling mistakes :whistle:

Edited by MsCreatoR

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  MsCreatoR said:

OK! thanks you very much! it' s work... but... how can i make the background of title to be transparent? (just like the original title)?

This example uses the colors that are set on your machine as the active caption and inactive caption for the background and white for the text color. You can play around with the colors that are passed in the SetBkColor and SetTextColor calls if you want to use different colors for the background/text.

If you're using a theme for your desktop (like Vista Aero), you'll have to change the color calls to be theme aware. More code than I care to write at the momemt. :whistle:

Auto3Lib: A library of over 1200 functions for AutoIt
Posted

PaulIA

  Quote

If you're using a theme for your desktop (like Vista Aero), you'll have to change the color calls to be theme aware

No, i don't using any thems, and on my desktop the icons have transparent color...

The active caption and inactive caption this is the color of selected items? if not, then i have another question (sorry for litle offtop) - How can i get the system color of selected items? i mean, that color that around the selectd file (by default its dark-blue). The function _API_GetSysColor($iColor) can get it?

P.S

Thank you for you help, and see here :whistle:

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  MsCreatoR said:

PaulIA

No, i don't using any thems, and on my desktop the icons have transparent color...

The active caption and inactive caption this is the color of selected items? if not, then i have another question (sorry for litle offtop) - How can i get the system color of selected items? i mean, that color that around the selectd file (by default its dark-blue). The function _API_GetSysColor($iColor) can get it?

P.S

Thank you for you help, and see here :whistle:

No, the active/inactive caption colors are the background of the window caption when the window is active/inactive. When an item is selected, I believe that the constant is COLOR_HIGHLIGHT and the text itself is COLOR_HIGHLIGHTTEXT. Here is the MSDN link for GetSysColor that has all of the color constants.
Auto3Lib: A library of over 1200 functions for AutoIt

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...