Jump to content

Problem with GUIGetCursorInfo


Recommended Posts

I am having problems with GUIGetCursorInfo I can not get a mouse over the Checkbox to change an image, the code works but sometimes it locks and the Checkbox flashes, if anyone has any idea I will appreciate it.
I am not a programmer but I need to make a kind of menu. Sorry for my bad English I speak Spanish

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <EditConstants.au3>
#include <GUIConstants.au3>
;#include <ColorConstants.au3>



$Form1 = GUICreate("Form1", 615, 437, 192, 124)
GUISetBkColor(0x7a7a7a)

$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 56, 97, 13)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox1", 40, 80, 97, 13)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox1", 40, 104, 97, 13)
$Checkbox4 = GUICtrlCreateCheckbox("Checkbox1", 40, 128, 97, 13)
$Checkbox5 = GUICtrlCreateCheckbox("Checkbox1", 40, 152, 97, 13)
$Checkbox6 = GUICtrlCreateCheckbox("Checkbox1", 40, 176, 97, 33)
$Checkbox7 = GUICtrlCreateCheckbox("Checkbox1", 40, 200, 97, 33)
$Checkbox8 = GUICtrlCreateCheckbox("Checkbox1", 40, 224, 97, 33)
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\0.jpg", 360, 64, 217, 249)
$Edit1 = GUICtrlCreateEdit("", 160, 64, 140, 100, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY), 0)
GUICtrlSetData(-1, StringFormat("EDIT1\r\nASDFASDASDSADSAAS\r\nSADASDAS\r\nASDSADSA"))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
;GUICtrlSetCursor (-1, 2)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    _Imagen()
     If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                        Sleep(2000)

                Exit
            EndIf

WEnd
Func _Imagen()

$aCInfo = GUIGetCursorInfo($Form1)

    If $aCInfo[4] = $Checkbox1 Then
        GUICtrlSetData($Edit1, StringFormat("EDIT1\111111111"))
          GUICtrlSetImage($Pic1, @ScriptDir & "\1.bmp")
          GUICtrlSetColor($Checkbox2, 0x000000)
          GUICtrlSetColor($Checkbox3, 0x000000)
          GUICtrlSetColor($Checkbox4, 0x000000)
          GUICtrlSetColor($Checkbox5, 0x000000)
          GUICtrlSetColor($Checkbox1, 0x00FF00)

      EndIf

If $aCInfo[4] = $Checkbox2 Then
          GUICtrlSetImage($Pic1, @ScriptDir & "\2.bmp")
GUICtrlSetData($Edit1, StringFormat("EDIT1\2222222"))
          GUICtrlSetColor($Checkbox3, 0x000000)
          GUICtrlSetColor($Checkbox4, 0x000000)
          GUICtrlSetColor($Checkbox5, 0x000000)
          GUICtrlSetColor($Checkbox1, 0x000000)
          GUICtrlSetColor($Checkbox2, 0x00FF00)
      EndIf

  If $aCInfo[4] = $Checkbox3 Then
          GUICtrlSetImage($Pic1, @ScriptDir & "\3.bmp")
          GUICtrlSetData($Edit1, StringFormat("EDIT1\33333333"))
          GUICtrlSetColor($Checkbox2, 0x000000)
          GUICtrlSetColor($Checkbox4, 0x000000)
          GUICtrlSetColor($Checkbox5, 0x000000)
          GUICtrlSetColor($Checkbox1, 0x000000)
          GUICtrlSetColor($Checkbox3, 0x00FF00)
      EndIf

  If $aCInfo[4] = $Checkbox4 Then
          GUICtrlSetImage($Pic1, @ScriptDir & "\4.jpg")
          GUICtrlSetData($Edit1, StringFormat("EDIT1\4444444"))
          GUICtrlSetColor($Checkbox3, 0x000000)
          GUICtrlSetColor($Checkbox2, 0x000000)
          GUICtrlSetColor($Checkbox5, 0x000000)
          GUICtrlSetColor($Checkbox1, 0x000000)
          GUICtrlSetColor($Checkbox4, 0x00FF00)
      EndIf

  If $aCInfo[4] = $Checkbox5 Then
          GUICtrlSetImage($Pic1, @ScriptDir & "\5.jpg")
          GUICtrlSetData($Edit1, StringFormat("EDIT1\555555555"))
           GUICtrlSetColor($Checkbox3, 0x000000)
         GUICtrlSetColor($Checkbox2, 0x000000)
         GUICtrlSetColor($Checkbox4, 0x000000)
          GUICtrlSetColor($Checkbox1, 0x000000)
          GUICtrlSetColor($Checkbox5, 0x00FF00)

  EndIf


  EndFunc

 

