Sign in to follow this  
Followers 0
Revolter

Exit not working

3 posts in this topic

#1 ·  Posted (edited)

I have this small script:

#include <ButtonConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <NoFocusLines.au3>
#include <ScreenCapture.au3>
#include <SliderConstants.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt( "GUIOnEventMode" , 1 )
HotKeySet( "{UP}" , "_Up" )
HotKeySet( "{DOWN}" , "_Down" )
HotKeySet( "{LEFT}" , "_Left" )
HotKeySet( "{RIGHT}" , "_Right" )
Global $x = MouseGetPos( 0 ) , $y = MouseGetPos( 1 ) , $pos , $win_pos , $msg , $split , $old_x , $old_y , $zoom = 8 , $color = "F0F0F0" , $pause = False , $dll[ 2 ]
$dll[ 0 ] = DllOpen( "user32.dll" )
$dll[ 1 ] = DllOpen( "gdi32.dll" )
$gui = GUICreate( "Cursor Info" , 285 , 390 , @DesktopWidth - 297 , 6 , Default , $WS_EX_TOPMOST )
$paused = GUICtrlCreateLabel( "Paused: " & $pause , 10 , 10 , 200 , 15 )
$cursor_position = GUICtrlCreateLabel( $x & " : " & $y , 10 , 30 , 60 , 15 )
$cursor_position_x = GUICtrlCreateButton( "Copy X co-ordinate" , 70 , 26 , 100 , 20 )
  GUICtrlSetOnEvent( $cursor_position_x , "_Cursor_Position_X" )
$cursor_position_y = GUICtrlCreateButton( "Copy Y co-ordinate" , 175 , 26 , 100 , 20 )
  GUICtrlSetOnEvent( $cursor_position_y , "_Cursor_Position_Y" )
$cursor_area = GUICtrlCreateLabel( "0 : 0" , 10 , 50 , 60 , 15 )
$cursor_area_x = GUICtrlCreateButton( "Copy X co-ordinate" , 70 , 46 , 100 , 20 )
  GUICtrlSetOnEvent( $cursor_area_x , "_Cursor_Area_X" )
$cursor_area_y = GUICtrlCreateButton( "Copy Y co-ordinate" , 175 , 46 , 100 , 20 )
  GUICtrlSetOnEvent( $cursor_area_y , "_Cursor_Area_Y" )
$cursor_color = GUICtrlCreateLabel( "" , 10 , 70 , 60 , 15 )
$cursor_color_example = GUICtrlCreateLabel( "" , 70 , 70 , 100 , 15 )
$cursor_color_copy = GUICtrlCreateButton( "Copy color value" , 175 , 66 , 100 , 20 )
  GUICtrlSetOnEvent( $cursor_color_copy , "_Cursor_Color_Copy" )
$zoom_level = GUICtrlCreateSlider( 3 , 90 , 175 , 20 , $TBS_NOTICKS )
_NoFocusLines_Set( $zoom_level )
GUICtrlSetLimit( $zoom_level , 15 , 1 )
GUICtrlSetData( $zoom_level , 16 - $zoom )
$zoom_label = GUICtrlCreateLabel( "Zoom level: " & GUICtrlRead( $zoom_level ) , 180 , 92 , 70 , 15 )
$magnifier = GUICreate( "" , 264 , 264 , @DesktopWidth - 285 , 145 , $WS_POPUP + $WS_BORDER , Default , $gui )
GUIRegisterMsg( $WM_HSCROLL , "_Zoom" )
GUIRegisterMsg( $WM_MOVE , "_Drag" )
;~ GUISetOnEvent( $GUI_EVENT_CLOSE , "_Esc" , $magnifier )
GUISetOnEvent( $GUI_EVENT_CLOSE , "_Esc" , $gui )
GUISetState( @SW_SHOW , $gui )
GUISetState( @SW_SHOW , $magnifier )
While 1
$pos = MouseGetPos()
If Not $pause Then
  $old_x = $pos[ 0 ]
  $old_y = $pos[ 1 ]
  _Update()
