#include <GuiListView.au3>
#include <Editconstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <ARRAY.au3>
Global $ListView_HitItem, $Listview_HitItemIndex, $Listview_HitItemSubItem, $ListView_HitItemInput,$Portnames;定义全局变量
Global Const $DBT_DEVICEARRIVAL = 0x8000 ;设备插入
Global Const $DBT_DEVICEREMOVECOMPLETE = 0x8004 ;设备移除
Global Const $DBT_DEVTYP_PORT = 0x00000003
$Form = GUICreate("端口读取工具",820, 450)
$Button=GUICtrlCreateButton('OK',727,412,80,30,-1,$WS_EX_WINDOWEDGE)
GUICtrlCreateLabel("BY-Lay Version1.0.1", 8, 420,200,40)
Local $sFont = "宋体"
GUICtrlSetFont(-1,10, 100, 2, $sFont)
GUICtrlSetState(-1,128)
GUISetFont(9, 400, 0, "微软雅黑")
$Combox=GUICtrlCreateCombo('',620,415,80,30)
GUICtrlSetTip($Combox,'选择已有的快捷方式名称,或者手动粘贴需要打开软件的路径','提示',1,1)
$Check=GUICtrlCreateCheckbox('',600,415,15,30)
GUICtrlSetTip($Check,'勾选复选框,根据端口数量打开对应软件窗口数量','提示',1,1)
GUICtrlSetData($Combox, 'QGNSS|PowerGPS|TTFF_Tester','QGNSS')
$ListView = GUICtrlCreateListView("序列(List)|端口(Port)|模块编号(ModuleId)", 8, 8, 800, 400)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES);扩展风格
$label = GUICtrlCreateLabel("", -100, -100, 1, 1)
GUISetState(@SW_SHOW)
GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 1, 500)
GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 2, 195)
Local $Ports=''
$objWMIService = objget("WinMgmts:")
$colBios = $objWMIService.ExecQuery("Select * from Win32_PNPEntity")
For $object in $colBios
$Ports &= StringMid($object.Caption,1)& @CRLF
Next
$Bports = StringRegExp($Ports,'(?m).+\(COM\d+\)$', 3)
If UBound($Bports)<1 Then
Sleep(50)
Else
For $i = 1 To UBound($Bports)
GUICtrlCreateListViewItem( $i &'|'&$Bports[$i-1]& "|", $ListView)
Next
EndIf
GUIRegisterMsg($WM_DEVICECHANGE, 'My_Message_Test')
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
Func My_Message_Test($hWnd, $Msg, $wParam, $lParam)
Switch $wParam
Case $DBT_DEVICEARRIVAL
Local $dbhdr = DllStructCreate('DWORD size;DWORD devicetype;DWORD reserved', $LParam)
If DllStructGetData($dbhdr, "devicetype") = $DBT_DEVTYP_PORT Then
Local $dbport = DllStructCreate('DWORD size;DWORD devicetype;DWORD reserved;wchar name[128]', $LParam)
$Portnames=DllStructGetData($dbport, 'name')
$WMIService = objget("WinMgmts:")
$colBios = $WMIService.ExecQuery("Select * from Win32_SerialPort")