GUIGetCursorInfo.rar

Link to comment
Share on other sites

Just use AdLibRegister after GuiSetState and remove calling _Imagen from the loop, I would also recommend checking to see if the $aCInfo[4] has changed, basic example:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <EditConstants.au3>
#include <GUIConstants.au3>

Global $g_iCInfo = Null

DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1)

Global $g_hForm = GUICreate("Form1", 615, 437, 192, 124)
    GUISetBkColor(0x7a7a7a)
    Global $g_idCheckbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 56, 97, 13)
    Global $g_idCheckbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 80, 97, 13)
    Global $g_idCheckbox3 = GUICtrlCreateCheckbox("Checkbox3", 40, 104, 97, 13)
    Global $g_idCheckbox4 = GUICtrlCreateCheckbox("Checkbox4", 40, 128, 97, 13)
    Global $g_idCheckbox5 = GUICtrlCreateCheckbox("Checkbox5", 40, 152, 97, 13)
    Global $g_idCheckbox6 = GUICtrlCreateCheckbox("Checkbox6", 40, 176, 97, 33)
    Global $g_idCheckbox7 = GUICtrlCreateCheckbox("Checkbox7", 40, 200, 97, 33)
    Global $g_idCheckbox8 = GUICtrlCreateCheckbox("Checkbox8", 40, 224, 97, 33)
    Global $g_idPic = GUICtrlCreatePic(@ScriptDir & "\0.jpg", 360, 64, 217, 249)
    Global $g_idEdit = GUICtrlCreateEdit("", 160, 64, 140, 100, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY), 0)
        GUICtrlSetData(-1, StringFormat("EDIT1\r\nASDFASDASDSADSAAS\r\nSADASDAS\r\nASDSADSA"))
        GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
        GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)
AdlibRegister("_Imagen", 100)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func _Imagen()
    Local $aCInfo = GUIGetCursorInfo($g_hForm)
    If $aCInfo[4] = $g_iCInfo Then Return
    Switch $aCInfo[4]
        Case $g_idCheckbox1
            GUICtrlSetData($g_idEdit, StringFormat("EDIT1\111111111"))
            GUICtrlSetImage($g_idPic, @ScriptDir & "\1.bmp")
            GUICtrlSetColor($g_idCheckbox2, 0x000000)
            GUICtrlSetColor($g_idCheckbox3, 0x000000)
            GUICtrlSetColor($g_idCheckbox4, 0x000000)
            GUICtrlSetColor($g_idCheckbox5, 0x000000)
            GUICtrlSetColor($g_idCheckbox1, 0x00FF00)
        Case $g_idCheckbox2
            GUICtrlSetImage($g_idPic, @ScriptDir & "\2.bmp")
            GUICtrlSetData($g_idEdit, StringFormat("EDIT1\2222222"))
            GUICtrlSetColor($g_idCheckbox3, 0x000000)
            GUICtrlSetColor($g_idCheckbox4, 0x000000)
            GUICtrlSetColor($g_idCheckbox5, 0x000000)
            GUICtrlSetColor($g_idCheckbox1, 0x000000)
            GUICtrlSetColor($g_idCheckbox2, 0x00FF00)
        Case $g_idCheckbox3
            GUICtrlSetImage($g_idPic, @ScriptDir & "\3.bmp")
            GUICtrlSetData($g_idEdit, StringFormat("EDIT1\33333333"))
            GUICtrlSetColor($g_idCheckbox2, 0x000000)
            GUICtrlSetColor($g_idCheckbox4, 0x000000)
            GUICtrlSetColor($g_idCheckbox5, 0x000000)
            GUICtrlSetColor($g_idCheckbox1, 0x000000)
            GUICtrlSetColor($g_idCheckbox3, 0x00FF00)
        Case $g_idCheckbox4
            GUICtrlSetImage($g_idPic, @ScriptDir & "\4.jpg")
            GUICtrlSetData($g_idEdit, StringFormat("EDIT1\4444444"))
            GUICtrlSetColor($g_idCheckbox3, 0x000000)
            GUICtrlSetColor($g_idCheckbox2, 0x000000)
            GUICtrlSetColor($g_idCheckbox5, 0x000000)
            GUICtrlSetColor($g_idCheckbox1, 0x000000)
            GUICtrlSetColor($g_idCheckbox4, 0x00FF00)
        Case $g_idCheckbox5
            GUICtrlSetImage($g_idPic, @ScriptDir & "\5.jpg")
            GUICtrlSetData($g_idEdit, StringFormat("EDIT1\555555555"))
            GUICtrlSetColor($g_idCheckbox3, 0x000000)
            GUICtrlSetColor($g_idCheckbox2, 0x000000)
            GUICtrlSetColor($g_idCheckbox4, 0x000000)
            GUICtrlSetColor($g_idCheckbox1, 0x000000)
            GUICtrlSetColor($g_idCheckbox5, 0x00FF00)
    EndSwitch
    $g_iCInfo = $aCInfo[4]
    Return
  EndFunc

 

