Jump to content
Sign in to follow this  
gil900

How to create a new button here?

Recommended Posts

gil900

Hello

How can i create a new button here? :

Posted Image

How it can be done?

Thanks for helpers!

Share this post


Link to post
Share on other sites
Nessie

Brutal way:

;Author: coded by rover for themes from example by Funkey 2k11
;WM_NCLBUTTONDOWN does not work like expected Costum titlebar
;http://www.autoitscript.com/forum/topic/125012-wm-nclbuttondown-does-not-work-like-expected/page__p__868177__fromsearch__1#entry868177
;Thanks to Yashied for the theme engine API's in WinAPIEx.au3

;#forceref not used in WinAPIEx.au3 and APIConstants.au3
;too many declared, but not used errors if this line used
;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6


#include <APIConstants.au3>
#include <FrameConstants.au3>
#include <GUIConstantsEx.au3>
#Include <Constants.au3>
#include <WinAPI.au3>
#Include <WinAPIEx.au3>
#include <WindowsConstants.au3>

If @OSVersion <> "WIN_XP" Then
    MsgBox(262144+48, "XP ONLY", "This only works on XP"&@CRLF&"Vista and 7 use DWM,"&@CRLF&"so a different method is required to do this")
    Exit
EndIf

Opt('MustDeclareVars', 1)


;need non-client area dimensions here
Global $tRECT = _WinAPI_CreateRectEx(300, 3, 40, 18)
;quick hack to set rect in non-client area
Global $tRECTx = _WinAPI_CreateRectEx(300, -22, 35, 16)
Global $msg, $nState = 1, $hTheme, $nPrev = -1, $fBtnTFont = True
Global $fNCKeyDn = False, $fNCKeyUp = False, $fBtnHot = False

Global $hGui = GUICreate("Title bar button", 500, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX))
Global $cBtn1 = GUICtrlCreateButton("Disable", 40, 40, 100, 25)
Global $cBtn2 = GUICtrlCreateButton("Hide", 40, 100, 100, 25)
Global $cBtnTBar = GUICtrlCreateDummy()

$hTheme = _WinAPI_OpenThemeData($hGui, 'Button')
If @error Then $hTheme = 0
Global $tLOGFONT = _WinAPI_GetThemeFont($hTheme, 1, 1, $TMT_FONT)
;ConsoleWrite('- DllStructGetData($tLOGFONT, "FaceName") = ' & DllStructGetData($tLOGFONT, "FaceName") & @crlf)
Global $hFont = _WinAPI_CreateFontIndirect($tLOGFONT)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hFont = ' & $hFont & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
;no theme font, so use default
If $hFont = 0 Then
    $hFont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)
    $fBtnTFont = False
EndIf


GUIRegisterMsg($WM_THEMECHANGED, "_WinProc")
GUIRegisterMsg($WM_NCMOUSEMOVE, "_WinProc")
GUIRegisterMsg($WM_NCHITTEST, "_WinProc")
GUIRegisterMsg($WM_NCLBUTTONUP, "_WinProc")
GUIRegisterMsg($WM_NCLBUTTONDOWN, "_WinProc")
GUIRegisterMsg($WM_NCLBUTTONDBLCLK, "_WinProc")
GUIRegisterMsg($WM_NCACTIVATE, "_WinProc")
GUIRegisterMsg($WM_NCPAINT, "_WinProc")

GUISetState()

