Jump to content
corz

Help my one-hit-wonder!

Recommended Posts

corz

This is a magnifier-color-picker thing mostly based on some code I found on Stack Overflow, of all places. At least all the clever bits are from there. 

I'd love to use this code inside an app I'm working on. But it has an issue. The first time the mag pops up it works perfectly, but the second and subsequent times, it's a boring grey square. 

One of you smart dudes will probably look at this and go, "Aha!", but I'm stumped.

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <StaticConstants.au3>

MagWindow()
MagWindow()

; Magnifier-Color-Picker..
; Props to McBarby for the cross-hairs.
func MagWindow()

    global $iMagZoom = 5
    global $iMagWidth = Ceiling(100/$iMagZoom)
    global $iMagHeight = Ceiling(100/$iMagZoom)

    global $hDCDesk, $hDCZoom, $hPen
    global $hUser32 = DllOpen("user32.dll")
    global $hGDI32 = DllOpen("gdi32.dll")
    global $pixel_color, $mag_open = false
    local  $mX, $mY
    
    global $hCross = GUICreate('', 48, 48, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
    WinSetTrans($hCross, '', 0)
    GUISetCursor(3, 1, $hCross)

    global $hZoom = GUICreate("MagPicker", $iMagWidth * $iMagZoom, $iMagHeight * $iMagZoom, _
                    MouseGetPos(0), MouseGetPos(1), $WS_POPUP+$WS_BORDER, $WS_EX_TOPMOST)

    global $mag_label = GUICtrlCreateLabel("placehold", (($iMagHeight * $iMagZoom)/2)+2, ($iMagHeight * $iMagZoom) - 13, _
                            (($iMagHeight * $iMagZoom)/2)-3, 12, $SS_RIGHT)
    
    ; put this after the GUICreate()s so that it will not error on startup with mouse already moving. (now trapped! but we will leave them here.)
    global $__hMouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
    global $__hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($__hMouseProc), _WinAPI_GetModuleHandle(0))
        
    GUISetState(@SW_SHOW, $hCross)
    GUISetState(@SW_SHOW, $hZoom)
    $mag_open = true
    
    ; once at start, then from the mouse-callback-function..
    _Magnify()
    
    while $mag_open
        Sleep(50)
        $mX = MouseGetPos(0)
        $mY = MouseGetPos(1)        
        $pixel_color = Hex(PixelGetColor($mX, $mY), 6)
        GUICtrlSetData ($mag_label, $pixel_color)
    wend
    
    GUIDelete($hZoom)
    GUIDelete($hCross)
    ReleaseHooks()
    
endfunc

func _Magnify($_iX=-1, $_iY=-1)
    local Static $fInit = true
    if $fInit then
        $fInit = False
        $hDCDesk = (DLLCall($hUser32, "int", "GetDC", "hwnd", 0))[0]
        $hDCZoom = (DLLCall($hUser32, "int", "GetDC", "hwnd", $hZoom))[0]
        $hPen = (DLLCall($hGDI32, "int", "CreatePen", "int", 0, "int", 3, "int", 0x008b9094))[0] ; 0=PS_SOLID, dark-blue (0x00BBGGRR)
        DLLCall($hGDI32, "int", "SelectObject", "int", $hDCZoom, "hwnd", $hPen)
        $_iX = MouseGetPos(0)
        $_iY = MouseGetPos(1)
    endif
    local $iW = $iMagWidth * $iMagZoom, $iH = $iMagHeight * $iMagZoom
    if not @error then
        DLLCall($hGDI32, "int", "StretchBlt", "int", $hDCZoom, "int", _
            0, "int", 0, "int", $iW, "int", $iH, "int", $hDCDesk, "int", _
            $_iX - $iMagWidth/2, "int", $_iY - $iMagHeight/2, "int", $iMagWidth ,"int", $iMagHeight, _
            "long", $SRCCOPY)
        ; draw the crosshair    (start x, start y, end x, end y)
        _GDI32_DrawLine($hDCZoom, ($iW/2)-2, $iH/8, ($iW/2)-2, 4*($iH/8)-6, $hGDI32)     ; vertical top
        _GDI32_DrawLine($hDCZoom, ($iW/2)-2, 5*($iH/8)-10, ($iW/2)-2, 7*($iH/8), $hGDI32) ; vertical bottom
        _GDI32_DrawLine($hDCZoom, $iW/8, ($iH/2)-2, (3*($iW/8))+6, ($iH/2)-2, $hGDI32)     ; horizontal left
        _GDI32_DrawLine($hDCZoom, 4*($iW/8)+3, ($iH/2)-2, 7*($iW/8), ($iH/2)-2, $hGDI32) ; horizontal right
    endif
