Jump to content

I know I'm over looking something simple...


Recommended Posts

Do you intend for this to work for future versions of AutoIt?

 

Nope, I'm going to compile it as a simple standalone tool, though why do ou ask (I'm always up for learning something)

Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Because this is how to use WM_DROPFILES with the current beta...

#include <APIConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>

Global $__aDropFiles = 0

Example()

Func Example()
    Local $hGUI = GUICreate('', 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)

    ; Create a label that is transparent which will accept 'drop' events.
    GUICtrlCreateLabel('', 0, 0, 500, 500)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetResizing(-1, $GUI_DOCKALL)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES')
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $GUI_EVENT_DROPPED
                If $__aDropFiles[0] > 0 Then
                    _ArrayDisplay($__aDropFiles)
                EndIf

        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>Example

Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $lParam
    Switch $iMsg
        Case $WM_DROPFILES
            Local Const $aReturn = _WinAPI_DragQueryFileEx($wParam)
            If UBound($aReturn) Then
                $__aGUIDropFiles = $aReturn
            Else
                Local Const $aError[1] = [0]
                $__aGUIDropFiles = $aError
            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DROPFILES

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

guinness,

Thank you for the tip on the Dropfiles. Could you shed some light on why this isn't working?=

Func _On_Drop() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    For $i = 1 To $aDrop_List[0]
        GUICtrlSetData($Input1, $aDrop_List[$i])
    Next
    Local $ReadInput1 = GUICtrlRead($Input1)
    Local $TextCheck = FileRead($ReadInput1)
    Local $CheckM47 = Execute("'" & StringRegExp ($TextCheck, "M47", 0) & "'")
    If $CheckM47 = 1 Then
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0x000000, 0x00FF00)
    ElseIf $CheckM47 = 0 Then
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0x000000, 0xFF0000)
    EndIf
EndFunc   ;==>_On_Drop;;; This adds the file path of the dropped item to the input box and checks for the M47 code displaying a green or red circle accordingly

I suspect it has to do with this part of the code:
 

Local $CheckM47 = Execute("'" & StringRegExp ($TextCheck, "M47", 0) & "'")

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Remove the use of Execute.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Remove the use of Execute.

Func _On_Drop() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    For $i = 1 To $aDrop_List[0]
        GUICtrlSetData($Input1, $aDrop_List[$i])
    Next
    Local $ReadInput1 = GUICtrlRead($Input1)
    Local $TextCheck = FileRead($ReadInput1)
    Local $CheckM47 = StringRegExp ($TextCheck, "(?m)(N\d+M\d+\R)?N(\d+)(M47\R)", 0)
    If $CheckM47 = 1 Then
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0x000000, 0x00FF00)
    ElseIf $CheckM47 = 0 Then
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0x000000, 0xFF0000)
    EndIf
EndFunc

Still does not work

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

The match always fails: we have Nxx.1M47 and not NxxM47. Try this:

Func _On_Drop() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    For $i = 1 To $aDrop_List[0]
        GUICtrlSetData($Input1, $aDrop_List[$i])
    Next
    Local $ReadInput1 = GUICtrlRead($Input1)
    Local $TextCheck = FileRead($ReadInput1)
    Local $CheckM47 = StringRegExp ($TextCheck, "(?m)N\d+\.\dM47\R", 0)
    If $CheckM47 Then
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0x000000, 0x00FF00)
    Else
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0x000000, 0xFF0000)
    EndIf
EndFunc

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

 

The match always fails: we have Nxx.1M47 and not NxxM47. Try this:

Func _On_Drop() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    For $i = 1 To $aDrop_List[0]
        GUICtrlSetData($Input1, $aDrop_List[$i])
    Next
    Local $ReadInput1 = GUICtrlRead($Input1)
    Local $TextCheck = FileRead($ReadInput1)
    Local $CheckM47 = StringRegExp ($TextCheck, "(?m)N\d+\.\dM47\R", 0)
    If $CheckM47 Then
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0x000000, 0x00FF00)
    Else
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0x000000, 0xFF0000)
    EndIf
EndFunc

 

This isn't working either, I have no idea why...

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

That's just it, it doesnt do anything. Upon dropping the item on the gui it edits the input as it should but the graphic doesnt change and I haven't the faintest clue why.

 