Do
    $msg = GUIGetMsg()
    Switch $msg
        Case $cBtnTBar;title/caption bar button
            ConsoleWrite("+ Title bar button clicked" & @CRLF)
        Case $cBtn1;enable/disable
            If $nState <> -1 Then
                Switch $nState
                    Case 1
                        $nState = 4
                        GUICtrlSetData($cBtn1, "Enable")
                    Case 4
                        $nState = 1
                        GUICtrlSetData($cBtn1, "Disable")
                EndSwitch
                _WinAPI_RedrawWindow($hGui, $tRECT, 0, BitOR($RDW_INVALIDATE, $RDW_FRAME))
            EndIf
        Case $cBtn2;hide/show
            Switch $nState
                Case -1
                    $nState = $nPrev
                    GUICtrlSetData($cBtn2, "Hide")
                    _WinAPI_RedrawWindow($hGui, $tRECT, 0, BitOR($RDW_INVALIDATE, $RDW_FRAME))
                Case Else
                    $nPrev = $nState
                    $nState = -1
                    GUICtrlSetData($cBtn2, "Show")
                    _WinAPI_SetWindowPos($hGui, -1, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOACTIVATE, $SWP_NOMOVE, $SWP_NOSIZE))
            EndSwitch
    EndSwitch

Until $msg = -3