EndIf
If _IsPressed( "02" , $dll[ 0 ] ) Then
  While _IsPressed( "02" , $dll[ 0 ] )
   Sleep( 100 )
  WEnd
  $pause = Not $pause
  GUICtrlSetData( $paused , "Paused: " & $pause )
EndIf
If $pos[ 0 ] <> $x OR $pos[ 1 ] <> $y Then
  If Not WinActive( $gui ) Then WinActivate( $gui )
  GUICtrlSetState( $zoom_level , $GUI_FOCUS )
  $x = $pos[ 0 ]
  $y = $pos[ 1 ]
  If Not $pause Then
   GUICtrlSetData( $cursor_position , $x & " : " & $y )
   If StringRight( Hex( PixelGetColor( $x , $y ) ) , 6 ) <> "0x" & $color Then
    $color = "0x" & StringRight( Hex( PixelGetColor( $x , $y ) ) , 6 )
    GUICtrlSetData( $cursor_color , $color )
    GUICtrlSetBkColor( $cursor_color_example , $color )
   EndIf
  EndIf
EndIf
If Not $pause And _IsPressed( "01" , $dll[ 0 ] ) Then
  $x_1 = MouseGetPos( 0 )
  $y_1 = MouseGetPos( 1 )
  While _IsPressed( "01" , $dll[ 0 ] )
   If _IsPressed( "02" , $dll[ 0 ] ) Then
    While _IsPressed( "02" , $dll[ 0 ] )
     Sleep( 100 )
    WEnd
    $pause = Not $pause
    GUICtrlSetData( $paused , "Paused: " & $pause )
   EndIf
   If MouseGetPos( 0 ) <> $x OR MouseGetPos(  1 ) <> $y Then
    $x = MouseGetPos( 0 )
    $y = MouseGetPos( 1 )
    GUICtrlSetData( $cursor_position , $x & " : " & $y )
    If StringRight( Hex( PixelGetColor( $x , $y ) ) , 6 ) <> "0x" & $color Then
     $color = "0x" & StringRight( Hex( PixelGetColor( $x , $y ) ) , 6 )
     GUICtrlSetData( $cursor_color , $color )
     GUICtrlSetBkColor( $cursor_color_example , $color )
    EndIf
   EndIf
   If MouseGetPos( 0 ) <> $x_1 OR MouseGetPos( 1 ) <> $y_1 Then
    $old_x = MouseGetPos( 0 )
    $old_y = MouseGetPos( 1 )
    _Update()
    $x_1 = $pos[ 0 ]
    $y_1 = $pos[ 1 ]

    GUICtrlSetData( $cursor_area , Abs( $x_1 - $old_x ) & " : " &  Abs( $y_1 - $old_y ) )
    GUICtrlSetData( $cursor_position , $x_1 & " : " & $y_1 )
   EndIf
  WEnd
EndIf
Sleep( 10 )
WEnd
Func _Up()
MouseMove( MouseGetPos( 0 ) , MouseGetPos( 1 ) - 1 , 0 )
EndFunc
Func _Down()
MouseMove( MouseGetPos( 0 ) , MouseGetPos( 1 ) + 1 , 0 )
EndFunc
Func _Left()
MouseMove( MouseGetPos( 0 ) - 1 , MouseGetPos( 1 ) , 0 )
EndFunc
Func _Right()
MouseMove( MouseGetPos( 0 ) + 1 , MouseGetPos( 1 ) , 0 )
EndFunc
Func _Cursor_Position_X()
$split = StringSplit( GUICtrlRead( $cursor_position ) , " : " , 1 )
ClipPut( $split[ 1 ] )
EndFunc
Func _Cursor_Position_Y()
$split = StringSplit( GUICtrlRead( $cursor_position ) , " : " , 1 )
ClipPut( $split[ 2 ] )
EndFunc
Func _Cursor_Area_X()
$split = StringSplit( GUICtrlRead( $cursor_area ) , " : " , 1 )
ClipPut( $split[ 1 ] )
EndFunc
Func _Cursor_Area_Y()
$split = StringSplit( GUICtrlRead( $cursor_area ) , " : " , 1 )
ClipPut( $split[ 2 ] )
EndFunc
Func _Cursor_Color_Copy()
$split = StringSplit( $color , "0x" , 1 )
ClipPut( $split[ 2 ] )
EndFunc
Func _Zoom( $hWnd , $iMsg , $wParam , $lParam )
    #forceref $hWnd, $iMsg, $wParam
