; 电商平台聚合器 - AutoIt3版本
; 功能:打开四个电商平台并自动排列成2x2网格
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <TrayConstants.au3>
#include <Date.au3>
#include <WinAPISys.au3>
; 常量定义
Global Const $APP_NAME = "电商平台聚合器"
Global Const $APP_VERSION = "1.0"
; 电商平台配置
Global $PLATFORMS[4][3] = [ _
["京东", "https://www.jd.com", "京东"], _
["拼多多", "https://www.pinduoduo.com", "拼多多"], _
["抖音", "https://www.douyin.com", "抖音"], _
["有赞", "https://www.youzan.com", "有赞"] _
]
; 全局变量
Global $hGUI, $hStatusLabel, $hTimeLabel
Global $aBrowserHandles[4] = [0, 0, 0, 0]
Global $bRunning = True
Global $iTimer = 0
; 主程序
_Main()
Func _Main()
; 检查是否已运行
If _Singleton($APP_NAME, 1) = 0 Then
MsgBox(48, "错误", "程序已在运行中!")
Exit
EndIf
; 创建主窗口
_CreateGUI()
; 询问是否开机启动
_AskStartup()
; 打开所有网站
_OpenAllWebsites()
; 主消息循环
GUISetState(@SW_SHOW, $hGUI)
While $bRunning
; 处理窗口消息
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_Exit()
Case $GUI_EVENT_RESIZED
; 窗口大小改变时重新排列浏览器
_ArrangeBrowsers()
EndSwitch
; 更新时间显示
_UpdateTime()
Sleep(100)
WEnd
EndFunc
Func _CreateGUI()
; 获取屏幕尺寸
Local $iScreenWidth = @DesktopWidth
Local $iScreenHeight = @DesktopHeight
; 创建主窗口
$hGUI = GUICreate($APP_NAME, $iScreenWidth, $iScreenHeight, 0, 0, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
; 设置窗口样式
GUISetBkColor(0xF0F0F0)
; 创建工具栏
Local $hToolbar = GUICtrlCreateLabel("", 5, 5, $iScreenWidth - 10, 50, $SS_SUNKEN)
GUICtrlSetBkColor($hToolbar, 0xFFFFFF)
GUICtrlSetState($hToolbar, $GUI_DISABLE)
; 标题
GUICtrlCreateLabel("📱 电商平台监控中心", 15, 15, 200, 30)
GUICtrlSetFont(-1, 12, 800, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x333333)
; 刷新所有按钮
Local $hRefreshBtn = GUICtrlCreateButton("🔄 刷新所有", $iScreenWidth - 300, 15, 100, 30)
GUICtrlSetBkColor($hRefreshBtn, 0x4CAF50)
GUICtrlSetColor($hRefreshBtn, 0xFFFFFF)
GUICtrlSetFont($hRefreshBtn, 10, 400, 0, "微软雅黑")
; 全屏切换按钮
Local $hFullscreenBtn = GUICtrlCreateButton("⛶ 全屏", $iScreenWidth - 190, 15, 80, 30)
GUICtrlSetBkColor($hFullscreenBtn, 0x2196F3)
GUICtrlSetColor($hFullscreenBtn, 0xFFFFFF)
GUICtrlSetFont($hFullscreenBtn, 10, 400, 0, "微软雅黑")
; 退出按钮
Local $hExitBtn = GUICtrlCreateButton("✕ 退出", $iScreenWidth - 100, 15, 80, 30)
GUICtrlSetBkColor($hExitBtn, 0xF44336)
GUICtrlSetColor($hExitBtn, 0xFFFFFF)
GUICtrlSetFont($hExitBtn, 10, 400, 0, "微软雅黑")
; 创建状态栏
Local $hStatusBar = GUICtrlCreateLabel("", 5, $iScreenHeight - 30, $iScreenWidth - 10, 25, $SS_SUNKEN)
GUICtrlSetBkColor($hStatusBar, 0xE0E0E0)
$hStatusLabel = GUICtrlCreateLabel("就绪 | 等待打开网站...", 10, $iScreenHeight - 28, 300, 20)
GUICtrlSetColor($hStatusLabel, 0x000000)
$hTimeLabel = GUICtrlCreateLabel(_NowTime(), $iScreenWidth - 150, $iScreenHeight - 28, 140, 20, $SS_RIGHT)
GUICtrlSetColor($hTimeLabel, 0x000000)
; 创建浏览器占位框(用于视觉提示)
For $i = 0 To 3
Local $x = 5 + (($iMod2) * (($iScreenWidth - 20) / 2))
Local $y = 60 + (Floor($i / 2) * (($iScreenHeight - 100) / 2))
Local $w = ($iScreenWidth - 30) / 2
Local $h = ($iScreenHeight - 110) / 2
GUICtrlCreateLabel("正在加载 " & $PLATFORMS[$i][0] & "...", $x + 10, $y + 10, $w - 20, 30)
GUICtrlSetFont(-1, 12, 800, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x666666)
GUICtrlCreateLabel("浏览器窗口将自动嵌入此处", $x + 10, $y + 50, $w - 20, 20)
GUICtrlSetFont(-1, 9, 400, 2, "微软雅黑")
GUICtrlSetColor(-1, 0x999999)
Next
; 注册消息处理
GUIRegisterMsg($WM_SIZE, "_OnResize")
GUIRegisterMsg($WM_GETMINMAXINFO, "_OnMinMaxInfo")
EndFunc
Func _OpenAllWebsites()
_UpdateStatus("正在打开电商平台...")
; 设置默认浏览器
Local $sBrowserPath = _GetDefaultBrowserPath()
If $sBrowserPath = "" Then
MsgBox(48, "错误", "找不到默认浏览器!")
Return
EndIf
; 打开所有网站
For $i = 0 To 3
_UpdateStatus("正在打开 " & $PLATFORMS[$i][0] & "...")
ShellExecute($PLATFORMS[$i][1])
Sleep(1500) ; 等待浏览器打开
Next
; 等待所有浏览器窗口加载
_UpdateStatus("正在查找浏览器窗口...")
Sleep(3000)
; 获取浏览器窗口句柄
_GetBrowserHandles()
; 排列窗口
_ArrangeBrowsers()
_UpdateStatus("完成!所有平台已打开并排列好")
EndFunc
Func _GetBrowserHandles()
; 清空数组
For $i = 0 To 3
$aBrowserHandles[$i] = 0
Next
; 获取所有窗口
Local $aWList = WinList()
; 遍历查找浏览器窗口
Local $iFound = 0
For $i = 1 To $aWList[0][0]
Local $sTitle = $aWList[$i][0]
Local $hWnd = $aWList[$i][1]
; 跳过无效窗口
If $sTitle = "" Or Not WinExists($hWnd) Then ContinueLoop
If BitAND(WinGetState($hWnd), 2) = 0 Then ContinueLoop ; 跳过不可见窗口
; 检查是否包含平台名称
For $j = 0 To 3
If StringInStr($sTitle, $PLATFORMS[$j][2]) > 0 Then
; 找到匹配的窗口
If $aBrowserHandles[$j] = 0 Then
$aBrowserHandles[$j] = $hWnd
$iFound += 1
_UpdateStatus("找到 " & $PLATFORMS[$j][0] & " 窗口")
EndIf
ExitLoop
EndIf
Next
Next
; 如果没找到匹配的,获取最近打开的窗口
If $iFound < 4 Then
_UpdateStatus("未完全匹配,使用最近窗口...")
Local $aRecentWins = WinList()
Local $iIndex = 0
For $i = 1 To $aRecentWins[0][0]
If $iIndex >= 4 Then ExitLoop
Local $sTitle = $aRecentWins[$i][0]
Local $hWnd = $aRecentWins[$i][1]
If $sTitle <> "" And WinExists($hWnd) And $hWnd <> $hGUI Then
; 检查是否已存在
Local $bExists = False
For $j = 0 To 3
If $aBrowserHandles[$j] = $hWnd Then
$bExists = True
ExitLoop
EndIf
Next
If Not $bExists Then
$aBrowserHandles[$iIndex] = $hWnd
$iIndex += 1
EndIf
EndIf
Next
EndIf
EndFunc
Func _ArrangeBrowsers()
; 获取主窗口位置
Local $aGUIPos = WinGetPos($hGUI)
If @error Then Return
; 计算每个浏览器窗口的大小和位置
Local $iWidth = ($aGUIPos[2] - 20) / 2
Local $iHeight = ($aGUIPos[3] - 80) / 2
; 排列每个浏览器
For $i = 0 To 3
If $aBrowserHandles[$i] <> 0 And WinExists($aBrowserHandles[$i]) Then
; 计算位置
Local $iCol = Mod($i, 2)
Local $iRow = Floor($i / 2)
Local $iX = $aGUIPos[0] + 5 + ($iCol * $iWidth)
Local $iY = $aGUIPos[1] + 60 + ($iRow * $iHeight)
; 移除窗口边框和标题栏
_RemoveWindowBorder($aBrowserHandles[$i])
; 移动并调整大小
WinMove($aBrowserHandles[$i], "", $iX, $iY, $iWidth, $iHeight)
; 将窗口置顶在主窗口内
WinSetOnTop($aBrowserHandles[$i], "", 1)
EndIf
Next
EndFunc
Func _RemoveWindowBorder($hWnd)
; 移除窗口边框和标题栏
Local $iStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
$iStyle = BitAND($iStyle, BitNOT($WS_CAPTION))
$iStyle = BitAND($iStyle, BitNOT($WS_THICKFRAME))
$iStyle = BitAND($iStyle, BitNOT($WS_MINIMIZEBOX))
$iStyle = BitAND($iStyle, BitNOT($WS_MAXIMIZEBOX))
$iStyle = BitAND($iStyle, BitNOT($WS_SYSMENU))
_WinAPI_SetWindowLong($hWnd, $GWL_STYLE, $iStyle)
; 刷新窗口
_WinAPI_SetWindowPos($hWnd, 0, 0, 0, 0, 0, BitOR($SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOZORDER, $SWP_FRAMECHANGED))
EndFunc
Func _UpdateStatus($sText)
GUICtrlSetData($hStatusLabel, "状态: " & $sText)
EndFunc
Func _UpdateTime()
GUICtrlSetData($hTimeLabel, _NowTime())
EndFunc
Func _GetDefaultBrowserPath()
; 从注册表获取默认浏览器路径
Local $sBrowserPath = RegRead("HKEY_CLASSES_ROOT\http\shell\open\command", "")
If @error Then Return ""
; 提取可执行文件路径
Local $aMatches = StringRegExp($sBrowserPath, '"([^"]+)"', 1)
If @error Then Return ""
Return $aMatches[0]
EndFunc
Func _AskStartup()
Local $iAnswer = MsgBox(36, "开机启动", "是否将程序添加到开机启动?" & @CRLF & "(每次开机自动运行)")
If $iAnswer = 6 Then ; 是
_AddToStartup()
EndIf
EndFunc
Func _AddToStartup()
; 获取当前脚本路径
Local $sScriptPath = @ScriptFullPath
; 写入注册表
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", _
"EcommerceAggregator", "REG_SZ", '"' & @AutoItExe & '" "' & $sScriptPath & '"')
If @error Then
MsgBox(48, "错误", "添加开机启动失败!")
Else
MsgBox(64, "成功", "已添加到开机启动!")
EndIf
EndFunc
Func _Exit()
; 恢复窗口样式
For $i = 0 To 3
If $aBrowserHandles[$i] <> 0 And WinExists($aBrowserHandles[$i]) Then
WinSetOnTop($aBrowserHandles[$i], "", 0)
EndIf
Next
$bRunning = False
GUIDelete($hGUI)
Exit
EndFunc
; 窗口大小改变时的处理
Func _OnResize($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam, $lParam
_ArrangeBrowsers()
EndFunc
; 限制最小窗口大小
Func _OnMinMaxInfo($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $tMinMax = DllStructCreate($tagMINMAXINFO, $lParam)
DllStructSetData($tMinMax, "ptMinTrackSize", 800, 1)
DllStructSetData($tMinMax, "ptMinTrackSize", 600, 2)
EndFunc |