My code so far:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <Array.au3>
#include <File.au3>
Opt("GUIOnEventMode", 1)
; GUI section starts here:
$GUI = GUICreate("M47 Tool", 509, 136, 340, 175, Default, $WS_EX_ACCEPTFILES)
GUISetIcon("C:\prog_res\Lab\test_res\config.ico", -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close_M47_Tool")
$Input1 = GUICtrlCreateInput("", 92, 56, 329, 21)
$Label1 = GUICtrlCreateLabel("Use this tool to add or remove the M47 code from a program", 11, 16, 486, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Add M47", 88, 88, 161, 41)
GUICtrlSetCursor (-1, 0)
GUICtrlSetOnEvent(-1, "Add_M47")
$Button2 = GUICtrlCreateButton("Remove M47", 260, 88, 161, 41)
GUICtrlSetCursor (-1, 0)
GUICtrlSetOnEvent(-1, "Remove_M47")
$Button3 = GUICtrlCreateButton("", 440, 48, 49, 41, $BS_ICON)
GUICtrlSetImage(-1, "C:\prog_res\Lab\test_res\reload%2032.ico", -1)
GUICtrlSetTip(-1, "Reload Tool")
GUICtrlSetCursor (-1, 0)
GUICtrlSetOnEvent(-1, "Tool_Reload")
$Button4 = GUICtrlCreateButton("?", 456, 104, 33, 25, $BS_PUSHBOX)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlSetTip(-1, "Open the Help file")
GUICtrlSetCursor (-1, 4)
GUICtrlSetOnEvent(-1, "Open_Help")
$Graphic1 = GUICtrlCreateGraphic(48, 48, 40, 41)
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 5, 4, 30, 31)
$cDrop_Dummy = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "_On_Drop")
Local $sText
Global $aDrop_List
GUISetState(@SW_SHOW)
; GUI section ends here.
;;;;;;;;;;;;;;;;;;;;;
; Register $WM_DROPFILES function to detect drops anywhere on the GUI <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUIRegisterMsg(0x233, "On_WM_DROPFILES") ; $WM_DROPFILES
;;;;;;;;;;;;;;;;;;;;
While 1

WEnd

Func _On_Drop() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    For $i = 1 To $aDrop_List[0]
        GUICtrlSetData($Input1, $aDrop_List[$i])
    Next
    Local $ReadInput1 = GUICtrlRead($Input1)
    Local $TextCheck = FileRead($ReadInput1)
    Local $CheckM47 = StringRegExp ($TextCheck, "(?m)N\d+\.\dM47\R", 0)
    If $CheckM47 Then
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0x000000, 0x00FF00)
    Else
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0x000000, 0xFF0000)
    EndIf
EndFunc   ;==>_On_Drop;;; This adds the file path of the dropped item to the input box and checks for the M47 code displaying a green or red circle accordingly

Func Input_Prog_Check(); Checks the program for the M47 code and displays either an error icon or success icon

EndFunc

Func Close_M47_Tool(); CLoses the Tool
    Exit
EndFunc

Func Add_M47(); This function adds the M47 code to the program
    Local $ReadInput1 = GUICtrlRead($Input1)
    Local $sText = FileRead($ReadInput1)
    Local $sTextM47 = Execute("'" & StringRegExpReplace($sText, "(?m)(N\d+M\d+\R)?N(\d+)(M0\R)", "$1N' & StringFormat('%04.1f', $2 - 0.9) & 'M47" & @CRLF & "N$2$3", 1) & "'")
    FileDelete ($ReadInput1)
        FileWrite ($ReadInput1, $sTextM47)
EndFunc

Func Remove_M47(); This function removes the M47 code from the program

EndFunc

Func Tool_Reload(); This function clears the $ReadInput1 var
    GUICtrlSetData ($Input1, "")
EndFunc

