Jump to content

Recommended Posts

#include <GUIConstants.au3>
#Include <Misc.au3>

Opt("GUIOnEventMode", 1)

GuiCreate('Choose Color', 500, 500) 
    GuiSetOnEvent($GUI_EVENT_CLOSE, '_Exit') 

GuiCtrlCreateButton('Click me to choose a color!', 100, 200, 300, 30) 
    GuiCtrlSetOnEvent(-1, '_ChooseColorEvent') 

GuiSetState()

While 1 
    Sleep(300) 
WEnd 

Func _ChooseColorEvent() 
    $color = _ChooseColor(2, 0, 2) 
    GuiSetBkColor($color)
EndFunc

Func _Exit() 
    Exit 
EndFunc

Edited by Piano_Man
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to post
Share on other sites

That didnt do anything. WinMove() doesnt do anything either.

Mis-understood what he was asking, would have to do something like what has been done for other dialogs, run another script that would set the position being that is a system dialog.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to post
Share on other sites

#include <GUIConstants.au3>
#Include <Misc.au3>

Opt("GUIOnEventMode", 1)
$CCTitle = 'Color'
$CCText = '&Define Custom Colors'
$x = (@DesktopWidth / 2) - (453 / 2)
$y = (@DesktopHeight / 2) - (324 / 2)
GUICreate('Choose Color', 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')

GUICtrlCreateButton('Click me to choose a color!', 100, 200, 300, 30)
GUICtrlSetOnEvent(-1, '_ChooseColorEvent')

GUISetState()

While 1
    Sleep(300)
WEnd

Func _ChooseColorEvent()
    Local $file = FileOpen(EnvGet("temp") & "\ChooseColorDL.au3", 2)
    If $file = -1 Then Return;if error, give up on the move

    Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
    Local $line2 = 'WinWait("' & $CCTitle & '", "' & $CCText & '")'
    Local $line3 = 'WinMove("' & $CCTitle & '", "' & $CCText & '"' & ', ' & $x & ', ' & $y & ')'
    FileWrite($file, $line1 & @CRLF & $line2 & @CRLF & $line3)
    FileClose($file)

    Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\ChooseColorDL.au3")

    $color = _ChooseColor(2, 255, 2)

    GUISetBkColor($color)
    FileDelete(EnvGet("temp") & "\ChooseColorDL.au3")
EndFunc   ;==>_ChooseColorEvent

Func _Exit()
    Exit
EndFunc   ;==>_Exit

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to post
Share on other sites

Mis-understood what he was asking, would have to do something like what has been done for other dialogs, run another script that would set the position being that is a system dialog.

I made that clearer in my title...

(EDIT: I posted without reading Gary's last post but it still holds true for the second part)

Would what you suggest use WinMove()? I prefer not to have the window flicker from the top left to the desired position if possible...

Edited by Piano_Man
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to post
Share on other sites

Would require a change to the UDF

like so:

;===============================================================================
;
; Description:            _ChooseColor
; Parameter(s):        $i_ReturnType - Optional: determines return type
;                            $i_colorref - Optional: default selected Color
;                            $i_refType - Optional: Type of $i_colorref passed in
; Requirement:            None
; Return Value(s):    Returns COLORREF rgbcolor if $i_refType = 0 (default)
;                            Returns Hex RGB value if $i_refType = 1
;                            Returns Hex BGR Color if $i_refType = 2
;                            if error occurs, @error is set
; User CallTip:        _ChooseColor([$i_ReturnType = 0[, $i_colorref = 0[, $i_refType=0]]]) Creates a Color dialog box that enables the user to select a color. (required: <Misc.au3>)
; Author(s):            Gary Frost (custompcs at charter dot net)
; Note(s):                $i_ReturnType = 0 then COLORREF rgbcolor is returned (default)
;                            $i_ReturnType = 1 then Hex BGR Color is returned
;                            $i_ReturnType = 2 Hex RGB Color is returned
;
;                            $i_colorref = 0 (default)
;
;                            $i_refType = 0 then $i_colorref is COLORREF rgbcolor value (default)
;                            $i_refType = 1 then $i_colorref is BGR hex value
;                            $i_refType = 2 then $i_colorref is RGB hex value
;
;===============================================================================
Func _ChooseColor($i_ReturnType = 0, $i_colorref = 0, $i_refType = 0, $h_wnd_owner = 0)
;~ typedef struct {
;~     DWORD lStructSize;
;~     HWND hwndOwner;
;~     HWND hInstance;
;~     COLORREF rgbResult;
;~     COLORREF *lpCustColors;
;~     DWORD Flags;
;~     LPARAM lCustData;
;~     LPCCHOOKPROC lpfnHook;
;~     LPCTSTR lpTemplateName;
;~ } CHOOSECOLOR, *LPCHOOSECOLOR;
    Local $custcolors = "int[16]"
    Local $struct = "dword;int;int;int;ptr;dword;int;ptr;ptr"
    Local $p = DllStructCreate($struct)
    If @error Then
        ;MsgBox(0,"","Error in DllStructCreate " & @error);
        SetError(-1)
        Return -1
    EndIf
    Local $cc = DllStructCreate($custcolors)
    If @error Then
        ; MsgBox(0,"","Error in DllStructCreate " & @error);
        ;        DllStructDelete ($p)
        SetError(-2)
        Return -1
    EndIf
    If ($i_refType == 1) Then
        $i_colorref = Int($i_colorref)
    ElseIf ($i_refType == 2) Then
        $i_colorref = Hex(String($i_colorref), 6)
        $i_colorref = '0x' & StringMid($i_colorref, 5, 2) & StringMid($i_colorref, 3, 2) & StringMid($i_colorref, 1, 2)
    EndIf
    ConsoleWrite($h_wnd_owner & @LF)
    DllStructSetData($p, 1, DllStructGetSize($p))
    DllStructSetData($p, 2, $h_wnd_owner)
    DllStructSetData($p, 4, $i_colorref)
    DllStructSetData($p, 5, DllStructGetPtr($cc))
    DllStructSetData($p, 6, BitOR($CC_ANYCOLOR, $CC_FULLOPEN, $CC_RGBINIT))
    Local $ret = DllCall("comdlg32.dll", "long", "ChooseColor", "ptr", DllStructGetPtr($p))
    If ($ret[0] == 0) Then
        ; user selected cancel or struct settings incorrect
        ;        DllStructDelete ($p)
        ;        DllStructDelete ($cc)
        SetError(-3)
        Return -1
    EndIf
    Local $color_picked = DllStructGetData($p, 4)
    ;    DllStructDelete ($p)
    ;    DllStructDelete ($cc)
    If ($i_ReturnType == 1) Then
        ; return Hex BGR Color
        Return '0x' & Hex(String($color_picked), 6)
    ElseIf ($i_ReturnType == 2) Then
        ; return Hex RGB Color
        $color_picked = Hex(String($color_picked), 6)
        Return '0x' & StringMid($color_picked, 5, 2) & StringMid($color_picked, 3, 2) & StringMid($color_picked, 1, 2)
    ElseIf ($i_ReturnType == 0) Then
        Return $color_picked
    Else
        SetError(-4)
        Return -1
    EndIf
EndFunc   ;==>_ChooseColor
oÝ÷ Ù8^;¬µÆ¥Ø^~éܶ*'Â+a¶¡jwezÚ-ì"Ú0¶­Â¥v'Ùbë(jëh×6
#include <GUIConstants.au3>
#Include <Misc.au3>

Opt("GUIOnEventMode", 1)
GUICreate('Choose Color', 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')

GUICtrlCreateButton('Click me to choose a color!', 100, 200, 300, 30)
GUICtrlSetOnEvent(-1, '_ChooseColorEvent')

GUISetState()

While 1
    Sleep(300)
WEnd

Func _ChooseColorEvent()
    $color = _ChooseColor(2, 255, 2, WinGetHandle('Choose Color','Click me to choose a color!'))
    GUISetBkColor($color)
EndFunc   ;==>_ChooseColorEvent

Func _Exit()
    Exit
EndFunc   ;==>_Exit

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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

    No registered users viewing this page.

×
×
  • Create New...