Jump to content

Set Title On Center


Recommended Posts

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.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Valuater

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

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

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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
Link to comment
Share on other sites

PaulIA

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:

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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