Edited by Subz
Link to comment
Share on other sites

The code was not working for me. Setting color to checkbox the way you have done it was not working.  It's the way I have setup my general window theme.  Anyway, I ended up rewriting the code (if you are interested) :

#include <GUIConstants.au3>
#include <Constants.au3>
#include <String.au3>
#include <WinAPITheme.au3>

Global $g_hForm = GUICreate("Form1", 615, 437, 192, 124)
GUISetBkColor(0x7a7a7a)
Global $g_idCheckbox[8]
For $i = 0 To UBound($g_idCheckbox) - 1
  $g_idCheckbox[$i] = GUICtrlCreateCheckbox("Checkbox" & $i + 1, 40, 56 + $i * 24, 97, 13)
  _WinAPI_SetWindowTheme (GUICtrlGetHandle($g_idCheckbox[$i]), "0", "0")
Next
Global $g_idPic = GUICtrlCreatePic(@ScriptDir & "\0.jpg", 360, 64, 217, 249)
Global $g_idEdit = GUICtrlCreateEdit("", 160, 64, 140, 100, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY), 0)
GUICtrlSetData(-1, StringFormat("EDIT1\r\nASDFASDASDSADSAAS\r\nSADASDAS\r\nASDSADSA"))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)
Local $aCInfo, $g_iCInfo = 0
While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
  $aCInfo = GUIGetCursorInfo($g_hForm)
  If $aCInfo[4] <> $g_iCInfo And $aCInfo[4] >= $g_idCheckbox[0] And $aCInfo[4] <= $g_idCheckbox[UBound($g_idCheckbox)-1] Then
    _Imagen($aCInfo[4], $g_idCheckbox)
    $g_iCInfo = $aCInfo[4]
  EndIf
WEnd

Func _Imagen($iId, ByRef $aId)
  ConsoleWrite ($iId & @CRLF)
  Local $iNum = $iId - $aId[0] + 1
  GUICtrlSetData($g_idEdit, StringFormat("EDIT1\") & _StringRepeat($iNum, 8))
  GUICtrlSetImage($g_idPic, @ScriptDir & "\" & $iNum & ".bmp")
  For $i = 0 To UBound($aId) - 1
    GUICtrlSetColor($aId[$i], ($aId[$i] = $iId ? 0x00FF00 : 0x000000))
  Next
EndFunc   ;==>_Imagen

I still do not understand your stringFormat thing tho :ermm:

Edited by Nine
Link to comment
Share on other sites

19 hours ago, Subz said:

Just use AdLibRegister after GuiSetState and remove calling _Imagen from the loop, I would also recommend checking to see if the $aCInfo[4] has changed, basic example:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <EditConstants.au3>
#include <GUIConstants.au3>

Global $g_iCInfo = Null

DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1)

Global $g_hForm = GUICreate("Form1", 615, 437, 192, 124)
    GUISetBkColor(0x7a7a7a)
    Global $g_idCheckbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 56, 97, 13)
    Global $g_idCheckbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 80, 97, 13)
    Global $g_idCheckbox3 = GUICtrlCreateCheckbox("Checkbox3", 40, 104, 97, 13)
    Global $g_idCheckbox4 = GUICtrlCreateCheckbox("Checkbox4", 40, 128, 97, 13)
    Global $g_idCheckbox5 = GUICtrlCreateCheckbox("Checkbox5", 40, 152, 97, 13)
    Global $g_idCheckbox6 = GUICtrlCreateCheckbox("Checkbox6", 40, 176, 97, 33)
    Global $g_idCheckbox7 = GUICtrlCreateCheckbox("Checkbox7", 40, 200, 97, 33)
    Global $g_idCheckbox8 = GUICtrlCreateCheckbox("Checkbox8", 40, 224, 97, 33)
    Global $g_idPic = GUICtrlCreatePic(@ScriptDir & "\0.jpg", 360, 64, 217, 249)
    Global $g_idEdit = GUICtrlCreateEdit("", 160, 64, 140, 100, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY), 0)
        GUICtrlSetData(-1, StringFormat("EDIT1\r\nASDFASDASDSADSAAS\r\nSADASDAS\r\nASDSADSA"))
        GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
        GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)
