Sign in to follow this  
Followers 0
DJG

A thanks and a couple questions

5 posts in this topic

I just wanted to say thank you for an amazingly intuitive program. I am not a programmer and have no programming experience other than a couple of BASIC classes I took a long (20+ years) time ago. That said, using this program and with a lot of trial and error I was able to put together a rather sophisticated program that has been very useful to me. There are a couple problems I am stuck on that I hope you can help with.

1) My program essentially reads an Edit window and copies the information to a text file if the text has changed in any way. Unfortunately, the text can change at any time so because of this I have it read in an endless loop. The problem I notice is it consumes a ton of system resources in this way. The CPU devotes 99% of resources as it's scanning this window over and over again for changes. Is there a better way of doing this?

While 1

$re = ControlGetText("Window","","Edit2")

If $re <> $re2 Then (continue program...)

WEnd

2) I have no problems assigning a filename to a variable (i.e. $filename) and the FileOpen, FileClose, and FileWriteLine commands work with it. However, I can't seem to get the FileMove command to work. Is it because I am trying to move the file to a network drive or will the FileMove command just not work with a variable?

FileMove ($filename, "\\new\target\")

3) Finally, I'm trying to get the program to close a window by hitting the OK button at the random times it pops up. The problem is I can't close it based on the window title as it changes each time. I can't seem to get it to close using "Class:" either. I don't want it to hit any "OK" or "Button1" button or it might close a different program or something important I am doing in the background. Any suggestions? The window is the same size each time it pops up I am pretty sure. Perhaps it can close any windows that meet certain X and Y criteria? I believe it also pops up in the same area (center) of the screen. If I can close the window using one of these criteria, could you explain how?

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

Title: (varies)

Class: #32770

Size: X: 696 Y: 521 W: 208 H: 130

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Screen: X: 786 Y: 621

Cursor ID: 2

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0xD4D0C8 Dec: 13947080

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 62 Y: 65 W: 77 H: 25

Control ID: 16382

ClassNameNN: Button1

Text: OK

Style: 0x54014001

ExStyle: 0x00000000

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<

OK

>>>>>>>>>>> Hidden Window Text <<<<<<<<<<<

Thank you in advance.

Share this post


Link to post
Share on other sites



  • Add Sleep(1) or Sleep(100) Into your While loop
  • You should use full path if you want to do this sucessfully, and use a dir, such as @ScriptDir
  • I can help if you provide more information about this "Window"

Share this post


Link to post
Share on other sites

1) Worked perfect, thank you.

2) If I'm reading the help file correctly, @scriptdir uses the directory the script is running in? The variable I use for the filename is a different directory so I'm not sure how I could get this to work the way you suggested. Sorry, I really am a complete noob when it comes to this program, but here's an example of how it's currently set:

If $midcount >= $filesize Then

FileClose($filemid)

FileMove($filemid, "\\New\MID\")

$midcount = 0

$sDate = @YEAR & "-" & @MON & "-" & @MDAY & " - " & @HOUR & "h" & @MIN & "m" & @SEC & "s "

$filemid = "C:\MID\MID - " & $sDate & $filename & " -MID-.txt"

Endif

\\New\MID is a network directory for a different computer. All the other commands seem to work ok, just not FileMove.

3) It's a standard small window that pops up as a notification that a different window is about to close automatically. Once you hit the OK button, the window closes in addition to the window it's referring to. Does that answer your question?

Share this post


Link to post
Share on other sites

Also, if it helps, the window has the 'x' in the top-right that can be clicked and it can also be closed using Alt-F4.

Help? :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This is a bit of a stretch, but at some point gafrost edited a program i had made so i could tell when a control has changed, and update another based on it. I believe the effect is similar to what you desire.

Unfortunately I don't quite understand exactly how GUIRegisterMsg Works, but here is the thread:

http://www.autoitscript.com/forum/index.ph...c=31355&hl=

And gafrost's final code (after i removed debug):

#include <GuiConstants.au3>

Global Const $WM_COMMAND = 0x0111
Global Const $EN_CHANGE = 0x300

