Jump to content

Recommended Posts

Posted (edited)

Hi

I have these two functions the one works and the other doesn't and do not understand why.

Basically if $Trans = 255 or higher then don't increase by 5.

Thanks for the help!

If Not $Trans <= 0 Then ; Works
$Trans -= 5
ToolTip($Trans)
WinSetTrans($GUI, "", $Trans)
EndIf
If Not $Trans >= 255 Then ; Does not work.
$Trans += 5
ToolTip($Trans)
WinSetTrans($GUI, "", $Trans)
EndIf
Edited by SkellySoul
Posted (edited)

Is the ceiling 255 though? Because technically what you're saying you want to do is if it's 254, still increase by 5... which makes it 259.

EDIT:

Also, are these 2 running synonymous? Because both directives will be true if it's in the range of -4 thru 254 and it will subtract 5 then add 5 back.

Edited by Mechaflash
  Reveal hidden contents

 

Posted

Why do not write it the other way round?

If $Trans > 0 Then
    $Trans -= 5
    ToolTip($Trans)
    WinSetTrans($GUI, "", $Trans)
EndIf

If $Trans < 255 Then
    $Trans += 5
    ToolTip($Trans)
    WinSetTrans($GUI, "", $Trans)
EndIf

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

This is more of the code.

Func _Trans()
If IsHWnd($GUI) Then
Local $Key = ""
MsgBox(0 , "", $Trans)
ConsoleWrite(@HotKeyPressed)
    Switch @HotKeyPressed
Case "{PGUP}"
If Not $Trans >= 255 Then
$Trans += 5
ToolTip($Trans)
WinSetTrans($GUI, "", $Trans)
EndIf
        Case "{PGDN}"
If Not $Trans <= 0 Then
$Trans -= 5
ToolTip($Trans)
WinSetTrans($GUI, "", $Trans)
EndIf
EndSwitch
EndIf
EndFunc
 
 
 
Full Source
 
#cs ----------------------------------------------------------------------------
 
 AutoIt Version: 3.3.11.2 (Beta)
 Author:         myName
 
 Script Function:
Template AutoIt script.
 
#ce ----------------------------------------------------------------------------
 
; Script Start - Add your code below here
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
Global $GUI, $Trans
 
HotKeySet("{Home}", "_Window")
HotKeySet("{End}" , "_Exit")
HotKeySet("{PGUP}" , "_Trans")
HotKeySet("{PGDN}" , "_Trans")
 
$Trans = 100
 
While 1
Sleep(1000)
WEnd
 
Func _Window()
GUIDelete($GUI)
;Fix up Errors
$Pos = WinGetPos("[ACTIVE]")
$Handle = WinGetHandle("[ACTIVE]")
If @Error = 1 Then
MsgBox(16, "Error", "No Window Found!")
Exit
Else
$GUI = GUICreate("", $Pos[2], $Pos[3], $Pos[0], $Pos[1], $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
GUISetBkColor(0x000000)
GUISetState(@SW_HIDE)
WinSetTrans($GUI, "", $Trans)
GUISetState(@SW_SHOW)
 
;WinGetState
 
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
EndIf
EndFunc
 
Func _Trans()
If IsHWnd($GUI) Then
Local $Key = ""
ConsoleWrite(@HotKeyPressed)
    Switch @HotKeyPressed
Case "{PGUP}"
If Not $Trans >= 255 Then
$Trans += 5
ToolTip($Trans)
WinSetTrans($GUI, "", $Trans)
EndIf
        Case "{PGDN}"
If Not $Trans <= 0 Then
$Trans -= 5
ToolTip($Trans)
WinSetTrans($GUI, "", $Trans)
EndIf
EndSwitch
EndIf
EndFunc
 
Func _Exit()
GUIDelete($GUI)
Exit
EndFunc
Edited by SkellySoul
Posted (edited)

EDIT: Checked the WinSetTrans() and it only accepts a range of 0 - 255. Changed the two if statements to reflect this properly.

Func _Trans()
If IsHWnd($GUI) Then
  Local $Key = ""
  MsgBox(0 , "", $Trans)
  ConsoleWrite(@HotKeyPressed)
    Switch @HotKeyPressed
      Case "{PGUP}"
        If ($Trans + 5) <= 255 Then
          $Trans += 5
          ToolTip($Trans)
          WinSetTrans($GUI, "", $Trans)
        EndIf
      Case "{PGDN}"
        If ($Trans - 5) >= 0 Then
          $Trans -= 5
          ToolTip($Trans)
          WinSetTrans($GUI, "", $Trans)
        EndIf
      EndSwitch
EndIf
EndFunc
Edited by Mechaflash
  Reveal hidden contents

 

Posted (edited)

opps..I had them backwards  :mellow:

Thanks very much for the help :)

[Edited]

I guess also using "Not" wasn't very wise either heh  :sweating:

Edited by SkellySoul

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...