If $hTheme <> 0 Then _WinAPI_CloseThemeData($hTheme)
If $hFont <> 0 Then _WinAPI_DeleteObject($hFont)
Exit

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Local $hDC, $x, $y, $tPoint
    Switch $iMsg
        Case $WM_THEMECHANGED
            If $hTheme <> 0 Then _WinAPI_CloseThemeData($hTheme)
            If $hFont <> 0 Then _WinAPI_DeleteObject($hFont)
            $hTheme = _WinAPI_OpenThemeData($hWnd, 'Button')
            If @error Or $hTheme = 0 Then Return $GUI_RUNDEFMSG
            Local $tLOGFONT = _WinAPI_GetThemeFont($hTheme, 1, 1, $TMT_FONT)
            ;ConsoleWrite('- DllStructGetData($tLOGFONT, "FaceName") = ' & DllStructGetData($tLOGFONT, "FaceName") & @crlf)
            $hFont = _WinAPI_CreateFontIndirect($tLOGFONT)
            If $hFont = 0 Then
                $hFont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)
                $fBtnTFont = False
            Else
                $fBtnTFont = True
            EndIf
        Case $WM_NCMOUSEMOVE ;when mouse moves over or moves off of button, redraw button in Hot or Normal state
            If $hWnd <> $hgui Then Return $GUI_RUNDEFMSG
            ;when mouse moved off button, redraw button in Normal state
            If ($wParam = $HTCAPTION Or $wParam = $HTTOP) And ($nState = 2 Or $nState = 3) Then
                $nState = 1
                $fBtnHot = False
                _WinAPI_RedrawWindow($hWnd, $tRECT, 0, BitOR($RDW_INVALIDATE, $RDW_FRAME))
            EndIf
            ;when mouse moves over button, redraw button in Hot state
            If $wParam = $HTBORDER And $nState <> 4 And $nState <> -1 Then ;return from WM_NCHITTEST is HTBORDER
                $tPoint = DllStructCreate($tagPOINT)
                DllStructSetData($tPoint, 1, BitAND($lParam, 0x0000FFFF))
                DllStructSetData($tPoint, 2, BitShift($lParam, 16))
                _WinAPI_ScreenToClient($hWnd, $tPoint)
                If _WinAPI_PtInRect($tRECTx, $tPoint) Then
                    If $fBtnHot = False Then
                        $nState = 2
                        $fBtnHot = True
                        _WinAPI_RedrawWindow($hWnd, $tRECT, 0, BitOR($RDW_INVALIDATE, $RDW_FRAME))
                    EndIf
                EndIf
            EndIf
            Return $GUI_RUNDEFMSG
        Case $WM_NCHITTEST
            If $hWnd <> $hgui Then Return $GUI_RUNDEFMSG
            $tPoint = DllStructCreate($tagPOINT)
            DllStructSetData($tPoint, 1, BitAND($lParam, 0x0000FFFF))
            DllStructSetData($tPoint, 2, BitShift($lParam, 16))
            _WinAPI_ScreenToClient($hWnd, $tPoint)
            If _WinAPI_PtInRect($tRECTx, $tPoint) Then
                $fNCKeyDn = True
                Return $HTBORDER ; tell the window the mouse is clicking on the border so we get a WM_NCLBUTTONUP message
            EndIf
            $fNCKeyDn = False ;required to prevent key down message if titlebar clicked after keyup on button
            Return $GUI_RUNDEFMSG
        Case $WM_NCLBUTTONUP
            If $hWnd <> $hgui Then Return $GUI_RUNDEFMSG
            If $nState = 2 Then
                $nState = 1
                $fBtnHot = False
                _WinAPI_RedrawWindow($hWnd, $tRECT, 0, BitOR($RDW_INVALIDATE, $RDW_FRAME))
            EndIf
            If $fNCKeyDn = True And $fNCKeyUp = True Then
                $fNCKeyUp = False
                $nState = 2
                GUICtrlSendToDummy($cBtnTBar)
                _WinAPI_RedrawWindow($hWnd, $tRECT, 0, BitOR($RDW_INVALIDATE, $RDW_FRAME))
                $x = BitAND($lParam, 0x0000FFFF)
                $y = BitShift($lParam, 16)
                ConsoleWrite("+Up at " & $x & "/" & $y & @cr)
            EndIf
            Return $GUI_RUNDEFMSG
        ;WM_NCLBUTTONDBLCLK: optionally allow fast clicking of button, otherwise some repeated clicks are missed.
        Case $WM_NCLBUTTONDOWN, $WM_NCLBUTTONDBLCLK
            If $hWnd <> $hgui Then Return $GUI_RUNDEFMSG
            If $fNCKeyDn = True And $nState <> 4 And $nState <> -1 Then
                $fNCKeyUp = True
                $nState = 3
                _WinAPI_RedrawWindow($hWnd, $tRECT, 0, BitOR($RDW_INVALIDATE, $RDW_FRAME))
                $x = BitAND($lParam, 0x0000FFFF)
                $y = BitShift($lParam, 16)
                ConsoleWrite("-Down at " & $x & "/" & $y & @cr)
            EndIf
            Return $GUI_RUNDEFMSG
        Case $WM_NCACTIVATE, $WM_NCPAINT
            If $hWnd <> $hgui Then Return $GUI_RUNDEFMSG
            If $nState = -1 Then Return $GUI_RUNDEFMSG
            Local $Res = _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
            ;theme button, theme window caption bar buttons or custom bitmap
            If $hTheme <> 0 Then
                $hDC = _WinAPI_GetWindowDC($hWnd)
                _WinAPI_DrawThemeBackground($hTheme, 1, $nState, $hDC, $tRECT)
                If $fBtnTFont = False Then Local $hOldFont = _WinAPI_SelectObject($hDC, $hFont)
                ;DrawThemeText uses the last font in the DC if no theme font is available.
                ;therefore the DEFAULT_GUI_FONT must be selected into the DC.
                _WinAPI_DrawThemeText($hTheme, 1, $nState, $hDC, 'OK', $tRECT, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
                If $fBtnTFont = False Then _WinAPI_SelectObject($hDC, $hOldFont)
                _Winapi_ReleaseDC($hWnd, $hDC)
            Else
                ;needs DrawFrameControl code
            EndIf

            Return $Res
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Code by rover

Hi!


My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites
gil900

this is for XP.

i got this msg:

MsgBox(262144+48, "XP ONLY", "This only works on XP"&@CRLF&"Vista and 7 use DWM,"&@CRLF&"so a different method is required to do this")

Edited by gil900

Share this post


Link to post
Share on other sites
water
might be a good starting point.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
gil900

might be a good starting point.

This is not a starting point.

It's Almost Ending point!! :thumbsup:

i need that the script will work only on windows that their style is 0x17CF0000 / 0x16CF0000 / 0x14CF0000

Share this post


Link to post
Share on other sites
gil900
water

This is not a starting point.

It's Almost Ending point!! :thumbsup:

Glad to be of service :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  

×