endfunc

func _GDI32_DrawLine(ByRef $_hDC, $_iX0, $i_Y0, $_iX1, $i_Y1, $_hDll=-1)
    If $_hDll = -1 then $_hDll = "gdi32.dll"
    Local $tCurrent = DllStructCreate("struct; long X;long Y; endstruct")
    DllCall($_hDll, "int", "MoveToEx", "int", $_hDC, "int", $_iX0, "int", $i_Y0, "ptr", DllStructGetPtr($tCurrent))
    DllCall($_hDll, "int", "LineTo", "int", $_hDC, "int", $_iX1, "int", $i_Y1)
    return $tCurrent
endfunc

func _MouseProc($_nCode, $_wParam, $_lParam)
    local $tMSLLHOOKSTRUCT = DllStructCreate("struct; long X;long Y; endstruct; " & _
        "DWORD mouseData; DWORD flags; DWORD time; ULONG_PTR dwExtraInfo;endstruct", $_lParam)
    if $_nCode < 0 Then Return _WinAPI_CallNextHookEx($__hHook, $_nCode, $_wParam, $_lParam)
    local $iX = $tMSLLHOOKSTRUCT.X, $iY = $tMSLLHOOKSTRUCT.Y
    switch $_wParam
        case $WM_LBUTTONDOWN
            CloseMag()
        case $WM_MOUSEMOVE
            if not $mag_open then return
            WinMove($hCross, "", $iX -24, $iY -24)
            Local $iXz = ($iX +24 + $iMagWidth*$iMagZoom > @DesktopWidth) ? $iX -(24 + $iMagWidth*$iMagZoom) : $iX +24
            Local $iYz = ($iY +24 + $iMagHeight*$iMagZoom > @DesktopHeight) ? $iY -(24 + $iMagHeight*$iMagZoom) : $iY +24
            WinMove($hZoom, "", $iXz + $iMagWidth/2, $iYz)
            _Magnify($iX, $iY)
    endswitch
    return _WinAPI_CallNextHookEx($__hHook, $_nCode, $_wParam, $_lParam)
endfunc

func ReleaseHooks()
    DLLCall($hUser32, "int", "ReleaseDC", "int", $hDCZoom, "hwnd", $hPen)
    DLLCall($hUser32, "int", "ReleaseDC", "int", $hDCDesk, "hwnd", 0)
    DLLCall($hUser32, "int", "ReleaseDC", "int", $hDCZoom, "hwnd", 0)
    DllClose($hUser32)
    DllClose($hGDI32)
    _WinAPI_UnhookWindowsHookEx($__hHook)
    DllCallbackFree($__hMouseProc)
endfunc

func CloseMag()  ; called by mouse left click
    $mag_open = false
endfunc

 

Thanks for any and all insights!

;o) Cor


nothing is foolproof to the sufficiently talented fool..

Share this post


Link to post
Share on other sites
Jos

Nice ...   try this version and find the difference :)

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <StaticConstants.au3>

MagWindow()
MagWindow()

