Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Need advice re toggling on-screen button

$
0
0

I want to use AutoIt to display a frameless, chrome-less, ~200px square image (jpg, bmp, png - doesn't matter to me) at a specific location on the screen. When the user clicks on it the image is replaced by another of the same size, position, etc. It's like a two-state button. Once I get this part working I'll add an action that results from clicking on the button.

 

I've adapted some example code to this task but I wonder if there's a better approach. I'm also seeing single-pixel black artifacts in the button images.  Note that the bmp images I'm using are 200px by 195px, and the code is supposed to show them at that size. The original bmp's are perfect -- no artifacts, so the black pixels are being introduced by my AutoIt script. Maybe I'm using the wrong bmp format but I've used bmp's from Photoshop before, without probs.

 

Here's a screen shot example of the tiny black pixels that are introduced in white areas of the image.  Any idea why this is happening?

 

artifactexample.png

 

 

And here's the code.

AutoIt         
  1. #include <GUIConstantsEx.au3>
  2. #include <StaticConstants.au3>
  3. #include <WindowsConstants.au3>
  4. #include <Misc.au3>
  5. #include <SendMessage.au3>
  6.  
  7. AutoItSetOption ("TrayIconDebug", 1);0-off
  8.  
  9. Opt("WinTitleMatchMode", 1)
  10.  
  11. HotKeySet("{ESC}", "Terminate") ;ESC to bail out
  12.  
  13.  
  14. ;Create a form 10px larger than the button I'm going to display
  15. $Form1 = GUICreate("Test", 205, 205, 516, 25, BitOR($WS_SYSMENU,$WS_POPUP), 0)
  16.  
  17. ;Use a blank gray image that's the same size as the above form
  18. $Pic1 = GUICtrlCreatePic("mutebg.jpg", 0, 0, 205, 205)
  19.  
  20. GuiCtrlSetState(-1,$GUI_DISABLE)
  21.  
  22. ;The initial "button" I want to show
  23. $PicMute = GUICtrlCreatePic("Mic-Off.bmp", 0, 0, 200, 195)
  24. $MuteState = "mic_off"
  25.  
  26.  
  27. ;Wait for user to click on my "button" image.
  28.     $nMsg = GUIGetMsg()
  29.     Switch $nMsg
  30.         Case $GUI_EVENT_CLOSE
  31.             Exit
  32.  
  33.         Case $PicMute
  34.             Call("Mute")
  35.     EndSwitch
  36.  
  37.  
  38. ;When the user clicks on the "button this routine toggles between button states and will eventually execute some additional code if $playState="mic_on"
  39. Func Mute()
  40.    if $MuteState="mic_off" Then
  41.         $MuteState="mic_on"
  42.         GUICtrlSetImage($PicMute,"Mic-On.bmp")
  43.         ;unmute code
  44.     Else
  45.         $MuteState="mic_off"
  46.         GUICtrlSetImage($PicMute,"Mic-Off.bmp")
  47.         ;mute code
  48.     EndIf
  49.  
  50.  
  51.  
  52. Func Terminate() ;process ESC key
  53.     Exit 0

Thank you.

 

 


Viewing all articles
Browse latest Browse all 12506

Trending Articles