; == GUI generated with Koda == Thank GOD for Koda!!
$Decimal = GUICreate("Decimal and Hexadecimal Colors", 592, 299, 414, 191, -1, $WS_EX_TOOLWINDOW)
GUISetBkColor(0xD4D0C8)
$RedSlider = GUICtrlCreateSlider(75, 35, 255, 35, BitOR($TBS_BOTH, $TBS_NOTICKS), $WS_EX_CLIENTEDGE)
$GreenSlider = GUICtrlCreateSlider(75, 90, 255, 35, BitOR($TBS_BOTH, $TBS_NOTICKS), $WS_EX_CLIENTEDGE)
$BlueSlider = GUICtrlCreateSlider(75, 145, 255, 35, BitOR($TBS_BOTH, $TBS_NOTICKS), $WS_EX_CLIENTEDGE)
GUICtrlSetLimit($RedSlider, 255, 0)
GUICtrlSetLimit($GreenSlider, 255, 0)
GUICtrlSetLimit($BlueSlider, 255, 0)
GUICtrlCreateLabel("Red:", 10, 35, 40, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("Green:", 10, 90, 58, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
GUICtrlSetColor(-1, 0x008000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("Blue:", 10, 145, 45, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetBkColor(-1, 0xD4D0C8)
$Display = GUICtrlCreateLabel("", 370, 23, 200, 230, BitOR($SS_SUNKEN, $WS_BORDER), $WS_EX_CLIENTEDGE)
GUICtrlSetBkColor(-1, 0x000000)
$HexInput = GUICtrlCreateInput("000000", 215, 195, 135, 24, $ES_CENTER, $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000080)
$DecInput = GUICtrlCreateInput("000000", 215, 235, 135, 24, BitOR($ES_CENTER, $ES_NUMBER), $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000080)
$RedCount = GUICtrlCreateLabel("Red: 0 = 00", 15, 195, 130, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
$GreenCount = GUICtrlCreateLabel("Green: 0 = 00", 15, 225, 140, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
$BlueCount = GUICtrlCreateLabel("Blue: 0 = 00", 15, 255, 130, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("HEX:", 155, 195, 50, 27)
GUICtrlSetFont(-1, 12, 800, 0, "Arial Black")
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("DEC:", 155, 235, 49, 27)
GUICtrlSetFont(-1, 12, 800, 0, "Arial Black")
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
$CurrentRed = GUICtrlRead($RedSlider)
$CurrentGreen = GUICtrlRead($GreenSlider)
$CurrentBlue = GUICtrlRead($BlueSlider)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            If $CurrentRed <> GUICtrlRead($RedSlider) Or _
                    $CurrentGreen <> GUICtrlRead($GreenSlider) Or _
                    $CurrentBlue <> GUICtrlRead($BlueSlider) Then
                $CurrentRed = GUICtrlRead($RedSlider)
                GUICtrlSetData($RedCount, "Red: " & $CurrentRed & " = " & StringTrimLeft(Hex($CurrentRed), 6))
                $CurrentGreen = GUICtrlRead($GreenSlider)
                GUICtrlSetData($GreenCount, "Green: " & $CurrentGreen & " = " & StringTrimLeft(Hex($CurrentGreen), 6))
                $CurrentBlue = GUICtrlRead($BlueSlider)
                GUICtrlSetData($BlueCount, "Blue: " & $CurrentBlue & " = " & StringTrimLeft(Hex($CurrentBlue), 6))
                $OutHex = StringTrimLeft(Hex($CurrentRed), 6) & StringTrimLeft(Hex($CurrentGreen), 6) & StringTrimLeft(Hex($CurrentBlue), 6)
                $OutDec = Dec($OutHex)
                GUICtrlSetData($HexInput, $OutHex)
                GUICtrlSetData($DecInput, $OutDec)
                GUICtrlSetBkColor($Display, "0x" & $OutHex)
            EndIf
    EndSelect

WEnd
Exit

Func _Hex_Changed()
    Local $Hex = GUICtrlRead($HexInput)
    If StringLen($Hex) = 6 Then
        If GUICtrlRead($RedSlider) <> Dec(StringMid($Hex, 1, 2)) Then
            GUICtrlSetData($RedSlider, Dec(StringMid($Hex, 1, 2)))
        EndIf
        If GUICtrlRead($GreenSlider) <> Dec(StringMid($Hex, 3, 2)) Then
            GUICtrlSetData($GreenSlider, Dec(StringMid($Hex, 3, 2)))
        EndIf
        If GUICtrlRead($BlueSlider) <> Dec(StringMid($Hex, 5, 2)) Then
            GUICtrlSetData($BlueSlider, Dec(StringMid($Hex, 5, 2)))
        EndIf
    EndIf
EndFunc   ;==>_Hex_Changed

Func _Dec_Changed()
    Local $Hex = Hex(GUICtrlRead($DecInput), 6)
    If StringLen($Hex) = 6 Then
        If GUICtrlRead($RedSlider) <> Dec(StringMid($Hex, 1, 2)) Then
            GUICtrlSetData($RedSlider, Dec(StringMid($Hex, 1, 2)))
        EndIf
        If GUICtrlRead($GreenSlider) <> Dec(StringMid($Hex, 3, 2)) Then
            GUICtrlSetData($GreenSlider, Dec(StringMid($Hex, 3, 2)))
        EndIf
        If GUICtrlRead($BlueSlider) <> Dec(StringMid($Hex, 5, 2)) Then
            GUICtrlSetData($BlueSlider, Dec(StringMid($Hex, 5, 2)))
        EndIf
    EndIf
EndFunc   ;==>_Dec_Changed

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam

    Switch $nID
        Case $HexInput
            Switch $nNotifyCode
                Case $EN_CHANGE
                    _Hex_Changed()
            EndSwitch
        Case $DecInput
            Switch $nNotifyCode
                Case $EN_CHANGE
                    _Dec_Changed()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord
Edited by Paulie

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