Jump to content

Slow Checkbox when activated elsewhere


Recommended Posts

Hi everyone,

I'm trying to make a check box which uses white text insted of the standard black, now as far as i know, that cannot be done directly. So i've made a check box with no text, and then white text next to it, and when i click the text i want it to check the checkbox, just like you'd normaly expect from text next to a check box. My problem is that it's slow, you cannot click it and then unclick it with in the same second.

Can anyone help me out here? any help would be appreciated?

#include

GUICreate("GUI",300,200)
GUISetBkColor(0x333333)

$Checkbox = GUICtrlCreateCheckbox("", 8, 49, 15, 15)
$Checktext = GUICtrlCreateLabel("Click the text", 27, 48, 130, 20, 0)
GUICtrlSetFont($Checktext, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Checktext, 0xFFFFFF)

GuiSetState()


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Checktext
_CheckUncheck($Checkbox)
EndSwitch
WEnd

Func _CheckUncheck($Thingtocheckuncheck)
If GUICtrlRead($Thingtocheckuncheck) = $GUI_CHECKED Then
GUICtrlSetState($Thingtocheckuncheck, $GUI_UNCHECKED)
ElseIf GUICtrlRead($Thingtocheckuncheck) = $GUI_UNCHECKED then
GUICtrlSetState($Thingtocheckuncheck, $GUI_CHECKED)
endif
EndFunc
Link to comment
Share on other sites

I tried to see if I can get it more faster using $SS_NOTIFY messages but seems to be the same speed. Anyway you function _CheckUncheck() can be write very simple:

ControlClick($hGUI,"",$Checkbox)

LE: if just the color is the reason of creating a label instead of full checkbox then check out here how to set white color of checkbox

#include <GuiConstantsEx.au3>

$hMain = GUICreate("GUI",300,200)
GUISetBkColor(0x333333)

$Checkbox = GUICtrlCreateCheckbox("Click the text", 8, 49, 150, 15)
DllCall("UxTheme.dll","int","SetWindowTheme","hwnd",GUICtrlGetHandle($Checkbox),"wstr",0,"wstr",0)
GUICtrlSetFont($Checkbox, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Checkbox, 0xFFFFFF)
GuiSetState()


While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Thanks Andreik,

The controlclick is a much nicer thing to look at in my script indeed, how ever your changing of the colour on it... mm i don't like because it makes the text flicker when you click it? also as i don't know what that dll holds i'm unsure if it will let me use it in Xp, 7 and 8? (yes, i need it to work in all 3)

Link to comment
Share on other sites

Add this line to your script after the checkbox creation line DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $iControl, "wstr", 0, "wstr", 0) and you can then set the color of it to whatever you want.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I'm trying to make a check box which uses white text insted of the standard black, now as far as i know, that cannot be done directly. So i've made a check box with no text, and then white text next to it, and when i click the text i want it to check the checkbox, just like you'd normaly expect from text next to a check box. My problem is that it's slow, you cannot click it and then unclick it with in the same second.

Remove the CS_DBLCLKS style from the Static class control (Label), now the double click lag is removed.

Alternately the checkbox text can be coloured by customdrawing,

but a workaround of extra code is required for XP support because of a bug in button customdrawing that was fixed in Vista and up.

#include <WinAPIEx.au3>
#include <GUIConstantsEx.au3>

GUICreate("GUI", 300, 200)
GUISetBkColor(0x333333)
$Checkbox = GUICtrlCreateCheckbox("", 8, 49, 15, 15)
$Checktext = GUICtrlCreateLabel("Click the text", 27, 48, 130, 20, 0)
_Remove_CS_DBLCLKS(-1) ;removes style for all subsequently created static controls, no need to remove ss_notify style
GUICtrlSetFont($Checktext, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Checktext, 0xFFFFFF)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checktext
            _CheckUncheck($Checkbox)
    EndSwitch
WEnd

Func _CheckUncheck($Thingtocheckuncheck)
    If GUICtrlRead($Thingtocheckuncheck) = $GUI_CHECKED Then
        GUICtrlSetState($Thingtocheckuncheck, $GUI_UNCHECKED)
    ElseIf GUICtrlRead($Thingtocheckuncheck) = $GUI_UNCHECKED Then
        GUICtrlSetState($Thingtocheckuncheck, $GUI_CHECKED)
    EndIf
EndFunc   ;==>_CheckUncheck


Func _Remove_CS_DBLCLKS($Ctrl)
    ;Author; rover 2k9 - updated 2k12
    ;Requires WinAPIEx.au3
    ;
    ;Removes the CS_DBLCLKS style from Static or Button class controls
    ;Fixes the issue of slow response(lag) with Labels or colour Buttons when rapidly clicking with the mouse
    ;
    ;NOTE: Run one time only on the first control created in your script process with the control class you want to remove this style from
    ;All subsequently created controls of the Static or Button class for the current process will not have the CS_DBLCLKS style
    ;http://www.autoitscript.com/forum/topic/90309-why-the-huge-performance-hit/page__view__findpost__p__663443
    If Not IsHWnd($Ctrl) Then
        $Ctrl = GUICtrlGetHandle($Ctrl)
        If Not IsHWnd($Ctrl) Then Return SetError(1, 0, 0)
    EndIf
    If Not IsDeclared("GCL_STYLE") Then Local Const $GCL_STYLE = -26
    If Not IsDeclared("CS_DBLCLKS") Then Local Const $CS_DBLCLKS = 0x8
    Local $ClassStyle = _WinAPI_GetClassLongEx($Ctrl, $GCL_STYLE)
    If @error Or Not $ClassStyle Then Return SetError(2, @error, 0)
    Local $NewStyle = BitAND($ClassStyle, BitNOT($CS_DBLCLKS))
    _WinAPI_SetClassLongEx($Ctrl, $GCL_STYLE, $NewStyle)
    If @error Then Return SetError(3, @error, 0)
    Local $ClassChk = _WinAPI_GetClassLongEx($Ctrl, $GCL_STYLE)
    If @error Or Not $ClassChk Then Return SetError(4, @error, 0)
    If $ClassStyle = $ClassChk Then Return SetError(5, 0, 0)
    Return SetError(0, 0, 1)
EndFunc   ;==>_Remove_CS_DBLCLKS
Edited by rover

I see fascists...

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