Func Open_Help(); The function opens the help file to aid the user in adding or removing the M47 code
$Form2 = GUICreate("Form2", 665, 834, 484, 50)
GUISetOnEvent($GUI_EVENT_CLOSE, "Help_window_close")
GUISetIcon("C:\prog_res\Lab\test_res\config.ico", -1)
$Label1 = GUICtrlCreateLabel("M47 Help Window", 225, 8, 215, 33)
GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0xA0A0A4)
$Pic1 = GUICtrlCreatePic("C:\prog_res\Lab\test_res\ScreenCap.bmp", 8, 56, 649, 363)
$Label2 = GUICtrlCreateLabel("1:  Indicates that the loaded program contains the M47 code", 59, 472, 476, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label3 = GUICtrlCreateLabel("2:  Indicates that the Loaded Program does not contain the M47 code", 59, 519, 544, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label4 = GUICtrlCreateLabel("3:  Use this button to add the M47 code", 59, 566, 312, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label5 = GUICtrlCreateLabel("4:  Use this button to remove the M47 code", 59, 613, 338, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label6 = GUICtrlCreateLabel("5:  Use this button to access the Help Window", 59, 660, 359, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label7 = GUICtrlCreateLabel("6:  Use this button to reset the M47 Tool Window", 59, 707, 382, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label8 = GUICtrlCreateLabel("7:   Either type in the full path, or drag and drop the file here", 59, 754, 644, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
EndFunc

Func Help_window_close()
    GUIDelete ("M47 Help Window")
EndFunc

; React to items dropped on the GUI <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Func On_WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    ; Credit to ProgAndy for DLL calls
    #forceref $hWnd, $iMsg, $lParam
    Local $iSize, $pFileName
    ; Get number of files dropped
    Local $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 0)
    ; Reset array to correct size
    Global $aDrop_List[$aRet[0] + 1] = [$aRet[0]]
    ; And add item names
    For $i = 0 To $aRet[0] - 1
        $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $iSize = $aRet[0] + 1
        $pFileName = DllStructCreate("wchar[" & $iSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $iSize)
        $aDrop_List[$i + 1] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
    ; Send the count to trigger the drop function in the main loop
    GUICtrlSendToDummy($cDrop_Dummy, $aDrop_List[0])
EndFunc   ;==>On_WM_DROPFILES

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

alright so i have the graphic showing on drop, but it only shows up green. Its shows as green with or without the M47 code present in the file. So this leads me to believe that the StringRegExp isn't effecting the If statement

Func _On_Drop() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    For $i = 1 To $aDrop_List[0]
        GUICtrlSetData($Input1, $aDrop_List[$i])
    Next
    Local $ReadInput1 = GUICtrlRead($Input1)
    Local $TextCheck = FileRead($ReadInput1)
    Local $CheckM47 = StringRegExp ($TextCheck, "(?m)N\d+\.\dM47\R", 0)
        If $CheckM47 = 1 Then
            $Graphic1 = GUICtrlCreateGraphic(48, 48, 40, 41)
            GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x00FF00)
            GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 5, 4, 30, 31)
            GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
        ElseIf $CheckM47 = 0 Then
            $Graphic1 = GUICtrlCreateGraphic(48, 48, 40, 41)
            GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xFF0000)
            GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 5, 4, 30, 31)
            GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
        EndIf
EndFunc

and yes I have declared the $CheckM47 as a global var

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

a way of debugging is to put messageboxes in the code so you know where it goes and where it fails

 

and please append an example file to drop it in :)

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <Array.au3>
#include <File.au3>
Opt("GUIOnEventMode", 1)
; GUI section starts here:
$GUI = GUICreate("M47 Tool", 509, 136, 340, 175, Default, $WS_EX_ACCEPTFILES)
GUISetIcon("C:\prog_res\Lab\test_res\config.ico", -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close_M47_Tool")
$Input1 = GUICtrlCreateInput("", 92, 56, 329, 21)
$Label1 = GUICtrlCreateLabel("Use this tool to add or remove the M47 code from a program", 11, 16, 486, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Add M47", 88, 88, 161, 41)
GUICtrlSetCursor (-1, 0)
GUICtrlSetOnEvent(-1, "Add_M47")
$Button2 = GUICtrlCreateButton("Remove M47", 260, 88, 161, 41)
GUICtrlSetCursor (-1, 0)
GUICtrlSetOnEvent(-1, "Remove_M47")
$Button3 = GUICtrlCreateButton("", 440, 48, 49, 41, $BS_ICON)
GUICtrlSetImage(-1, "C:\prog_res\Lab\test_res\reload%2032.ico", -1)
GUICtrlSetTip(-1, "Reload Tool")
GUICtrlSetCursor (-1, 0)
GUICtrlSetOnEvent(-1, "Tool_Reload")
$Button4 = GUICtrlCreateButton("?", 456, 104, 33, 25, $BS_PUSHBOX)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlSetTip(-1, "Open the Help file")
GUICtrlSetCursor (-1, 4)
GUICtrlSetOnEvent(-1, "Open_Help")
$cDrop_Dummy = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "_On_Drop")
Global $Graphic1
Local $sText
Global $aDrop_List
GUISetState(@SW_SHOW)
; GUI section ends here.
;;;;;;;;;;;;;;;;;;;;;
; Register $WM_DROPFILES function to detect drops anywhere on the GUI <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUIRegisterMsg(0x233, "On_WM_DROPFILES") ; $WM_DROPFILES
;;;;;;;;;;;;;;;;;;;;
While 1

WEnd

Func _On_Drop() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    For $i = 1 To $aDrop_List[0]
        GUICtrlSetData($Input1, $aDrop_List[$i])
    Next
    Local $ReadInput1 = GUICtrlRead($Input1)
    Local $TextCheck = FileRead($ReadInput1)
    Local $CheckM47 = StringRegExp ($TextCheck, "(?m)N\d+\.\dM47\R", 0)
        If $CheckM47 = 1 Then
            $Graphic1 = GUICtrlCreateGraphic(48, 48, 40, 41)
            GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x00FF00)
            GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 5, 4, 30, 31)
            GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
        ElseIf $CheckM47 = 0 Then
            $Graphic1 = GUICtrlCreateGraphic(48, 48, 40, 41)
            GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xFF0000)
            GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 5, 4, 30, 31)
            GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
        EndIf
