Jump to content

Icon corruption when disabling a button


TheDcoder
 Share

Recommended Posts

Hello :bye:,

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 259, 91, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 88, 32, 75, 25)
GUICtrlSetImage($Button1, @ScriptDir & '\grass_arrow.ico')
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

AdlibRegister("DisableAndEnable", 4000)

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

    EndSwitch
WEnd

Func DisableAndEnable()
    GUICtrlSetState($Button1, $GUI_DISABLE)
    Sleep(2000)
    GUICtrlSetState($Button1, $GUI_ENABLE)
EndFunc

050a0d731333a25c35ddeebc950aa539.gif

Did you see the icon getting messed up? Does anybody here know how to avoid it? :think:

 

Thanks in Advance, TD :D

 grass_arrow.ico

Edited by TheDcoder
Added Screenshot

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

No idea what exactly you're asking here.

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

  • Moderators

@TheDcoder you have been around long enough to know better than to make such a post. If you're having a problem, explain in detail what you're trying to do, and share the code, rather than giving some lame vague issue and expecting people to play 20 questions with you.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Could you post the ICO file as well? Also, I doubt this has anything to do with button coloring as you're not coloring the button.

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

@Zedna The icon looks messed up in the 2nd screenshot, I guess Aero is enabled in that screenshot?

Added a GIF on main post, TD :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

  • Moderators

@TheDcoder can you elaborate on "looks messed up"? On my screen, other than being grayed out, Zedna's icon looks fine.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Really? Nobody see the disappearing pixels?

@TheDcoder

The pixels with alpha in them goes fully transparent when the button is disabled. I don't know why so I can't suggest a fix other than removing them. Like so:

grass_arrow2.ico

Or create your own custom button...

Edited by AdmiralAlkex
Link to comment
Share on other sites

Really? Nobody see the disappearing pixels?

Glad you spotted it :)... I will do some research and report back with a solution (if exists :P)

 

Thanks! TD :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

@AdmiralAlkex I searched around a little and your solution seems to be the best... How did you remove them anyway? :P

Just tried a online png to ico converter and it worked! :D

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

It's much easier than you think. This is the example for _GUICtrlButton_Create in the help file. One line modified. Two lines added:

#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $g_idBtn, $g_idRdo, $g_idChk, $g_idMemo

; Note the controlID from these buttons can NOT be read with GUICtrlRead

Example()

Func Example()
  Local $hGUI

  $hGUI = GUICreate("Buttons", 400, 400)
  $g_idMemo = GUICtrlCreateEdit("", 119, 10, 276, 374, $WS_VSCROLL)
  GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")

  $g_idBtn = _GUICtrlButton_Create($hGUI, "Button1", 10, 10, 90, 50, $BS_ICON) ; <<<< Added $BS_ICON style
  _GUICtrlButton_SetImage( $g_idBtn, "grass_arrow.ico" )                       ; <<<< Added
  _GUICtrlButton_Enable( $g_idBtn, False )                                     ; <<<< Added

  $g_idRdo = _GUICtrlButton_Create($hGUI, "Radio1", 10, 60, 90, 50, $BS_AUTORADIOBUTTON)

  $g_idChk = _GUICtrlButton_Create($hGUI, "Check1", 10, 120, 90, 50, $BS_AUTO3STATE)

  GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
  GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

  GUISetState(@SW_SHOW)

  MemoWrite("$g_idBtn handle: " & $g_idBtn)
  MemoWrite("$g_idRdo handle: " & $g_idRdo)
  MemoWrite("$g_idChk handle: " & $g_idChk & @CRLF)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd

  Exit
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
  GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg, $wParam
  Local Const $BCN_HOTITEMCHANGE = -1249
  Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam)
  Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code")
  Local $nID = DllStructGetData($tNMBHOTITEM, "IDFrom")
  Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom")
  Local $iFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")
  Local $sText = ""

  Switch $nNotifyCode
    Case $BCN_HOTITEMCHANGE ; Win XP and Above
      If BitAND($iFlags, 0x10) = 0x10 Then
        $sText = "$BCN_HOTITEMCHANGE - Entering: " & @CRLF

      ElseIf BitAND($iFlags, 0x20) = 0x20 Then
        $sText = "$BCN_HOTITEMCHANGE - Leaving: " & @CRLF
      EndIf
      MemoWrite($sText & _
          "-----------------------------" & @CRLF & _
          "WM_NOTIFY - Infos:" & @CRLF & _
          "-----------------------------" & @CRLF & _
          "Code" & @TAB & ":" & $nNotifyCode & @CRLF & _
          "CtrlID" & @TAB & ":" & $nID & @CRLF & _
          "CtrlHWnd:" & $hCtrl & @CRLF & _
          _GUICtrlButton_GetText($hCtrl) & @CRLF)
  EndSwitch
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

; React on a button click
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg
  Local $nNotifyCode = BitShift($wParam, 16)
  Local $nID = BitAND($wParam, 0x0000FFFF)
  Local $hCtrl = $lParam
  Local $sText = ""

  Switch $hCtrl
    Case $g_idBtn, $g_idRdo, $g_idChk
      Switch $nNotifyCode
        Case $BN_CLICKED
          $sText = "$BN_CLICKED" & @CRLF
        Case $BN_PAINT
          $sText = "$BN_PAINT" & @CRLF
        Case $BN_PUSHED, $BN_HILITE
          $sText = "$BN_PUSHED, $BN_HILITE" & @CRLF
        Case $BN_UNPUSHED, $BN_UNHILITE
          $sText = "$BN_UNPUSHED" & @CRLF
        Case $BN_DISABLE
          $sText = "$BN_DISABLE" & @CRLF
        Case $BN_DBLCLK, $BN_DOUBLECLICKED
          $sText = "$BN_DBLCLK, $BN_DOUBLECLICKED" & @CRLF
        Case $BN_SETFOCUS
          $sText = "$BN_SETFOCUS" & @CRLF
        Case $BN_KILLFOCUS
          $sText = "$BN_KILLFOCUS" & @CRLF
      EndSwitch
      MemoWrite($sText & _
          "-----------------------------" & @CRLF & _
          "WM_COMMAND - Infos:" & @CRLF & _
          "-----------------------------" & @CRLF & _
          "Code" & @TAB & ":" & $nNotifyCode & @CRLF & _
          "CtrlID" & @TAB & ":" & $nID & @CRLF & _
          "CtrlHWnd:" & $hCtrl & @CRLF & _
          _GUICtrlButton_GetText($hCtrl) & @CRLF)
      Return 0 ; Only workout clicking on the button
  EndSwitch
  ; Proceed the default AutoIt3 internal message commands.
  ; You also can complete let the line out.
  ; !!! But only 'Return' (without any value) will not proceed
  ; the default AutoIt3-message in the future !!!
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

Link to comment
Share on other sites

@LarsJ :o, Looks complicated... I still think @AdmiralAlkex's 1st solution is better for me... I want average users to understand my code :sweating:

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

I can't see your pictures but i'll guess that it doesn't look good. When I tested, it looked like the picture posted by Zedna. Since the icons looks bad in both examples (your example in first post and my example), I don't think we can blaime internal AutoIt code for the problem.

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