; Magnifier-Color-Picker..
; Props to McBarby for the cross-hairs.
Func MagWindow()

    Global $iMagZoom = 5
    Global $iMagWidth = Ceiling(100 / $iMagZoom)
    Global $iMagHeight = Ceiling(100 / $iMagZoom)

    Global $hDCDesk = 0, $hDCZoom = 0, $hPen = 0
    Global $hUser32 = DllOpen("user32.dll")
    Global $hGDI32 = DllOpen("gdi32.dll")
    Global $pixel_color, $mag_open = False
    Local $mX = 0, $mY = 0

    Global $hCross = GUICreate('', 48, 48, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
    WinSetTrans($hCross, '', 0)
    GUISetCursor(3, 1, $hCross)

    Global $hZoom = GUICreate("MagPicker", $iMagWidth * $iMagZoom, $iMagHeight * $iMagZoom, _
            MouseGetPos(0), MouseGetPos(1), $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST)

    Global $mag_label = GUICtrlCreateLabel("placehold", (($iMagHeight * $iMagZoom) / 2) + 2, ($iMagHeight * $iMagZoom) - 13, _
            (($iMagHeight * $iMagZoom) / 2) - 3, 12, $SS_RIGHT)

    ; put this after the GUICreate()s so that it will not error on startup with mouse already moving. (now trapped! but we will leave them here.)
    Global $__hMouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
    Global $__hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($__hMouseProc), _WinAPI_GetModuleHandle(0))

    GUISetState(@SW_SHOW, $hCross)
    GUISetState(@SW_SHOW, $hZoom)
    $mag_open = True

    ; once at start, then from the mouse-callback-function..
    _Magnify()

    While $mag_open
        Sleep(50)
        $mX = MouseGetPos(0)
        $mY = MouseGetPos(1)
        $pixel_color = Hex(PixelGetColor($mX, $mY), 6)
        GUICtrlSetData($mag_label, $pixel_color)
    WEnd

    GUIDelete($hZoom)
    GUIDelete($hCross)
    ReleaseHooks()

EndFunc   ;==>MagWindow

Func _Magnify($_iX = -1, $_iY = -1, $reset = False)
    Local Static $fInit = True
    If $fInit Then
        $fInit = False
        $hDCDesk = (DllCall($hUser32, "int", "GetDC", "hwnd", 0))[0]
        $hDCZoom = (DllCall($hUser32, "int", "GetDC", "hwnd", $hZoom))[0]
        $hPen = (DllCall($hGDI32, "int", "CreatePen", "int", 0, "int", 3, "int", 0x008b9094))[0] ; 0=PS_SOLID, dark-blue (0x00BBGGRR)
        DllCall($hGDI32, "int", "SelectObject", "int", $hDCZoom, "hwnd", $hPen)
        $_iX = MouseGetPos(0)
        $_iY = MouseGetPos(1)
    EndIf
    Local $iW = $iMagWidth * $iMagZoom, $iH = $iMagHeight * $iMagZoom
    If Not @error Then
        DllCall($hGDI32, "int", "StretchBlt", "int", $hDCZoom, "int", _
                0, "int", 0, "int", $iW, "int", $iH, "int", $hDCDesk, "int", _
                $_iX - $iMagWidth / 2, "int", $_iY - $iMagHeight / 2, "int", $iMagWidth, "int", $iMagHeight, _
                "long", $SRCCOPY)
        ; draw the crosshair    (start x, start y, end x, end y)
        _GDI32_DrawLine($hDCZoom, ($iW / 2) - 2, $iH / 8, ($iW / 2) - 2, 4 * ($iH / 8) - 6, $hGDI32) ; vertical top
        _GDI32_DrawLine($hDCZoom, ($iW / 2) - 2, 5 * ($iH / 8) - 10, ($iW / 2) - 2, 7 * ($iH / 8), $hGDI32) ; vertical bottom
        _GDI32_DrawLine($hDCZoom, $iW / 8, ($iH / 2) - 2, (3 * ($iW / 8)) + 6, ($iH / 2) - 2, $hGDI32) ; horizontal left
        _GDI32_DrawLine($hDCZoom, 4 * ($iW / 8) + 3, ($iH / 2) - 2, 7 * ($iW / 8), ($iH / 2) - 2, $hGDI32) ; horizontal right
    EndIf
    If $reset Then
        $fInit = True
    EndIf