If $lParam = GUICtrlGetHandle( $zoom_level ) Then
  $zoom = 16 - GUICtrlRead( $zoom_level )
        GUICtrlSetData( $zoom_label , "Zoom level: " & $zoom )
  _Update()
EndIf
    Return $GUI_RUNDEFMSG
EndFunc
Func _Drag( $hWnd , $iMsg , $wParam , $lParam )
$win_pos = WinGetPos( $gui )
WinMove( $magnifier , "" , $win_pos[ 0 ] + 12 , $win_pos[ 1 ] + 140 )
Return $GUI_RUNDEFMSG
EndFunc
Func _Update()
    $DeskHDC = DLLCall( $dll[ 0 ] , "int" , "GetDC" , "hwnd" , 0 )
    $GUIHDC = DLLCall( $dll[ 0 ] , "int" , "GetDC" , "hwnd" , $magnifier )
If Not @error Then
        DLLCall( $dll[ 1 ] , "int" , "StretchBlt" , "int" , $GUIHDC[ 0 ] , "int" , 0 , "int" , 0 , "int" , 264 , "int" , 264 , "int" , $DeskHDC[ 0 ] , _
   "int" , $old_x - 132 / $zoom / 2 + 1 , "int" , $old_y - 132 / $zoom / 2 + 1 , _
   "int" , 132 / $zoom , "int" , 132 / $zoom , "long", $SRCCOPY )
        DLLCall( $dll[ 0 ] , "int" , "ReleaseDC" , "int" , $DeskHDC[ 0 ] , "hwnd" , 0 )
        DLLCall( $dll[ 0 ] , "int" , "ReleaseDC" , "int" , $GUIHDC[ 0 ] , "hwnd" , $magnifier )
  $pen = DLLCall( $dll[ 1 ] , "hwnd" , "CreatePen" , "int" , 0 , "int" , 1 , "int" , 0x000000FF )
  DLLCall( $dll[ 1 ] ,"hwnd","SelectObject", "hwnd", $GUIHDC[ 0 ] , "hwnd", $pen[ 0 ] )
  DLLCall( $dll[ 1 ] , "int" , "MoveToEx" , "hwnd" , $GUIHDC[ 0 ] , "int" , 0 , "int" , 264 / 2 , "ptr" , 0 )
  DLLCall( $dll[ 1 ] , "int" , "LineTo" , "hwnd" , $GUIHDC[ 0 ] , "int" , 264 , "int" , 264 / 2 )
  DLLCall( $dll[ 1 ] , "int" , "MoveToEx" , "hwnd" , $GUIHDC[ 0 ] , "int" , 264 / 2 , "int" , 0 , "ptr" , 0 )
  DLLCall( $dll[ 1 ] , "int" , "LineTo" , "hwnd" , $GUIHDC[ 0 ] , "int" , 264 / 2 , "int" , 264 )
    EndIf
EndFunc
Func _Esc()
ConsoleWrite( "before dll" & @CRLF )
DllClose( $dll[ 0 ] )
DllClose( $dll[ 1 ] )
ConsoleWrite( "before delete" & @CRLF )
GUIDelete( $magnifier )
ConsoleWrite( "before exit" & @CRLF )
Exit
EndFunc

If i run it from scite when i click the x button it doesn't exits, it just deletes the gui window but the process remains opened and i need to "Stop Executing"

Why is that?

Edited by Revolter

[center]Sorry for my bad english. Trying my best :Dhttp://iulianonofrei.comhttp://www.last.fm/user/Revolt666 [/center]