AdlibRegister("_Imagen", 100)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func _Imagen()
    Local $aCInfo = GUIGetCursorInfo($g_hForm)
    If $aCInfo[4] = $g_iCInfo Then Return
    Switch $aCInfo[4]
        Case $g_idCheckbox1
            GUICtrlSetData($g_idEdit, StringFormat("EDIT1\111111111"))
            GUICtrlSetImage($g_idPic, @ScriptDir & "\1.bmp")
            GUICtrlSetColor($g_idCheckbox2, 0x000000)
            GUICtrlSetColor($g_idCheckbox3, 0x000000)
            GUICtrlSetColor($g_idCheckbox4, 0x000000)
            GUICtrlSetColor($g_idCheckbox5, 0x000000)
            GUICtrlSetColor($g_idCheckbox1, 0x00FF00)
        Case $g_idCheckbox2
            GUICtrlSetImage($g_idPic, @ScriptDir & "\2.bmp")
            GUICtrlSetData($g_idEdit, StringFormat("EDIT1\2222222"))
            GUICtrlSetColor($g_idCheckbox3, 0x000000)
            GUICtrlSetColor($g_idCheckbox4, 0x000000)
            GUICtrlSetColor($g_idCheckbox5, 0x000000)
            GUICtrlSetColor($g_idCheckbox1, 0x000000)
            GUICtrlSetColor($g_idCheckbox2, 0x00FF00)
        Case $g_idCheckbox3
            GUICtrlSetImage($g_idPic, @ScriptDir & "\3.bmp")
            GUICtrlSetData($g_idEdit, StringFormat("EDIT1\33333333"))
            GUICtrlSetColor($g_idCheckbox2, 0x000000)
            GUICtrlSetColor($g_idCheckbox4, 0x000000)
            GUICtrlSetColor($g_idCheckbox5, 0x000000)
            GUICtrlSetColor($g_idCheckbox1, 0x000000)
            GUICtrlSetColor($g_idCheckbox3, 0x00FF00)
        Case $g_idCheckbox4
            GUICtrlSetImage($g_idPic, @ScriptDir & "\4.jpg")
            GUICtrlSetData($g_idEdit, StringFormat("EDIT1\4444444"))
            GUICtrlSetColor($g_idCheckbox3, 0x000000)
            GUICtrlSetColor($g_idCheckbox2, 0x000000)
            GUICtrlSetColor($g_idCheckbox5, 0x000000)
            GUICtrlSetColor($g_idCheckbox1, 0x000000)
            GUICtrlSetColor($g_idCheckbox4, 0x00FF00)
        Case $g_idCheckbox5
            GUICtrlSetImage($g_idPic, @ScriptDir & "\5.jpg")
            GUICtrlSetData($g_idEdit, StringFormat("EDIT1\555555555"))
            GUICtrlSetColor($g_idCheckbox3, 0x000000)
            GUICtrlSetColor($g_idCheckbox2, 0x000000)
            GUICtrlSetColor($g_idCheckbox4, 0x000000)
            GUICtrlSetColor($g_idCheckbox1, 0x000000)
            GUICtrlSetColor($g_idCheckbox5, 0x00FF00)
    EndSwitch
    $g_iCInfo = $aCInfo[4]
    Return
  EndFunc

thanks is what i was looking for

 

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...