EndFunc   ;==>_Magnify

Func _GDI32_DrawLine(ByRef $_hDC, $_iX0, $i_Y0, $_iX1, $i_Y1, $_hDll = -1)
    If $_hDll = -1 Then $_hDll = "gdi32.dll"
    Local $tCurrent = DllStructCreate("struct; long X;long Y; endstruct")
    DllCall($_hDll, "int", "MoveToEx", "int", $_hDC, "int", $_iX0, "int", $i_Y0, "ptr", DllStructGetPtr($tCurrent))
    DllCall($_hDll, "int", "LineTo", "int", $_hDC, "int", $_iX1, "int", $i_Y1)
    Return $tCurrent
EndFunc   ;==>_GDI32_DrawLine

Func _MouseProc($_nCode, $_wParam, $_lParam)
    Local $tMSLLHOOKSTRUCT = DllStructCreate("struct; long X;long Y; endstruct; " & _
            "DWORD mouseData; DWORD flags; DWORD time; ULONG_PTR dwExtraInfo;endstruct", $_lParam)
    If $_nCode < 0 Then Return _WinAPI_CallNextHookEx($__hHook, $_nCode, $_wParam, $_lParam)
    Local $iX = $tMSLLHOOKSTRUCT.X, $iY = $tMSLLHOOKSTRUCT.Y
    Switch $_wParam
        Case $WM_LBUTTONDOWN
            CloseMag()
        Case $WM_MOUSEMOVE
            If Not $mag_open Then Return
            WinMove($hCross, "", $iX - 24, $iY - 24)
            Local $iXz = ($iX + 24 + $iMagWidth * $iMagZoom > @DesktopWidth) ? $iX - (24 + $iMagWidth * $iMagZoom) : $iX + 24
            Local $iYz = ($iY + 24 + $iMagHeight * $iMagZoom > @DesktopHeight) ? $iY - (24 + $iMagHeight * $iMagZoom) : $iY + 24
            WinMove($hZoom, "", $iXz + $iMagWidth / 2, $iYz)
            _Magnify($iX, $iY)
    EndSwitch
    Return _WinAPI_CallNextHookEx($__hHook, $_nCode, $_wParam, $_lParam)
EndFunc   ;==>_MouseProc

Func ReleaseHooks()
    _Magnify(Default, Default, True)
    DllCall($hUser32, "int", "ReleaseDC", "int", $hDCZoom, "hwnd", $hPen)
    DllCall($hUser32, "int", "ReleaseDC", "int", $hDCDesk, "hwnd", 0)
    DllCall($hUser32, "int", "ReleaseDC", "int", $hDCZoom, "hwnd", 0)
    DllClose($hUser32)
    DllClose($hGDI32)
    _WinAPI_UnhookWindowsHookEx($__hHook)
    DllCallbackFree($__hMouseProc)
EndFunc   ;==>ReleaseHooks

Func CloseMag() ; called by mouse left click
    $mag_open = False
EndFunc   ;==>CloseMag

Jos

  • Like 1

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
corz

Jos! As ever, you are a star!

Reset. Very clever! Ta, mate!

;o) Cor


