I'll post this even though there are still a few minor bugs in this and needs to be tested more thouroughly.
I've made this to collect data from AllenBradly PLC's through RSLinx. I have added the DDE_Advise and DDE_Unadvise functions so RSLinx can send messages when the data changes instead of having to poll for changes all the time. For small amounts of data that doesn't change very quickly this works well for me.
This is the full script including a modified version of Joy2DWorld's DDE functions.
All credit goes to Joy2DWorld and a very small part to MSDN.
This is not compatible with AHK_L yet.
Code:
;==================================================================================================================
;=================================================Check Dependancies===============================================
;==================================================================================================================
If !FileExist(A_ProgramFiles . "\Rockwell Software\RSLinx\RSLinx.exe") ;"C:\Program Files\Rockwell Software\RSLINX\RSLINX.EXE"
{
MsgBox, 4144, Program Dependancy, This program requires RSLinx to be installed on this computer.
ExitApp
}
;==================================================================================================================
;=================================================Set Script Constants=============================================
;==================================================================================================================
#SingleInstance off ;force
#Persistent
PID := DllCall("GetCurrentProcessId")
OnMessage(0x404, "AHK_NOTIFYICON")
OnExit, Exit
DetectHiddenWindows, On
SetTitleMatchMode, 2
If A_IsCompiled
Ext:=".exe"
If !A_IsCompiled
Ext:=".ahk"
WinName:= "DDE2File2"
__DDE_Advise_Use := 1
__DDE_Use_Answer_Table := 0
__DDE_SafeMode := 1
__DDE_BatchMode:= 0
StringRight, Year, A_YYYY, 2
Month:= A_MM
Day:= A_DD
PID := DllCall("GetCurrentProcessId")
Help:= "The program works as follows. You select a DDE Server (RSLINX) and a DDE Topic that must be configured before you run this program. You also have to set up a DDE Trigger which is just a Boolean tag in a PLC that is used to trigger the collection of all the data points. `n`n You can collect the data in 2 ways. The first is to poll the data`, meaning you check the status of the trigger tag in intervals equal to the poll rate. The second is to set up a hot link in which RSLinx will send an Advise message to this program when ever the data changes. I recommend using the Advise method as it is much more efficient. When the trigger = 1 the program stops monitoring the trigger tag and collects all the data points saved in the configuration.`n`nTo edit the configuration select DDE2File2 Configuration from the Edit menu. Add the tag names you want to record on the trigger to the Data Points control. If the tag is a controller wide scope tag`, just add the tag name as Tag_Name. The tags collected at the trigger point will be added to a text file in the order they appear. `n`nIf the tag is a program wide scope the syntax is as follows.`n`nProgram:TG9.Tag_Name`n`nOnce the data has been collected the program will use DDE to set the trigger tag back to 0 to confirm the data has been collected. The data will be stored in Log File specified in a tab delimited format which can be easily opened with excel."
About:="DDE2File2 was created by Joel Wagner.`n`nMost of the work came from Joy2DWorld athe original topic http://www.autohotkey.com/forum/topic21910.html and MSDN."
IfNotExist, %A_StartMenu%\Programs\DDE2File2\Config Files
FileCreateDir, %A_StartMenu%\Programs\DDE2File2\Config Files
IfNotExist, %A_StartMenu%\Programs\DDE2File2\Logs
FileCreateDir, %A_StartMenu%\Programs\DDE2File2\Logs
IfNotExist, %A_StartMenu%\Programs\DDE2File2\RunTime
FileCreateDir, %A_StartMenu%\Programs\DDE2File2\RunTime
FileSetAttrib, -H,%A_StartMenu%\Programs\DDE2File2\Images,1,1
FileSetAttrib, -H,%A_StartMenu%\Programs\DDE2File2\Bin,1,1
IfNotExist, %A_StartMenu%\Programs\DDE2File2\Images
FileCreateDir, %A_StartMenu%\Programs\DDE2File2\Images
If FileExist("Data-Binding.png")
{
If FileExist(A_StartMenu . "\Programs\DDE2File2\Images\Data-Binding.png")
FileDelete, %A_StartMenu%\Programs\DDE2File2\Images\Data-Binding.png
FileCopy, Data-Binding.png, %A_StartMenu%\Programs\DDE2File2\Images\Data-Binding.png
}
IfNotExist, %A_StartMenu%\Programs\DDE2File2\Bin
FileCreateDir, %A_StartMenu%\Programs\DDE2File2\Bin
If A_ScriptFullPath != %A_StartMenu%\Programs\DDE2File2\Bin\DDE2File2%Ext%
{
If FileExist(A_StartMenu . "\Programs\DDE2File2\Bin\DDE2File2" . Ext)
FileDelete, %A_StartMenu%\Programs\DDE2File2\Bin\DDE2File2%Ext%
FileCopy, %A_ScriptFullPath%, %A_StartMenu%\Programs\DDE2File2\Bin\DDE2File2%Ext%
}
FileSetAttrib, +H,%A_StartMenu%\Programs\DDE2File2\Images,1,1
If 0 = 2 ;If params equals 2
Goto, RunInstance
;==================================================================================================================
;=================================================Create New or Instance============================================
;==================================================================================================================
Gui, Add, ListView, xm r20 w700 vMyListView gListView, Name|In Folder|Size (KB)|Type
LV_ModifyCol(3, "Integer") ; For sorting, indicate that the Size column is an integer.
; Create an ImageList so that the ListView can display some icons:
ImageListID1 := IL_Create(10)
ImageListID2 := IL_Create(10, 10, true) ; A list of large icons to go with the small ones.
; Attach the ImageLists to the ListView so that it can later display the icons:
LV_SetImageList(ImageListID1)
LV_SetImageList(ImageListID2)
; Create a popup menu to be used as the context menu:
Gui, Add, Button, gNew x+10 yp h25 w70, New
Gui, Add, Button, gExit xp y285 h25 w70, Exit
; Display the window and return. The OS will notify the script whenever the user
; performs an eligible action:
Gui, Show
; Ensure the variable has enough capacity to hold the longest file path. This is done
; because ExtractAssociatedIconA() needs to be able to store a new filename in it.
VarSetCapacity(Filename, 260)
sfi_size = 352
VarSetCapacity(sfi, sfi_size)
; Gather a list of file names from the selected folder and append them to the ListView:
GuiControl, -Redraw, MyListView ; Improve performance by disabling redrawing during load.
Loop %A_StartMenu%\Programs\DDE2File2\RunTime\*.*
{
FileName := A_LoopFileFullPath ; Must save it to a writable variable for use below.
; Build a unique extension ID to avoid characters that are illegal in variable names,
; such as dashes. This unique ID method also performs better because finding an item
; in the array does not require search-loop.
SplitPath, FileName,,, FileExt ; Get the file's extension.
if FileExt in EXE,ICO,ANI,CUR
{
ExtID := FileExt ; Special ID as a placeholder.
IconNumber = 0 ; Flag it as not found so that these types can each have a unique icon.
}
else ; Some other extension/file-type, so calculate its unique ID.
{
ExtID = 0 ; Initialize to handle extensions that are shorter than others.
Loop 7 ; Limit the extension to 7 characters so that it fits in a 64-bit value.
{
StringMid, ExtChar, FileExt, A_Index, 1
if not ExtChar ; No more characters.
break
; Derive a Unique ID by assigning a different bit position to each character:
ExtID := ExtID | (Asc(ExtChar) << (8 * (A_Index - 1)))
}
; Check if this file extension already has an icon in the ImageLists. If it does,
; several calls can be avoided and loading performance is greatly improved,
; especially for a folder containing hundreds of files:
IconNumber := IconArray%ExtID%
}
if not IconNumber ; There is not yet any icon for this extension, so load it.
{
; Get the high-quality small-icon associated with this file extension:
if not DllCall("Shell32\SHGetFileInfoA", "str", FileName, "uint", 0, "str", sfi, "uint", sfi_size, "uint", 0x101) ; 0x101 is SHGFI_ICON+SHGFI_SMALLICON
IconNumber = 9999999 ; Set it out of bounds to display a blank icon.
else ; Icon successfully loaded.
{
; Extract the hIcon member from the structure:
hIcon = 0
Loop 4
hIcon += *(&sfi + A_Index-1) << 8*(A_Index-1)
; Add the HICON directly to the small-icon and large-icon lists.
; Below uses +1 to convert the returned index from zero-based to one-based:
IconNumber := DllCall("ImageList_ReplaceIcon", "uint", ImageListID1, "int", -1, "uint", hIcon) + 1
DllCall("ImageList_ReplaceIcon", "uint", ImageListID2, "int", -1, "uint", hIcon)
; Now that it's been copied into the ImageLists, the original should be destroyed:
DllCall("DestroyIcon", "uint", hIcon)
; Cache the icon to save memory and improve loading performance:
IconArray%ExtID% := IconNumber
}
}
; Create the new row in the ListView and assign it the icon number determined above:
LV_Add("Icon" . IconNumber, A_LoopFileName, A_LoopFileDir, A_LoopFileSizeKB, FileExt)
}
GuiControl, +Redraw, MyListView ; Re-enable redrawing (it was disabled above).
LV_ModifyCol(1, 250) ; Make the Size column at little wider to reveal its header.
LV_ModifyCol(2, 310) ; Make the Size column at little wider to reveal its header.
LV_ModifyCol(3, 70) ; Make the Size column at little wider to reveal its header.
LV_ModifyCol(4, 70) ; Make the Size column at little wider to reveal its header.
Menu, HelpMenu, Add, DDE Help, Help
Menu, AboutMenu, Add, About, About
Menu, MyMenuBar, Add, Help, :HelpMenu
Menu, MyMenuBar, Add, About, :AboutMenu
Gui, Menu, MyMenuBar
Gui, Show,h320, %WinName%
Gui, +LastFound
Return
ListView:
if A_GuiEvent = DoubleClick ; There are many other possible values the script can check.
{
LV_GetText(FileName, A_EventInfo, 1) ; Get the text of the first field.
LV_GetText(FileDir, A_EventInfo, 2) ; Get the text of the second field.
If FileExist(FileDir . "\" . FileName)
{
Run %FileDir%\%FileName%,, UseErrorLevel
if ErrorLevel
MsgBox Could not open "%FileDir%\%FileName%".
ExitApp
}
}
return
New:
Gui, Destroy
Poll:=0
Advise:=0
Server:="RSLinx"
Log:= A_StartMenu . "\Programs\DDE2File2\Logs\Default\Default.xls"
New:=1
Gosub, CreateGui
Gosub, ShowGui
SB_SetText("Config Mode")
Return
;==================================================================================================================
;=================================================Run existing instance============================================
;==================================================================================================================
RunInstance:
Loop, 2 ;Check Parameters
{
Param%A_Index%:=%A_Index%
If !FileExist(Param%A_Index%)
{
If A_Index = 1
{
INI:= Param%A_Index%
MsgBox, 4144, File Parameter Error, Parameter %A_Index% is not a valid file. Please check the following file exists.`n`n%INI%
ExitApp
}
If A_Index = 2
{
Log:= Param%A_Index%
SplitPath, Log, OutFileName, OutDir, OutExt, OutNameNoExt, OutDrive
FileCreateDir, %OutDir%
If Errorlevel
{
MsgBox, 4112, Error, There was a problem creating the log file directory. Please check the drive exists and that you have sufficient security access.
ExitApp
}
}
}
If A_Index = 1
INI:= Param%A_Index%
If A_Index = 2
Log:= Param%A_Index%
}
Goto, RunConfig
DataPoints:
New:=1
Gui, Destroy
DDE_Unadvise(Trigger)
WinName:= "DDE2File2"
;=============================================================================================================================
;===============================================Run Config==================================================================
;=============================================================================================================================
;=============================================================================================================================
RunConfig:
IniRead, Server, %INI%, DDEConfig, Server
IniRead, Topic, %INI%, DDEConfig, Topic
IniRead, Trigger, %INI%, DDEConfig, Trigger
IniRead, ScanRate, %INI%, DDEConfig, ScanRate
IniRead, Poll, %INI%, DDEConfig, Poll
IniRead, Advise, %INI%, DDEConfig, Advise
IniRead, StartUp, %INI%, DDEConfig, StartUp
IniRead, MinimizeStartUp, %INI%, DDEConfig, MinimizeStartUp
IniRead, HideStartUp, %INI%, DDEConfig, HideStartUp
IniRead, AppendTime, %INI%, DDEConfig, AppendTime
IniRead, AppendDate, %INI%, DDEConfig, AppendDate
IniRead, PrefixTime, %INI%, DDEConfig, PrefixTime
IniRead, PrefixDate, %INI%, DDEConfig, PrefixDate
Gosub, CreateGui
Gosub, ShowGui
If New
Return
Gosub, Test
If Connected = 1
{
If Advise = 1
DDE_ADVISE(Trigger)
If Poll = 1
SetTimer, CheckTrigger, %ScanRate%
}
Return
CreateGui:
DataPoints := ""
Loop,
{
IniRead, Tag%A_Index%, %INI%, DDETags, Tag%A_Index%
If Tag%A_Index% = Error
{
Count:= A_Index-1
Break
}
If Tag%A_Index% =
{
Count:= A_Index-1
Break
}
DataPoints .= Tag%A_Index% . "`n"
}
Gui, Add, GroupBox, x10 y10 h40 w310, DDE Server
If !New
Gui, Add, Edit, +ReadOnly vEdit1 xp+5 yp+13 w300, %Server%
If New
Gui, Add, Edit, vEdit1 xp+5 yp+13 w300, %Server%
Gui, Add, GroupBox, x10 y55 h40 w310, DDE Topic
If !New
Gui, Add, Edit, +ReadOnly vEdit2 xp+5 yp+13 w300, %Topic%
If New
Gui, Add, Edit, vEdit2 xp+5 yp+13 w300, %Topic%
Gui, Add, GroupBox, x10 y100 h40 w310, Trigger
If !New
Gui, Add, Edit, +ReadOnly vEdit3 xp+5 yp+13 w300, %Trigger%
If New
Gui, Add, Edit, vEdit3 xp+5 yp+13 w300, %Trigger%
Gui, Add, GroupBox, x10 y180 h65 w280, Data Collection
Gui, Add, CheckBox, gCheckBox vPoll Checked%Poll% xp+10 yp+20, Poll Trigger
If !New
Gui, Add, Edit, vScanRate +ReadOnly x+5 yp-5 w50, %ScanRate%
If New
Gui, Add, Edit, vScanRate x+5 yp-5 w50, %ScanRate%
Gui, Add, Text, x+2 yp, ms
Gui, Add, CheckBox, gCheckBox vAdvise Checked%Advise% x20 y+15, Advise On Change
Gui, Add, GroupBox, x10 y+15 h65 w280, Start Up Options
Gui, Add, CheckBox, gCheckBox vStartUp Checked%StartUp% xp+10 yp+20, Run On Start Up
Gui, Add, CheckBox, gCheckBox vMinimizeStartUp Checked%MinimizeStartUp% xp yp+20, Minimize on Start Up
Gui, Add, CheckBox, gCheckBox vHideStartUp Checked%HideStartUp% x+20 yp, Hide on Start Up
Gui, Add, GroupBox, x330 y180 h65 w300, Log File
gui, font, s6, Verdana ; Set 10-point Verdana.
Gui, Add, Edit, +Wrap +ReadOnly xp+10 yp+20 r3 w280 vRecord,
gui, font,
Gui, Add, GroupBox, xp-10 y+13 h65 w300, Log File Options
Gui, Add, CheckBox, gCheckBox vAppendTime Checked%AppendTime% xp+10 yp+20, Append Time
Gui, Add, CheckBox, gCheckBox vAppendDate Checked%AppendDate% xp+100 yp, Append Date
Gui, Add, CheckBox, gCheckBox vPrefixTime Checked%PrefixTime% xp-100 yp+20, Prefix Time
Gui, Add, CheckBox, gCheckBox vPrefixDate Checked%PrefixDate% xp+100 yp, Prefix Date
Gui, Add, Text, x10 y325, Log File Path:%A_Space%
If !New
Gui, Add, Edit, +ReadOnly xp yp-5 r1 w620 vLog, %Log%
If New
Gui, Add, Edit, xp yp-5 r1 w590 vLog, %Log%
If New
Gui, Add, Button, gViewLog x+2 yp h20 w30, Log
Gui, Add, GroupBox, x330 y10 h165 w300, Data Points
If !New
Gui, Add, Edit, +ReadOnly xp+10 yp+15 r10 w280 vDataPoints, %DataPoints%
If New
Gui, Add, Edit, xp+10 yp+15 r10 w280 vDataPoints, %DataPoints%
Gui, Add, Picture, vBackground x0 y345 , %A_StartMenu%\Programs\DDE2File2\Images\Data-Binding1.png
If !New
{
GuiControl, Disable, Poll
GuiControl, Disable, Advise
GuiControl, Disable, StartUp
GuiControl, Disable, MinimizeStartUp
GuiControl, Disable, HideStartUp
GuiControl, Disable, AppendTime
GuiControl, Disable, AppendDate
GuiControl, Disable, PrefixTime
GuiControl, Disable, PrefixDate
Gui, Add, Button, gDataPoints x10 y145 w300, Enter Design Mode
}
If New
{
Gui, Add, Button, gSaveandRun x10 y145 w300, Save and Run
Menu, FileMenu, Add, Save And Run All, SaveandRunAll
Menu, FileMenu, Add, Save, Save
Menu, FileMenu, Add, Exit, Exit
Menu, EditMenu, Add, DDE2File2 Configuration, DataPoints
Menu, HelpMenu, Add, DDE Help, Help
Menu, AboutMenu, Add, About, About
Menu, MyMenuBar, Add, File, :FileMenu
Menu, MyMenuBar, Add, Edit, :EditMenu
Menu, MyMenuBar, Add, Help, :HelpMenu
Menu, MyMenuBar, Add, About, :AboutMenu
Gui, Menu, MyMenuBar
}
Menu, Tray, NoStandard
;Menu, Tray, Add, Restore
;Menu, Tray, Add, Exit
Gui, Add, StatusBar,,
SB_SetParts(100,140,100,230,80)
SB_SetText("Testing Connection....", 1)
SB_SetText(ScanRate . "ms", 3)
WinName:= WinName . " - " . Topic
If WinExist(WinName)
{
WinKill, % WinName
}
Return
ShowGui:
Gui, Submit, NoHide
If New
{
Gui, Show, h605 w640, %WinName%
Goto, End
}
If (HideStartUp = 1)
{
Gui, Show, Hide h605 w640, %WinName%
Goto, End
}
If (MinimizeStartUp = 1)
{
Gui, Show, x2000 y2000 h605 w640, %WinName%
Goto, End
}
Gui, Show, h605 w640, %WinName%
End:
Gui, +LastFound
hWin := WinExist()
Menu, Tray, Tip, %WinName%`n`n
SetTimer, ShowCPU, 1000
Return
CheckTrigger:
If New
Return
SetTimer, CheckTrigger, Off
Value:= Read(Trigger)
Sleep, 50
If Value = 1
{
Write(Trigger, 0)
SetTimer, AppendFile, 20
}
If Value = "Read Error -1"
{
MsgBox, "Read Error -1"
Gosub, Test
Return
}
If Poll = 1
SetTimer, CheckTrigger, %ScanRate%
Return
AppendFile:
SetTimer, AppendFile, Off
FileLine:=
Loop, %Count%
{
Reading%A_Index%:= Read(Tag%A_Index%)
FileLine.= Reading%A_Index% . A_Tab
}
If PrefixDate
FileLine:= A_MM . "\" . A_DD . "\" . A_YYYY . A_Tab . FileLine
If PrefixTime
FileLine:= A_Hour . ":" . A_Min . ":" . A_Sec . A_Tab . FileLine
If AppendTime
FileLine:= FileLine . A_Hour . ":" . A_Min . ":" . A_Sec . A_Tab
If AppendDate
FileLine:= FileLine . A_MM . "\" . A_DD . "\" . A_YYYY . A_Tab
FileLine:= FileLine . "`n"
SplitPath, Log, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
If !OutExtension
{
OutExtension = txt
Path:= Log . "\" . Topic . "\" . Topic
}
If OutExtension
{
Path:= OutDir . "\" . Topic
}
FileAppend, %FileLine%, %Path%_DATA_%A_MM%%A_DD%%A_YYYY%.%OutExtension%
If ErrorLevel
{
TempPath=%Path%_DATA_%A_MM%%A_DD%%A_YYYY%.%OutExtension%
SplitPath, TempPath, OutFileName1, OutDir1, OutExtension1, OutNameNoExt1, OutDrive1
FileCreateDir, %OutDir1%
If ErrorLevel
MsgBox, Could not create folder.
Else
FileAppend, %FileLine%, %Path%_DATA_%A_MM%%A_DD%%A_YYYY%.%OutExtension%
}
GuiControl,, Record, %FileLine%
GuiControl,, Log, %Path%_DATA_%A_MM%%A_DD%%A_YYYY%.%OutExtension%
LogFile= %Path%_DATA_%A_MM%%A_DD%%A_YYYY%.%OutExtension%
Return
Read(TagName){
global
;=============Read Data from Boolean Tag======================
DDE_Request_Result := DDE_Request(TagName . ",L1,C1", Connection_ID)
If DDE_Request_Result =
{
SB_SetText(TagName . " = ???",2)
DDE_Request_Result = "Read Error -1"
Return DDE_Request_Result
}
Else
{
SB_SetText(TagName . " = " . DDE_Request_Result,2)
SB_SetText(A_Hour . ":" . A_Min . ":" . A_Sec . " " . Month . "/" . Day . "/" . Year,3)
If Poll = 1
SB_SetText("Collection Mode = Polling at " . ScanRate . "ms" ,4)
If Advise = 1
SB_SetText("Collection Mode = Waiting For DDE Message" ,4)
Return DDE_Request_Result
}
}
Write(TagName, Val){
global
SB_SetText("Writing " . Val . " to " . TagName,2)
SB_SetText(A_Hour . ":" . A_Min . ":" . A_Sec . " " . Month . "/" . Day . "/" . Year,3)
If Poll = 1
SB_SetText("Collection Mode = Polling at " . ScanRate ,4)
If Advise = 1
SB_SetText("Collection Mode = Waiting For DDE Message" ,4)
DDE_Poke(TagName . ",L1,C1", Val, Connection_ID)
Return
}
Return
AHK_NOTIFYICON(wParam, lParam)
{
If (lParam = 0x203) ; WM_LBUTTONDBLCLK
{
SetTimer, Restore, 20
return 1 ; In case of load failure.
}
}
GetProcessTimes( PID=0 ) {
Static oldKrnlTime, oldUserTime
Static newKrnlTime, newUserTime
oldKrnlTime := newKrnlTime
oldUserTime := newUserTime
hProc := DllCall("OpenProcess", "Uint", 0x400, "int", 0, "Uint", pid)
DllCall("GetProcessTimes", "Uint", hProc, "int64P", CreationTime, "int64P"
, ExitTime, "int64P", newKrnlTime, "int64P", newUserTime)
DllCall("CloseHandle", "Uint", hProc)
Return (newKrnlTime-oldKrnlTime + newUserTime-oldUserTime)/10000000 * 100
}
ShowCPU:
SB_SetText("CPU= " . Round( GetProcessTimes(PID),1) . "%" ,5)
Return
SaveandRun:
SaveAndRun:=1
Save:
If !Edit2
{
MsgBox % "Please Type A Name for the Topic"
Return
}
INI:= A_StartMenu . "\Programs\DDE2File2\Config Files\" . EDIT2 . ".ini"
Gui, Submit, NoHide
IniDelete, %INI%, DDEConfig
IniWrite, %Edit1%, %INI%, DDEConfig, Server
IniWrite, %Edit2%, %INI%, DDEConfig, Topic
IniWrite, %Edit3%, %INI%, DDEConfig, Trigger
IniWrite, %ScanRate%, %INI%, DDEConfig, ScanRate
IniWrite, %Poll%, %INI%, DDEConfig, Poll
IniWrite, %Advise%, %INI%, DDEConfig, Advise
IniWrite, %StartUp%, %INI%, DDEConfig, StartUp
IniWrite, %MinimizeStartUp%, %INI%, DDEConfig, MinimizeStartUp
IniWrite, %HideStartUp%, %INI%, DDEConfig, HideStartUp
IniWrite, %Log%, %INI%, DDEConfig, Log
IniWrite, %AppendTime%, %INI%, DDEConfig, AppendTime
IniWrite, %AppendDate%, %INI%, DDEConfig, AppendDate
IniWrite, %PrefixTime%, %INI%, DDEConfig, PrefixTime
IniWrite, %PrefixDate%, %INI%, DDEConfig, PrefixDate
IniDelete, %INI%, DDETags
Loop, Parse, DataPoints, `n`r
{
If A_LoopField
IniWrite, %A_LoopField%, %INI%, DDETags, Tag%A_Index%
}
If Edit2
{
FileDelete, %A_ScriptFullPath%, %A_StartMenu%\Programs\DDE2File2\RunTime\%EDIT2%.lnk
FileCreateShortcut, %A_ScriptFullPath%, %A_StartMenu%\Programs\DDE2File2\RunTime\%EDIT2%.lnk,, "%INI%" "%LOG%",, ;iconfile
}
If SaveAndRun
{
Run, %A_StartMenu%\Programs\DDE2File2\RunTime\%EDIT2%.lnk
ExitApp
}
Return
CheckBox:
Gui, Submit, NoHide
If A_GuiControl = Poll
{
If Poll = 1
{
GuiControl,, Advise, 0
Advise:= 0
Return
}
If Poll = 0
{
GuiControl,, Advise, 1
Advise:= 1
Return
}
}
If A_GuiControl = Advise
{
If Advise = 1
{
GuiControl,, Poll, 0
Return
}
If Advise = 0
{
GuiControl,, Poll, 1
Return
}
}
If A_GuiControl = HideStartUp
{
Return
}
If A_GuiControl = MinimizeStartUp
{
Return
}
If A_GuiControl = StartUp
{
Loop, %A_StartMenu%\Programs\DDE2File2\RunTime\*.*
{
If A_LoopFileName = %Edit2%
{
Index := 60000 + (A_Index*2000)
Break
}
}
Startahk=
(
Sleep, %Index%
DetectHiddenWindows, On
SetTitleMatchMode, 2
Loop,
{
IfWinExist, DDE2File2 - %Edit2% ahk_class AutoHotkeyGUI
WinKill, DDE2File2 - %Edit2% ahk_class AutoHotkeyGUI
Else
Break
}
IfExist, %A_StartMenu%\Programs\DDE2File2\RunTime\%EDIT2%.lnk
Run, %A_StartMenu%\Programs\DDE2File2\RunTime\%EDIT2%.lnk,, %Options%
ExitApp
)
If StartUp = 1
{
FileDelete, %A_StartMenu%\Programs\StartUp\DDE %EDIT2%.ahk
FileAppend, %StartAhk%, %A_StartMenu%\Programs\StartUp\DDE %EDIT2%.ahk
}
If StartUp = 0
FileDelete, %A_StartMenu%\Programs\StartUp\DDE %EDIT2%.ahk
}
If A_GuiControl = AppendTime
{
If AppendTime = 1
{
GuiControl,, PrefixTime, 0
Return
}
If AppendTime = 0
{
Return
}
}
If A_GuiControl = PrefixTime
{
If PrefixTime = 1
{
GuiControl,, AppendTime, 0
Return
}
If PrefixTime = 0
{
Return
}
}
If A_GuiControl = AppendDate
{
If AppendDate = 1
{
GuiControl,, PrefixDate, 0
Return
}
If AppendDate = 0
{
Return
}
}
If A_GuiControl = PrefixDate
{
If PrefixDate = 1
{
GuiControl,, AppendDate, 0
Return
}
If PrefixDate = 0
{
Return
}
}
Return
ViewLog:
FileSelectFolder, Temp, C:\, 3, Select Log Folder
If ErrorLevel
Return
IfExist, %Temp%
{
Log:=Temp
GuiControl,, Log, %Log%
}
Return
Test:
SB_SetText("Testing Connection....")
Sleep, 500
Connection_ID := DDE_Connect(Edit1, Edit2)
If !Connection_ID
{
GuiControl,, Status, Connection Status : FAIL
SB_SetText("Connection Failed")
Connected := 0
}
Else
{
GuiControl,, Status, Connection Status : PASS
SB_SetText("Connection Passed")
Connected := 1
}
Return
Help:
SetTimer, HelpMsg, 1
Return
HelpMsg:
SetTimer, HelpMsg, Off
MsgBox, 4160, %WinName% Help, %Help%
Return
About:
SetTimer,AboutMsg, 1
Return
AboutMsg:
SetTimer,AboutMsg, Off
MsgBox, 4160, About %WinName%, %About%
Return
GuiSize:
If A_EventInfo = 1
Gui, Show, Hide h605 w640, %WinName%
Return
Restore:
SetTimer, Restore, Off
WinShow, %WinName%
WinMove, %WinName%,,200,50
WinActivate, %WinName%
Return
GuiClose:
Exit:
DDE_UNADVISE(Trigger)
DDE_Kill()
ExitApp
SaveAndRunall:
Gosub, Save
Run, %A_StartMenu%\Programs\DDE2File2\Bin\StartAll.ahk
Return
/* ======================================================
Step 1: Connect to a DDE Server.
DDE_connection_Number1 := DDE_Connect("NAME_OF_DDE_SERVER","TOPIC_REQUESTED", OPTIONAL_CONNECTION_NUMBER_1_TO_20, OPTIONAL_HANDLE_OF_DDE_SERVER_WINDOW )
if you have more than one connection, you use the "DDE_connection_Number1", "DDE_connection_Number2" var to designate in Requests, Pokes, etc..
You can have up to 20 connections WITH THE SAME SERVER ON THE SAME TOPIC.
You do not need a new connection# for different Servers or Different topics!!!!
Step 2: Send a command:
result := DDE_Execute("[COMMAND YOU WANT TO SEND]", OPTIONAL_CONNECTION_ID_EG_DDE_connection_Number, OPTIONAL_DELAY_NUMBER)
note: you do not need to pay attention or use connection ID's unless you have multiple connections. THE LAST ACCESSED CONNECTION IS THE DEFAULT, SO DOES NOT NEED TO BE REDESIGNATED, UNLESS YOU WANT TO CHANGE IT.
also can:
result := DDE_Request("[COMMAND]", OPTIONAL_connection_ID, OPTIONAL_DELAY)
usually_not_one := DDE_Poke("[COMMAND]", "[DATASET FOR COMMAND]", OPTIONAL_connection_ID, OPTIONAL_DELAY)
Step 3: (when you're all done!) Terminate Connection
DDE_KILL("SERVER_NAME","TOPIC", OPTIONAL_CONNECTION_NUMBER)
DDE_KILL() = kills all open connectinos.
Super-Powers: (in additional to multiple connections to same server&topic)
1. You don't need to track open servers & topics, all done for you.
DDE_Connect(Server,Topic) to existing open topic on that server returns you the Conversation_ID contained in the "DDE_connection_Number1" variable in example above. ie. Connection_X := DDE_Connect(Server,Topic) fills Connection_X with the conversation ID for taht conversation. Can have multiple conversationID's for same topic/server if made on different DDE connection ports: eg. DDE_Connect(Server,Topic,2), etc.
2. BATCH MODE!
uses following Global Bars:
__DDE_Advise_Use = Respond to Null Messages from DDE_ADVISE FUNCTION
__DDE_Answer_Table = holds your batch responses. (You can clear & modify it.. but best to do it in a CRITICAL segment!! so not get accidental conflict with new data recepiet)
__DDE_BatchMode = Set this to use batch mode!!
if set, you do not get Answer := Request('[xxxx') instead answer goes only to answer table. IE NO DELAY WAITING FOR ANSWER!!!!!!
__DDE_Use_Answer_Table = you DO get an answer, and you ALSO build an answer table
__DDE_SafeMode = for multiple connection used at same time, etc. if set TRACKS MESSAGE INCOMING DATA AGAINST INTENDED CONNECTION and SERVER. This is **IMPORTANT** where you have data comming in from multiple servers and/or connections in NON-BATCH mode.
it makes sure that the answer you get actually comes from the CONNECTION and the SERVER you are expecting it to be from.
usage note: [and this is well beyond basic use.. if you want to control word, etc. likely this is not something you even need to read] __DDE_Use_Answer_Table and __DDE_SafeMode should be normal operation mode for multiple active servers & connections with much async data exchange.
if you seek specific response to command X... all other's will be either qued, or saved in the answer table....
3. Debug AHK stuff:
__DDE_UseAHKMessages set to use AHK sendmessage in place of DLL,
will cause crash (eventually)....
option to allow debugging... or
for those bored with too much stability....
*/ ;======================================================
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HERE STARTS THE ACTUAL DDE WRAPPER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;------------------ DDE CLIENT WRAPPER ---------------------------------------
DDE_Connect(DDE_Server,DDE_Topic = "", DDEConnection_ = 0, DDE_Init_To = 0xFFFF ) {
; DDE_Init_To = 0 to test to see if connection exists & activate as default
global
static DDE_Assigned_Messages
local nDDE_Topic, nAppli, Conversation, hAH , sDDE_Topic, sDDE_Server ; , hAHK
DDE_Connection_ReNumber(DDEConnection_)
if (DDE_Topic = "")
DDE_Topic := DDE_Server
if InStr(DDE_Topic . DDE_Server, "\E" , 1) {
sDDE_Topic := regexreplace(DDE_Topic,"\\E","\E\\E\Q")
sDDE_Server := regexreplace(DDE_Server,"\\E","\E\\E\Q")
} else {
sDDE_Topic = %DDE_Topic%
sDDE_Server = %DDE_Server%
}
DDE_Topic_List_Matchme :=
if regexmatch( __DDEM_DDE_Topic_List
, "\n\Q"
. sDDE_Topic
. "|"
. sDDE_Server
. "|"
. DDEConnection_
. "|\E"
. "(?<DDE_Server_ID>[^|]++)"
. "\|"
. "(?<Client_ID>[^`n]++)", __DDEM_ ) {
__Conversation_BASE := DDEConnection_
. "|"
. DDE_HEX(__DDEM_DDE_Server_ID)
. "|"
. DDE_HEX(__DDEM_Client_ID)
return __Conversation_BASE
} else if !DDE_Init_To
return
if __DDE_UseAHKMessages
DetectHiddenWindows, On
if !DDE_Assigned_Messages {
CF_TEXT := 1
WM_DDE_INITIATE := 0x3E0
WM_DDE_TERMINATE:= 0x3E1
WM_DDE_ADVISE := 0x3E2
WM_DDE_UNADVISE := 0x3E3
WM_DDE_ACK := 0x3E4
WM_DDE_DATA := 0x3E5
WM_DDE_REQUEST := 0x3E6
WM_DDE_POKE := 0x3E7
WM_DDE_EXECUTE := 0x3E8
__DDE_TableDiv := "`n$[_DDE_TABLE_DIV_]$"
__DDE_NULL := "$[_DDE_NULL_]$"
OnMessage(WM_DDE_ACK , "DDE_ACK")
OnMessage(WM_DDE_DATA, "DDE_DATA")
DDE_Assigned_Messages = 1
}
if !regexmatch(__DDEConnection_Table , "x)\n\Q"
. DDEConnection_
. "|\E"
. "(?<K>[^`n]++)", hAH )
{
Gui, %DDEConnection_%: +LastFound
Gui, %DDEConnection_%: Show, hide w1 h1 ,__DDEConnection_%DDEConnection_%
hAHK := WinExist()
__DDEConnection_Table .= "`n" . DDEConnection_ . "|" . DDE_HEX(hAHK) ; msgbox %
}
Ack_W =
nAppli := DllCall("GlobalAddAtom", "str", DDE_Server, "Ushort")
nDDE_Topic := DllCall("GlobalAddAtom", "str", DDE_Topic, "Ushort")
initWait := 120000
loop 10 {
sleep 500
if !__DDE_UseAHKMessages
DllCall("SendMessage", "UInt", DDE_Init_To, "UInt", WM_DDE_INITIATE , "UInt", hAHK , "UInt", nAppli | nDDE_Topic << 16)
else
SendMessage, WM_DDE_INITIATE, hAHK, nAppli | nDDE_Topic << 16,, ahk_id %DDE_Init_To%
;;
if (__DDEM_DDE_Server_ID := DDE_WaitA(hAHK, initWait))
break
}
DllCall("DeleteAtom", "Ushort", nAppli)
DllCall("DeleteAtom", "Ushort", nDDE_Topic)
if !(__DDEM_DDE_Server_ID)
return ( DDE__Tooltips(" ++DDE INITIALIZATION ERROR " . DDE_Topic . hAHK . "++ " , 6000, 4) * 0)
if !(__DDEM_Client_ID := Ack_Hwnd) { ; hAHK ; Ack_Hwnd
__DDEM_Client_ID := DDE_HEX(hAHK)
DDE__Tooltips("++DDE CLIENT HANDLE INITIALIZATION ERROR " . hAHK . " ++" , 3000, 3)
}
Conversation :=DDEConnection_
. "|"
. DDE_HEX(__DDEM_DDE_Server_ID)
. "|"
. DDE_HEX(__DDEM_Client_ID)
__DDEM_DDE_Topic_List .= "`n"
. DDE_Topic
. "|"
. DDE_Server
. "|"
. Conversation
Return (__Conversation_BASE := Conversation )
}
; :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DDE_Select( byref Conversation) {
global
if ( Conversation or (Conversation := __Conversation_BASE) ) and Regexmatch(Conversation, "^(?<Connection>[^|]++)\|(?<__DDE_Server_ID>[^|]++)\|(?<Client_ID>.++)$", __DDEM_)
return 1
}
DDE_Connection_ReNumber(byref DDEConnection) {
if !DDEConnection or (DDEConnection < 1) or (DDEConnection > 21)
DDEConnection := 20
else
DDEConnection += 20
}
DDE_Wait(byRef Var, max = 120000) {
loop %max% {
if (Var <> "")
break
AX++
}
if ( AX < MAX ) ; ie. loop count
return Var ; A
}
DDE_WaitS(byRef VarKey, KeyValue, max = 120000) {
loop %max% {
if (VarKey = KeyValue)
break
AX++
}
if ( AX < MAX ) ; ie. loop count
return 1
}
DDE_WaitA(Var, max = 60000) {
global Ack_Hwnd,Ack_W
; max =60000
loop %max% { ; 1200000 {
if (Var = Ack_Hwnd)
break
AX++
}
if ( AX < MAX ) ; ie. loop count
return Ack_W
}
DDE_Request(Item, Conversation = "", delay = 90000) {
local hItem
if !DDE_Select( Conversation)
return DDE__Tooltips(" DDE UNDEFINED DDE REQUEST ERROR " . Conversation . " ** " , 6000, 3)
hItem := DllCall("GlobalAddAtom", "str", Item, "Ushort")
DDE__myAnswer =
DDE__myAnswerKey =
DDE__Data_Title =
if !__DDE_UseAHKMessages
DllCall("PostMessage", "UInt", __DDEM___DDE_Server_ID, "UInt", WM_DDE_REQUEST , "UInt", __DDEM_Client_ID , "UInt", CF_TEXT | hItem << 16)
else
PostMessage, WM_DDE_REQUEST, __DDEM_Client_ID, CF_TEXT | hItem << 16,, ahk_id %__DDEM___DDE_Server_ID%
DllCall("DeleteAtom", "Ushort", hItem)
if __DDE_BatchMode ; ie. no waiting... just >> __DDE_Use_Answer_Table
return
If DDE_SafeMode
return DDE_WaitS(DDE__myAnswerKey, __DDEM_Client_ID . "|" . __DDEM___DDE_Server_ID, delay) ? DDE__myAnswer : ""
else if (DDE_Wait(DDE__myAnswer, delay) = "$[_~~::NULL::~~_]$")
return
return DDE__myAnswer
}
DDE_Poke(item= "", data = "", Conversation = "", delay = 20000 ) {
Global
local hItem,hData,pData, lParam
if !DDE_Select( Conversation)
return DDE__Tooltips(" DDE UNDEFINED DDE POKE ERROR " . Conversation . " ** " , 6000, 3)
DDE__myAnswer =
Ack_Hwnd =
DDE__Data_Title =
If SubStr(Data, -1) <> "`r`n"
Data .= "`r`n"
hItem := DllCall("GlobalAddAtom", "str", Item, "Ushort")
hData := DllCall("GlobalAlloc", "Uint", 0x0002, "Uint", 2+2+StrLen(Data)+1)
pData := DllCall("GlobalLock" , "Uint", hData)
DllCall("ntdll\RtlFillMemoryUlong", "Uint", pData, "Uint", 4, "Uint", 1<<13|1<<16)
DllCall("lstrcpy", "Uint", pData+4, "Uint",&Data)
DllCall("GlobalUnlock", "Uint", hData)
lParam := DllCall("PackDDElParam", "Uint", WM_DDE_POKE, "Uint", hData, "Uint", hItem)
if !__DDE_UseAHKMessages
DllCall("PostMessage", "UInt", __DDEM___DDE_Server_ID, "UInt", WM_DDE_POKE , "UInt", __DDEM_Client_ID , "UInt", lParam)
else
PostMessage, WM_DDE_POKE, __DDEM_Client_ID, lParam,, ahk_id %__DDEM___DDE_Server_ID%
If ErrorLevel
{
DllCall("DeleteAtom", "Ushort", hItem)
; DllCall("GlobalFree", "Uint" , hData)
; DllCall("FreeDDElParam", "Uint", WM_DDE_POKE, "Uint", lParam)
}
return DDE_WaitA(__DDEM_Client_ID, delay)
}
DDE_Execute(item, Conversation = "", delay = 60000) {
Global
local hCmd, pCmd
; WM_DDE_EXECUTE,__DDEM_Client_ID,__DDEM___DDE_Server_ID, DDE__myAnswer, Ack_Hwnd
if !DDE_Select( Conversation)
return DDE__Tooltips(" UNDEFINED DDE EXECUTE ERROR " . Conversation . " ** " , 6000, 3)
hCmd := DllCall("GlobalAlloc", "Uint", 0x0002, "Uint", StrLen(item)+1)
pCmd := DllCall("GlobalLock" , "Uint", hCmd)
DllCall("lstrcpy", "Uint", pCmd, "str",item)
DllCall("GlobalUnlock", "Uint", hCmd)
DDE__myAnswer =
Ack_Hwnd =
DDE__Data_Title =
if !__DDE_UseAHKMessages
DllCall("PostMessage", "UInt", __DDEM___DDE_Server_ID, "UInt", WM_DDE_EXECUTE , "UInt", __DDEM_Client_ID , "UInt", hCmd)
else
PostMessage, WM_DDE_EXECUTE, __DDEM_Client_ID, hCmd,, ahk_id %__DDEM___DDE_Server_ID%
;If ErrorLevel
; DllCall("GlobalFree", "Uint", hCmd)
return DDE_WaitA(__DDEM_Client_ID, delay )
}
DDE_ADVISE(item= "", Conversation = "") {
global
local hItem, hAdvStruct, pAdvStruct, lParam
if !DDE_Select( Conversation)
return DDE__Tooltips(" DDE UNDEFINED DDE POKE ERROR " . Conversation . " ** " , 6000, 3)
hItem := DllCall("GlobalAddAtom", "str", Item, "Ushort")
hAdvStruct := DllCall("GlobalAlloc", "Uint", 0x0002, "Uint", 2+2+2+2)
pAdvStruct := DllCall("GlobalLock" , "Uint", hAdvStruct)
DllCall("ntdll\RtlFillMemoryUlong", "Uint", pAdvStruct, "Uint", 8, "Uint", 0<<14|0<<15|CF_TEXT<<16)
DllCall("GlobalUnlock", "Uint", hAdvStruct)
lParam := DllCall("PackDDElParam", "Uint", WM_DDE_ADVISE, "Uint", hAdvStruct, "Uint", hItem)
if !__DDE_UseAHKMessages
DllCall("PostMessage", "UInt", __DDEM___DDE_Server_ID, "UInt", WM_DDE_ADVISE , "UInt", __DDEM_Client_ID , "UInt", lParam)
else
PostMessage, WM_DDE_ADVISE, __DDEM_Client_ID, lParam,, ahk_id %__DDEM___DDE_Server_ID%
If ErrorLevel
{
DllCall("DeleteAtom", "Ushort", hItem)
DllCall("GlobalFree", "Uint" , hAdvStruct)
DllCall("FreeDDElParam", "Uint", WM_DDE_ADVISE, "Uint", lParam)
}
return
}
DDE_UNADVISE(item= "", Conversation = "") {
global
local hItem, lParam
if !DDE_Select( Conversation)
return DDE__Tooltips(" DDE UNDEFINED DDE POKE ERROR " . Conversation . " ** " , 6000, 3)
hItem := DllCall("GlobalAddAtom", "str", Item, "Ushort")
lParam := DllCall("PackDDElParam", "Uint", WM_DDE_UNADVISE, "Uint", CF_TEXT, "Uint", hItem)
if !__DDE_UseAHKMessages
DllCall("PostMessage", "UInt", __DDEM___DDE_Server_ID, "UInt", WM_DDE_UNADVISE , "UInt", __DDEM_Client_ID , "UInt", lParam)
else
PostMessage, WM_DDE_UNADVISE, __DDEM_Client_ID, lParam,, ahk_id %__DDEM___DDE_Server_ID%
If ErrorLevel
{
DllCall("DeleteAtom", "Ushort", hItem)
DllCall("GlobalFree", "Uint" , hAdvStruct)
DllCall("FreeDDElParam", "Uint", WM_DDE_UNADVISE, "Uint", lParam)
}
return
}
DDE_ACK(wParam, LParam, MsgID, hWnd) {
Critical 24
global Ack_W,Ack_L,Ack_Hwnd,Ack_MsgID
Ack_W := wParam
Ack_L := LParam
Ack_MsgID := MsgID
Ack_Hwnd := hWnd
}
DDE_DATA(wParam, lParam, MsgID, hWnd) {
Critical 250
Global WM_DDE_ACK, DDE__myAnswer , DDE__myAnswerKey, DDE_SafeMode,__DDE_BatchMode, Data_MsgID, DDE__Data_Title , __DDE_NULL, __DDE_Answer_Table,__DDE_Use_Answer_Table, __DDE_TableDiv,__DDE_UseAHKMessages, Trigger, Advise, Count, Tag1, Tag2, Tag3, Reading1, Reading2, Reading2 ; , sInfo
nITem = "Defined!"
DllCall("UnpackDDElParam", "Uint", MsgID, "Uint", lParam, "UintP", hData, "UINTP", nItem)
DllCall( "FreeDDElParam", "Uint", MsgID, "Uint", lParam)
pData := DllCall("GlobalLock", "Uint", hData)
VarSetCapacity(sInfo, DllCall("lstrlen", "Uint", pData+4))
DllCall("lstrcpy", "str", sInfo, "Uint", pData+4)
DllCall("GlobalUnlock", "Uint", hData)
If (*(pData+1) & 0x20)
DllCall("GlobalFree", "Uint", hData)
If (*(pData+1) & 0x80) {
if !__DDE_UseAHKMessages
DllCall("PostMessage", "UInt", wParam, "UInt", WM_DDE_ACK , "UInt", hWnd , "UInt", 0x80 << 8 | nItem << 16)
else {
DetectHiddenWindows, On
PostMessage, WM_DDE_ACK, hWnd, 0x80 << 8 | nItem << 16,, ahk_id %wParam%
}
}
Data_MsgID := MsgID
DDE__Data_Title := "Undefined!"
DllCall("GlobalGetAtomName", "UintP", nItem, "STR", DDE__Data_Title, "SHORT", 512)
DDE__myAnswer := sInfo
if (DDE__myAnswer = "") and !DDE_SafeMode
DDE__myAnswer := __DDE_NULL
DDE__myAnswerKey := DDE_HEX(hWnd) . "|" . DDE_HEX(wParam)
if ( __DDE_BatchMode or __DDE_Use_Answer_Table )
__DDE_Answer_Table .= __DDE_TableDiv
. DDE__myAnswerKey
. "|"
. DDE__Data_Title
. "|"
. DDE__myAnswer
;MsgBox % __DDE_TableDiv
. DDE__myAnswerKey
. "|"
. DDE__Data_Title
. "|"
. DDE__myAnswer
If Advise = 1
{
If DDE__myAnswer = 1
{
Write(Trigger, 0)
SetTimer, AppendFile, 20
}
}
return 0
}
DDE_KILL(__DDE_Server="",__DDE_Topic = "", __DDE_DDEConnection_ = 0) {
local s__DDE_Topic,s__DDE_Server
DDE_Connection_ReNumber( __DDE_DDEConnection_)
if (__DDE_Server = "") {
Loop, Parse, __DDEM_DDE_Topic_List ,`n
{
if !A_loopfield
continue
if regexmatch(A_Loopfield, "(?<__DDE_Topic>[^|]++)"
. "\|"
. "(?<__DDE_Server>[^|]++)"
. "\|"
. "(?<DDEConnection>[^|]++)",Kill_) and (!__DDE_No_mass_Termination)
DDE_KILL(Kill___DDE_Server,Kill___DDE_Topic, Kill_DDEConnection - 20)
}
__DDEM_DDE_Topic_List =
__DDEConnection_Table =
return
}
if (__DDE_Topic = "")
__DDE_Topic := __DDE_Server
if InStr(__DDE_Topic . __DDE_Server, "\E" , 1) {
s__DDE_Topic := regexreplace(__DDE_Topic,"\\E","\E\\E\Q")
s__DDE_Server := regexreplace(__DDE_Server,"\\E","\E\\E\Q")
} else {
s__DDE_Topic = %__DDE_Topic%
s__DDE_Server = %__DDE_Server%
}
if regexmatch(__DDEM_DDE_Topic_List
, "\n\Q"
. s__DDE_Topic
. "|"
. s__DDE_Server
. "|"
. __DDE_DDEConnection_
. "|\E"
. "(?<__DDE_Server_ID>[^|]++)"
. "\|"
. "(?<Client_ID>[^`n]++)", __DDEM_)
__DDEM_DDE_Topic_List := regexreplace(__DDEM_DDE_Topic_List,"x)"
. "\n"
. "[^|]+" ; __DDE_Topic
. "\|"
. "[^|]+" ; __DDE_Server
. "\|"
. "[^|]+" ; any connection.. (is same id#s!!!)
. "\Q|"
. __DDEM___DDE_Server_ID
. "|"
. __DDEM_Client_ID
. "\E(?=\n|$)" , "")
if __DDE_Kill_window_on_Kill and !regexmatch(__DDEM_DDE_Topic_List, "x)"
. "\n"
. "[^|]+"
. "\|"
. "[^|]+"
. "\|\Q"
. __DDE_DDEConnection_
. "|\E" , __DDEM_)
{
__DDEConnection_Table := regexreplace(__DDEConnection_Table,"\n\Q" . __DDE_DDEConnection_ . "|\E[^`n]++","")
if ( __DDE_DDEConnection_ > 20) and ( __DDE_DDEConnection_ < 51)
Gui, %__DDE_DDEConnection_%: destroy
}
if __DDEM___DDE_Server_ID {
if !__DDE_UseAHKMessages
DllCall("PostMessage", "UInt", __DDEM___DDE_Server_ID, "UInt", WM_DDE_TERMINATE , "UInt", hAHK , "Int", 0)
else {
DetectHiddenWindows, On
PostMessage, WM_DDE_TERMINATE, hAHK , 0,,ahk_id %__DDEM___DDE_Server_ID%
}
} else
return DDE__Tooltips( " ++DDE UNDEFINED TERMINATION ERROR " . __DDE_Topic . "|" . __DDE_Server . " " . __DDE_DDEConnection_ " ** " , 4000,3)
if __DDEM_DDE_Topic_List
regexmatch(__DDEM_DDE_Topic_List, "\n"
. "[^|]++"
. "\|"
. "[^|]++"
. "\|"
. "(?<Connection_>[^|]++)"
. "\|"
. "(?<M___DDE_Server_ID>[^|]++)"
. "\|"
. "(?<M_Client_ID>[^|]++)"
. "$", DDE)
if __DDEM___DDE_Server_ID
__Conversation_BASE := __DDE_DDEConnection_
. "|"
. hex ( __DDEM___DDE_Server_ID )
. "|"
. hex ( __DDEM_Client_ID )
}
DDE_exitapp() {
DDE_KILL()
exitapp
}
DDE__Tooltips(text = "", delay = 3000, id = 1, x = "", y = "") {
if (id < 1) or (id > 5)
id := 1
delay := (delay) ? delay : 3000
;ToolTip, %text%,%x%,%y%,%id%
if text
SetTimer, DDE__RemoveToolTip%id%, %delay%
return 1 ; ie. is set
}
DDE__RemoveToolTips(id = 1) {
if (id < 1) or (id > 5)
id := 1
SetTimer, DDE__RemoveToolTip%id%, Off
ToolTip,,,,%id%
return
DDE__RemoveToolTip1:
DDE__RemoveToolTips(2)
return
DDE__RemoveToolTip2:
DDE__RemoveToolTips(2)
return
DDE__RemoveToolTip3:
DDE__RemoveToolTips(3)
return
DDE__RemoveToolTip4:
DDE__RemoveToolTips(4)
return
DDE__RemoveToolTip5:
DDE__RemoveToolTips(5)
return
}
DDE_hex(HEXME_number) {
if ((format := A_FormatInteger) != "H") {
SetFormat Integer, Hex
HEXME_number := round(HEXME_number) + 0
SetFormat Integer, %format%
return HEXME_number
} else
return HEXME_number + 0
}
;
; v1.08 [3/20/10]
;
; Copr. 2007,2010. See License.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END OF DDE CLIENT WRAPPER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;