EndFunc   ;==>_On_Drop;;; This adds the file path of the dropped item to the input box and checks for the M47 code displaying a green or red circle accordingly

Func Input_Prog_Check(); Checks the program for the M47 code and displays either an error icon or success icon

EndFunc

Func Close_M47_Tool(); CLoses the Tool
    Exit
EndFunc

Func Add_M47(); This function adds the M47 code to the program
    Local $ReadInput1 = GUICtrlRead($Input1)
    Local $sText = FileRead($ReadInput1)
    Local $sTextM47 = Execute("'" & StringRegExpReplace($sText, "(?m)(N\d+M\d+\R)?N(\d+)(M0\R)", "$1N' & StringFormat('%04.1f', $2 - 0.9) & 'M47" & @CRLF & "N$2$3", 1) & "'")
    FileDelete ($ReadInput1)
        FileWrite ($ReadInput1, $sTextM47)
EndFunc

Func Remove_M47(); This function removes the M47 code from the program

EndFunc

Func Tool_Reload(); This function clears the $ReadInput1 var
    GUICtrlSetData ($Input1, "")
    GUICtrlDelete ($Graphic1)
EndFunc

Func Open_Help(); This function opens the help file to aid the user in adding or removing the M47 code
$Form2 = GUICreate("Form2", 665, 834, 484, 50)
GUISetOnEvent($GUI_EVENT_CLOSE, "Help_window_close")
GUISetIcon("C:\prog_res\Lab\test_res\config.ico", -1)
$Label1 = GUICtrlCreateLabel("M47 Help Window", 225, 8, 215, 33)
GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0xA0A0A4)
$Pic1 = GUICtrlCreatePic("C:\prog_res\Lab\test_res\ScreenCap.bmp", 8, 56, 649, 363)
$Label2 = GUICtrlCreateLabel("1:  Indicates that the loaded program contains the M47 code", 59, 472, 476, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label3 = GUICtrlCreateLabel("2:  Indicates that the Loaded Program does not contain the M47 code", 59, 519, 544, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label4 = GUICtrlCreateLabel("3:  Use this button to add the M47 code", 59, 566, 312, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label5 = GUICtrlCreateLabel("4:  Use this button to remove the M47 code", 59, 613, 338, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label6 = GUICtrlCreateLabel("5:  Use this button to access the Help Window", 59, 660, 359, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label7 = GUICtrlCreateLabel("6:  Use this button to reset the M47 Tool Window", 59, 707, 382, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
$Label8 = GUICtrlCreateLabel("7:   Either type in the full path, or drag and drop the file here", 59, 754, 644, 25)
GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium")
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
EndFunc

Func Help_window_close()
    GUIDelete ("M47 Help Window")
EndFunc

; React to items dropped on the GUI <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Func On_WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    ; Credit to ProgAndy for DLL calls
    #forceref $hWnd, $iMsg, $lParam
    Local $iSize, $pFileName
    ; Get number of files dropped
    Local $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 0)
    ; Reset array to correct size
    Global $aDrop_List[$aRet[0] + 1] = [$aRet[0]]
    ; And add item names
    For $i = 0 To $aRet[0] - 1
        $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $iSize = $aRet[0] + 1
        $pFileName = DllStructCreate("wchar[" & $iSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $iSize)
        $aDrop_List[$i + 1] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
    ; Send the count to trigger the drop function in the main loop
    GUICtrlSendToDummy($cDrop_Dummy, $aDrop_List[0])
EndFunc   ;==>On_WM_DROPFILES

That's the entire code, and I'm already making preperations to donate, this site is well worth it. Also the admins should consider putting in a spot on the members profile for other members to donate to them such as xda does for their devs. I plan to donate to the site but would also love the ability to donate directly to devs here that actively help out.

 

EDIT: AHA!!! It Works!!

So there were other M47 codes further down in the file.... that's why it was always green....

So I need it to check for:

NxxM47

NxxM0

exactly, so that I know its before the M0

Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Few things:

  o) in _On_Drop() you loop thru the list of files dropped but without processing them at all. Only the last one is processed. The Next statement sould be the last line in your function so that every file is processed. But since all files will be "processed" without possible user interaction (except for the last file) I don't see how this approach can work in practice when multiple files are dropped. You should invoke this function for every single file individually and wait for the user to select Add, Remove or Skip (is that missing?).

  o) my tests show that the regexp works as expected. Only drawing doesn't work (and I dramatically suck at graphics).

  o) Testing

        $CheckM47 = StringRegExp ($TextCheck, "(?m)Nd+.dM47R", 0)
        If $CheckM47 = 1 Then

        ElseIf $CheckM47 = 0 Then
        EndIf

is overkill:

        If StringRegExp ($TextCheck, "(?m)Nd+.dM47R", 0) Then
        Else
        EndIf

Guys, use this as input:

N01M12
N02M34
N03M02
N04M11
N05M0
N06M12
N07M0
N08M12

  

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Ahem, you say it works? That surprises me from what you've said before.

Look, the regexp explicitely looks for lines containing Nxx.xM47 where xx.x are (supposed) to have been added by the function discussed before. That means that the next line is an M0, well unless you already have extra Nxx.xM47 lines in the file, which are not followed by an M0. But you requested that only the first occurence of an M0 triggered insertion of an M47. To me this is a contradiction.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Ahem, you say it works? That surprises me from what you've said before.

 

Look, the regexp explicitely looks for lines containing Nxx.xM47 where xx.x are (supposed) to have been added by the function discussed before. That means that the next line is an M0, well unless you already have extra Nxx.xM47 lines in the file, which are not followed by an M0. But you requested that only the first occurence of an M0 triggered insertion of an M47. To me this is a contradiction.

 

 

Having the Nxx.xM47 before the NxxM0 causes it to be used for all punches in the program, though sometimes the program already has it in a few of the punches (hence below the NxxM0 code). This was the case with the test file, where it contained the M47 code later in the file and was being read as a valid array because it was present, as i did not specify to check specifically if it was present in this format:

Nxx.xM47

NxxM0(first M0 in file)

 

So my on_drop was displaying a green ellipse because it was indeed in the file, though not where i need it.

 

Also regarding the multiple files being dragged and dropped, they will only be doing one at a time, I simply used a code I found here on the forums that was fitted for multiple files.

 

My apologies

 

 

 

$CheckM47 is not declared globally and it does not look like it needs to be.

 

As Edano said, need a file to test with.

 

 

kylomas

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <Array.au3>
#include <File.au3>
Opt("GUIOnEventMode", 1)
; GUI section starts here:
$GUI = GUICreate("M47 Tool", 509, 136, 340, 175, Default, $WS_EX_ACCEPTFILES)
GUISetIcon("C:\prog_res\Lab\test_res\config.ico", -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close_M47_Tool")
$Input1 = GUICtrlCreateInput("", 92, 56, 329, 21)
$Label1 = GUICtrlCreateLabel("Use this tool to add or remove the M47 code from a program", 11, 16, 486, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Add M47", 88, 88, 161, 41)
GUICtrlSetCursor (-1, 0)
GUICtrlSetOnEvent(-1, "Add_M47")
$Button2 = GUICtrlCreateButton("Remove M47", 260, 88, 161, 41)
GUICtrlSetCursor (-1, 0)
GUICtrlSetOnEvent(-1, "Remove_M47")
$Button3 = GUICtrlCreateButton("", 440, 48, 49, 41, $BS_ICON)
GUICtrlSetImage(-1, "C:\prog_res\Lab\test_res\reload%2032.ico", -1)
GUICtrlSetTip(-1, "Reload Tool")
GUICtrlSetCursor (-1, 0)
GUICtrlSetOnEvent(-1, "Tool_Reload")
$Button4 = GUICtrlCreateButton("?", 456, 104, 33, 25, $BS_PUSHBOX)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlSetTip(-1, "Open the Help file")
GUICtrlSetCursor (-1, 4)
GUICtrlSetOnEvent(-1, "Open_Help")
$cDrop_Dummy = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "_On_Drop")
Global $Graphic1
Local $sText
Global $aDrop_List
GUISetState(@SW_SHOW)
; GUI section ends here.
37th line in above code

Also I cannot provide a test file as it is the intellectual property of the company i work for and would rather not be fired... Use this instead:

Guys, use this as input:

N01M12
N02M34
N03M02
N04M11
N05M0
N06M12
N07M0
N08M12
Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

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