nothing is foolproof to the sufficiently talented fool..

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

  • Similar Content

    • WoodGrain
      By WoodGrain
      Hi guys,
      I'm learning about GUI's, I'm trying the below code, the idea being if I press the letter "e" while I have the GUI open I want the label color to change to green (I'm using a UDF for label colors). But every time I press "e" on my keyboard I just get a "ding" sound from my speakers and nothing changes with the label.
      I've looked at using something like "While GUIGetMsg() <> $GUI_EVENT_CLOSE" as I've seen it in other code instead of "While 1", but I don't think it's relevant.
      #include <GUIConstantsEx.au3>; for GUI... #include <GUIRichLabel.au3>; UDF for rich text label fonts #include <Misc.au3>; for _IsPressed $myLetter = "e" $hGUI = GUICreate("test", 700, 60) $lbl2 = _GUICtrlRichLabel_Create($hGUI, '<font color="purple">' & $myLetter & '</font>', 10, 10); , 260, 25 GUISetState(@SW_SHOW) Local $hDLL = DllOpen("user32.dll") While 1 if _IsPressed(Hex($myLetter), $hDLL) Then While _IsPressed(Hex($myLetter), $hDLL) Sleep(250) WEnd _GUICtrlRichLabel_SetData($lbl2, '<font color="green">' & $myLetter & '</font>') Sleep(2000) DllClose($hDLL) Exit EndIf Sleep(50) WEnd DllClose($hDLL) I am using an array of letters that I'm wanting to do this for, but as I can't get it to work I've stripped it down to the simplest code I can think of to try and get this working first. Appreciate any help.
      Thanks!
    • nacerbaaziz
      By nacerbaaziz
      hi dears, i have an question please if you can help me.
      i maked an program to do some functions
      and this program works with the global hot keys
      i added an option to the users to change the hot keys
      when i searched about how to do that i found this UDF
      GUIHotkey.au3
      http://www.autoitscript.com/forum/index.php?showtopic=107965
      but the problem here that this UDF cant be detect the win key.
      can you help me to add it, or if there are any others UDFSS wich do that work please give me some.
      i hope that my question is clear for you.
      thanks in advance
    • Silas
      By Silas
      Hello everyone,
      I have a radio button ($Radio1), which I want to disable as soon as another one get's checked (Radio5). (The system fails if the radio button i'm troubling with also gets checked).
      I know how to disable him:
      If GUICtrlRead($Radio1)=1 And Not BitAND(GUICtrlGetState($Radio5), $GUI_DISABLE) Then GUICtrlSetState($Radio5, 128) But if i try to enable $Radio5 again, after $Radio1 isn't checked anymore, it fails:
      If GUICtrlRead($Radio1)=Not 1 And Not BitAND(GUICtrlGetState($Radio5), $GUI_ENABLE) Then GUICtrlSetState($Radio5, 64)  
      Anyone knows why?
    • Bllee
      By Bllee
      every time i press "delete button" delete a line, but i can't add new line with info. the id line write normally but i can't change or add new info
      obs: looking at the "includes" one realizes that already tried of everything that knew
      my code
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> #include <StringConstants.au3> #include <Array.au3> #include <GuiListBox.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 612, 480, 192, 154) $MenuItem1 = GUICtrlCreateMenu("&Arquivo") $MenuItem2 = GUICtrlCreateMenuItem("Salvar Ctrl+S", $MenuItem1, $SS_CENTER) $MenuItem4 = GUICtrlCreateMenuItem("Carregar Ctrl+O", $MenuItem1, $SS_CENTER) $MenuItem3 = GUICtrlCreateMenuItem("Salvar Como Shitft+Ctrl+S", $MenuItem1, $SS_CENTER) $Group1 = GUICtrlCreateGroup("", 21, 8, 569, 97, $SS_CENTER) $Input1 = GUICtrlCreateInput("ID COR", 122, 32, 97, 21, $SS_CENTER) $Input2 = GUICtrlCreateInput("REGIÃO", 138, 64, 249, 21, $SS_CENTER) $Input3 = GUICtrlCreateInput("Label", 264, 30, 121, 21, $SS_CENTER) $Label1 = GUICtrlCreateLabel("Label", 232, 32, 30, 17, $SS_CENTER) $Button1 = GUICtrlCreateButton("Capturar Cor", 42, 30, 75, 25, $SS_CENTER) $Button2 = GUICtrlCreateButton("Capturar Região", 42, 62, 91, 25, $SS_CENTER) $Button3 = GUICtrlCreateButton("ADD", 442, 24, 113, 33) $Button5 = GUICtrlCreateButton("Delet", 442, 64, 113, 33) $Group2 = GUICtrlCreateGroup("Editar ID selecionado", 8, 384, 601, 57, $SS_CENTER) $Input7 = GUICtrlCreateInput("ID", 10, 402, 40,21, $SS_CENTER) $Input4 = GUICtrlCreateInput("COR", 51, 402, 121, 21, $SS_CENTER) $Input5 = GUICtrlCreateInput("REGIÃO", 173, 402, 249, 21, $SS_CENTER) $Input6 = GUICtrlCreateInput("LABEL", 423, 402, 121, 21, $SS_CENTER) $Button4 = GUICtrlCreateButton("\/", 544, 400, 30, 25, $SS_CENTER) $Button6 = GUICtrlCreateButton("/\", 574, 400, 30, 25, $SS_CENTER) ; Add column Global $id = Int(0) $List1 = GUICtrlCreateListView("",5, 120, 601, 253, $SS_CENTER) _GUICtrlListView_AddColumn($List1, "ID",40) _GUICtrlListView_AddColumn($List1, "COR",100) _GUICtrlListView_AddColumn($List1, "COORDENADA",305) _GUICtrlListView_AddColumn($List1, "LABEL",150) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MenuItem2 MsgBox($MB_SYSTEMMODAL, "ctrl + s", "Nothing Here",1) Case $MenuItem3 MsgBox($MB_SYSTEMMODAL, "shift+ctrl s", "Nothing Here",1) Case $MenuItem4 MsgBox($MB_SYSTEMMODAL, "ctrl + o", "Nothing Here",1) Case $Button1 MsgBox($MB_SYSTEMMODAL, "Capturar cor", "Aperte espaço para capturar a cor") GUICtrlSetData($Input1,MouseColor()) Case $Button2 MsgBox($MB_SYSTEMMODAL, "capturar região", "Aperte espaço para capturar a posição inicial") local $mouse = MouseGetPos() $x_init = $mouse[0] $y_init = $mouse[1] MsgBox($MB_SYSTEMMODAL, "capturar região", "Aperte espaço para capturar a posição final") local $mouse = MouseGetPos() $x_end = $mouse[0] $y_end = $mouse[1] GUICtrlSetData($Input2,$x_init&','&$y_init&' ; '&$x_end&','&$y_end) Case $Button3 _GUICtrlListView_AddItem($List1, $id, 1) ; id _GUICtrlListView_AddSubItem($List1, $id, GUICtrlRead($Input1), 1, 1) ;cor _GUICtrlListView_AddSubItem($List1, $id, GUICtrlRead($Input2), 2, 1) ;coordenada _GUICtrlListView_AddSubItem($List1, $id, GUICtrlRead($Input3), 3, 1) ;label $id= $id + 1 Case $Button4 $Item = _GUICtrlListView_GetSelectedIndices($List1) $Sid = _GUICtrlListView_GetItem($List1, Number($Item),0) $Scor = _GUICtrlListView_GetItem($List1, Number($Item),1) $Scord = _GUICtrlListView_GetItem($List1, Number($Item),2) $Slabel = _GUICtrlListView_GetItem($List1, Number($Item),3) ; get info GUICtrlSetData($Input7,$Sid[3]) GUICtrlSetData($Input4,$Scor[3]) GUICtrlSetData($Input5,$Scord[3]) GUICtrlSetData($Input6,$Slabel[3]) Case $Button5 _GUICtrlListView_DeleteItemsSelected($List1) Case $Button6 ; give back inf if GUICtrlRead($Input7) <> "ID" Then _GUICtrlListView_SetItem($List1, GUICtrlRead($Input4), GUICtrlRead($Input7),1) ;cor _GUICtrlListView_SetItem($List1, GUICtrlRead($Input5), GUICtrlRead($Input7),2) ;coordenada _GUICtrlListView_SetItem($List1, GUICtrlRead($Input6), GUICtrlRead($Input7),3) ;coordenada EndIf EndSwitch WEnd Func MouseColor() local $mouse = MouseGetPos() Return Hex(PixelGetColor($mouse[0],$mouse[1]), 6) EndFunc  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      First, I want to apologize with you for the title not very clear, but I thought a little bit on which title to set at the thread, and this is the one that came in mind.
      Now, let me explain what I'm trying to understand.

      I am making an application ( with n clients ), with an SQLite Database, which has a Main form, and n sub-forms... 
      Since these sub-forms are called several times, because they are used to add or update records to the Database, I put the code that generates the GUI of these sub-forms in Functions.
      There are two sub-forms which are "treated" as two main forms, since even them have n sub-forms, which perform various tasks.
      Where am I stucked?

      For the Main form I created a Status Bar, in order to display messages ( add/delete/update/search results ), and it works perfectly with all the forms which don't have other sub-forms.
      For the two forms, which indeed have n sub-forms, I created two separated Status Bars, which are (re)created everytime I call the function that then displays the form.
      Practically, I can't set icons to these two Status Bars, and I don't know why.
      I'm really sorry that I don't feel clear enough, so, here you are an example of what I am saying.
      I recreated exactly what my script does:
      #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $frmSubForm, _ $txtSubFormField, _ $sbSubFormStatusBar, _ $objSB_IconError = _WinAPI_LoadShell32Icon(109), _ $objSB_IconInformation = _WinAPI_LoadShell32Icon(277) #Region ### START Koda GUI section ### Form= $frmMainForm = GUICreate("Main Form", 300, 300, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") $sbMainStatusBar = _GUICtrlStatusBar_Create($frmMainForm) $btnCreateSubForm = GUICtrlCreateButton("Create Sub Form", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "GenerateSubForm") GUICtrlSetFont(-1, 10, 400, 0, "Arial") _GUICtrlStatusBar_SetSimple($sbMainStatusBar) _GUICtrlStatusBar_SetText($sbMainStatusBar, "") GUISetState(@SW_SHOW, $frmMainForm) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func GenerateSubForm() #Region ### START Koda GUI section ### Form= $frmSubForm = GUICreate("Sub-Form", 300, 300, -1, -1, -1, -1, $frmMainForm) GUISetOnEvent($GUI_EVENT_CLOSE, "DeleteSubForm") $txtSubFormField = GUICtrlCreateInput("", 0, 0, 100, 20) $btnCheckSubFormField = GUICtrlCreateButton("Check Field", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "CheckSubFormField") GUICtrlSetFont(-1, 10, 400, 0, "Arial") $sbSubFormStatusBar = _GUICtrlStatusBar_Create($frmSubForm) _GUICtrlStatusBar_SetSimple($sbSubFormStatusBar) _GUICtrlStatusBar_SetText($sbSubFormStatusBar, "") GUISetState(@SW_SHOW, $frmSubForm) GUISetState(@SW_DISABLE, $frmMainForm) #EndRegion ### END Koda GUI section ### EndFunc Func DeleteSubForm() ; Declared Globally => $frmSubForm GUIDelete($frmSubForm) GUISetState(@SW_ENABLE, $frmMainForm) EndFunc Func WriteToStatusBar($sbStatusBar, $objSB_Icon, $strText) _GUICtrlStatusBar_SetIcon($sbStatusBar, 0, $objSB_Icon) _GUICtrlStatusBar_SetText($sbStatusBar, $strText) ConsoleWrite("Icon Handle: " & $objSB_Icon & @CRLF) EndFunc Func CheckSubFormField() ; Declared Globally => $txtSubFormField If GUICtrlRead($txtSubFormField) = "" Then ; Declared Globally => $sbStatusBar WriteToStatusBar($sbSubFormStatusBar, $objSB_IconError, "Field NOK.") Else WriteToStatusBar($sbSubFormStatusBar, $objSB_IconInformation, "Field OK.") EndIf EndFunc The text is set, but icon is not.
      Could someone please tell me why?
      Thanks everyone in advance  

      Best Regards.
×