Share this post


Link to post
Share on other sites



In such cases - TrayIconDebug is your friend.

You can see very easy where your script is stuck.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

That is a pretty cool script.

I think the problem is related to NoFocusLines.au3. I don't have that UDF so I commented out the two lines of codes that use it, and the script exited like it should.

A think I found a different bug in your script too. When I set the zoom level to 1 the GUI went crazy.

on my pc it works well at zoom level 1 ... can you send me a screenshot or explain with more details the bug please?

In such cases - TrayIconDebug is your friend.

You can see very easy where your script is stuck.

i have never used trayicondebug ... i most likely learn to use it ... thank you for the hint :)


[center]Sorry for my bad english. Trying my best :Dhttp://iulianonofrei.comhttp://www.last.fm/user/Revolt666 [/center]

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • IamKJ
      By IamKJ
      So I have a lot of different functions in the little program I'm making.  Most of them use the Do statement, such as finding images, clicking buttons, etc.
       
      The question I have is how would I be able to both
      1) Create a hotkey to pause whatever I am doing at the moment.  If I have to put something into every function in the program, I don't mind.
      2) Create a hotkey to exit whatever I am doing and stop all loops or commands and bring back the main GUI?
    • ur
      By ur
      I have created an exit function and registered using OnAutoItExitRegister.But it is not running when I close the app from taskbar or even with normal exit during end.
       
      Below is the part of code and the included files.
      #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <Date.au3> #include <file.au3> #include <Array.au3> #include <String.au3> OnAutoItExitRegister("Exit_Program") Func Exit_Program() LoggingMainScr("Entered Exit_Program") Local $exitmethod = ["Natural closing", "close by Exit function", "close by clicking on exit of the systray","close by user logoff","close by Windows shutdown"] ExitProgram("Exit with exit code: "& @exitCode & " And because of: " & $exitmethod[@exitmethod],@exitmethod) EndFunc Func ExitProgram($sReason="Exit by user",$sCode=0) LoggingMainScr($sReason) if $sCode <> 0 then LoggingMainScr("stopped before completion") FileDelete(@ScriptDir&"\Machines*.txt") FileDelete(@ScriptDir&"\PsExec.exe") FileDelete(@ScriptDir&"\HyperVMachines.ps1") FileDelete(@ScriptDir&"\VMwareMachines.ps1") EndFunc Func LoggingMainScr($sMessage) LoggingDefault($sMessage,@ScriptDir&"\MainScr_Logging.log") EndFunc Func LoggingDefault($sMessage,$sLogFile=@ScriptDir&"\Logging.log") If $sMessage = "" Then FileWriteLine($sLogFile, "") Else FileWrite($sLogFile,_NowCalc() & " :: " & $sMessage&@CRLF) EndIf EndFunc Any suggestion.
       
    • fopetesl
      By fopetesl
      For some reason my personal notes were omitted when posting.
      Still a Newb it seems! So have attached my slightly modified example.
      If I comment out Exit button references script will not Exit even with windows 'X' button icon.
      If I'm losing GUI/Tab focus I cannot see where is the difference with(out) definition.
      GUI_No_Exit.au3
    • fosil
      By fosil
      Hi all,

      I'm working on a relatively complex automation program and I need it to call a specific function when it is closed by a user. Ive resorted to "OnAutoItExitRegister" as i believe that's the only option available.

      This command works perfectly fine in a small scale test application I wrote, but once implemented in the final program that's much larger and divided over many files in many directories it no longer works. I don't get any error messages.

      My question is has anyone encountered an issue where implementation of this command in a large scale program gave them trouble? Does it matter where "OnAutoItExitRegister" is called and where the function is located? Currently they are both places in the main file that runs the whole program but it still doesn't work.

      Any help is appreciated
    • Masum
      By Masum
      Hi all,
      Ctrl+Break stops script only if AutoIt window is active. It doesn't work while automation is going on elsewhere.
      Is there a way to stop the script regardless of where the automation is happening?
      Thanks