Below is my code. I want to make the GUI autohide when mouse leave from it. But if I enable OnMessage(0x200, "WM_MOUSEMOVE") and OnMessage(0x2A3, "WM_MOUSELEAVE"), the script will become very slow and maybe halt when I triggle the listview g-label event. Except DoubleClick, the secondary notifications may be ignored.
Who can tell me how to solve this confilct?
Code:
#NoEnv
#SingleInstance
#Include lib\COM.ahk
#Include inc\ADO.ahk
#Include lib\Splitter.ahk
#Include lib\Win.ahk
#Include lib\Attach.ahk
COM_Init()
DB_RIS_CONNSTR := "Provider=MSDAORA.1;Persist Security Info=True;User ID=ma;Password=infinitt;Data Source=( DESCRIPTION = ( ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.1.49)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = risdb)) )"
oConn := ADO_OpenConnect(DB_RIS_CONNSTR)
SIDEBAR_WIDTH := 200
SysGet, MWA_, MonitorWorkArea
SysGet, SM_CYCAPTION, 4
SysGet, SM_CYMENU, 15
SysGet, SM_CXBORDER, 45
SysGet, SM_CYBORDER, 46
;Gui, 99:
Gui,+LastFound +AlwaysOnTop +Resize +ToolWindow
$hGUI := WInExist()
Gui, Margin, 5, 5
;Gui, Add, GroupBox, w200 h200 hwndhGB, 工作量统计
hSep1 := Splitter_Add( "y10 w200 h16 blackrect blackframe sunken", "急诊")
Gui, Add, ListView, y+0 w200 h100 AltSubmit hwndhLV1 vc_SysListView321 g@ListView_OnEvent, 状态|ID|姓名|部位|性别|年龄|访问号|申请单
LV_ModifyCol(2, 60)
LV_ModifyCol(3, 60)
LV_ModifyCol(4, 100)
hSep2 := Splitter_Add( "w200 h16 sunken", "门诊")
Gui, Add, ListView, y+0 wp h200 AltSubmit hwndhLV2 vc_SysListView322 g@ListView_OnEvent, 状态|ID|姓名|部位|性别|年龄|访问号|申请单
LV_ModifyCol(2, 60)
LV_ModifyCol(3, 60)
LV_ModifyCol(4, 100)
hSep3 := Splitter_Add( "w200 h16 sunken", "住院")
Gui, Add, ListView, y+0 wp h200 AltSubmit hwndhLV3 vc_SysListView323 g@ListView_OnEvent, 状态|ID|姓名|部位|性别|年龄|访问号|申请单
LV_ModifyCol(2, 60)
LV_ModifyCol(3, 60)
LV_ModifyCol(4, 100)
hSep4 := Splitter_Add( "wp h16 sunken", "无需报告")
Gui, Add, ListView, y+0 wp h100 AltSubmit hwndhLV4 vc_SysListView324 g@ListView_OnEvent, 状态|ID|姓名|部位|性别|年龄|访问号|申请单
LV_ModifyCol(2, 60)
LV_ModifyCol(3, 60)
LV_ModifyCol(4, 100)
;~ hSep4 := Splitter_Add( "x+0 y0 w10 h800 sunken")
;~ Gui, Add, Pic, ym w600 h800 hwndhPic
sDef = %hLV1% - %hLV2%
Splitter_Set( hSep2, sDef)
sDef = %hLV2% - %hLV3%
Splitter_Set( hSep3, sDef)
sDef = %hLV3% - %hLV4%
Splitter_Set( hSep4, sDef)
;~ sDef = %hGB% %hSep1% %hLV1% %hSep2% %hLV2% %hSep3% %hLV3% | %hPic%
;~ Splitter_Set( hSep4, sDef)
Attach(hLV1, "w h1/3")
Attach(hSep2, "w y")
Attach(hLV2, "y w h1/3")
Attach(hLV2, "w h1/3")
Gui, SHow, x0 y0, Radiohead
RISDB_GetPatientList(oConn)
Gosub @CreateMenu_Action
Gosub @CreateGUI_Pic
Gosub @RemoteLogon
SetTimer, @RefreshList, 60000
SetTimer, @Detect, 500
;method 1:
;~ WM_NCMOUSEMOVE = 0x00A0
;~ WM_MOUSEHOVER = 0x02A1,
;~ WM_MOUSELEAVE = 0x02A3,
;~ WM_NCMOUSEHOVER = 0x02A0,
;~ WM_NCMOUSELEAVE = 0x02A2,
;~ OnMessage(0x200, "WM_MOUSEMOVE")
;~ OnMessage(0x2A3, "WM_MOUSELEAVE")
;~ $bTracking := False
;method 2:
;~ If !Win_Subclass($hGUI, "WindowProc")
;~ MsgBox, Subclassing failed.
Return
GuiEscape:
GuiClose:
COM_Term()
ExitApp
GuiContextMenu:
IsMenuShown := True
MouseGetPos,,,,curCtrl
If !InStr(curCtrl, "SysListView32")
Return
Menu, mnAction, Show
Return
@RefreshList:
RISDB_GetPatientList(oConn)
Return
@Detect:
IfWinNotActive, Radiohead
{
IfWinExist, 申请单
Gui, 2: Hide
;bNeedRefresh := True
}
;~ IfWinActive, Radiohead
;~ {
;~ If bNeedRefresh
;~ RISDB_GetPatientList(oConn)
;~ bNeedRefresh := False
;~ }
Return
; 连接文件服务
@RemoteLogon:
HOST_IP := "192.1.6.58"
HOST_SHARE := "\\" . HOST_IP . "\RadioheadPacs"
HOST_USER := "Radiohead"
HOST_PSW := "pacs"
_sCmd = net use %HOST_SHARE% %HOST_PSW% /user:%HOST_USER%
While (!FileExist(HOST_SHARE . "\" . DB_PACS_PATH))
{
RunWait, %ComSpec% /c %_sCmd%,, Hide
;Sleep, 30000
}
Return
@ListView_OnEvent:
;~ If A_GuiEvent not in DoubleClick,Normal
;~ Return
MouseGetPos, , , , curCtrl
Gui, ListView, c_%curCtrl%
curRow := A_EventInfo
If (A_GuiEvent="DoubleClick")
{
LV_GetText(AccessNo, curRow, 2)
Gui, 2: Hide
WinActivate, ahk_class WindowsForms10.Window.8.app.0.378734a
WinWaitActive, ahk_class WindowsForms10.Window.8.app.0.378734a, , 10000
ControlSetText, WindowsForms10.EDIT.app.0.378734a6, %AccessNo%, ahk_class WindowsForms10.Window.8.app.0.378734a
ControlClick, WindowsForms10.Window.b.app.0.378734a9, ahk_class WindowsForms10.Window.8.app.0.378734a
Sleep 50
MouseClick, , 250, 190, 2
WinWaitActive, 诊断报告生成, , 10000
WinMove, 诊断报告生成, , 220
;ControlClick, WindowsForms10.Window.8.app.0.378734a3, ahk_class WindowsForms10.Window.8.app.0.378734a, , , 2
}
If (A_GuiEvent="Normal")
{
Gui, 2: Show, NA
LV_GetText(ID, curRow, 2)
ID := RegExReplace(ID, "\D*(\d+)", "$1")
LV_GetText(Path, curRow, 8)
GuiControl, 2: , c_Pic1, *w0 *h0 %Path%
today := SubStr(A_Now, 1, 8)
i := 0
Loop, 10
{
GuiControl, 2:, c_Dcm%A_Index%,
GuiControl, 2: Hide, c_Dcm%A_Index%
GuiControl, 2: Show, c_Dcm%A_Index%
}
IfExist, \\192.1.6.58\RadioheadPACS\img\DX\%today%\%ID%
{
Loop, \\192.1.6.58\RadioheadPACS\img\DX\%today%\%ID%\*, 0, 1
{
If InStr(A_LoopFileLongPath, ".jpg")
{
i++
GuiControl, 2:, c_Dcm%i%, *w0 *h0 %A_LoopFileLongPath%
}
}
}
IfExist, \\192.1.6.58\RadioheadPACS\img\CR\%today%\%ID%
{
Loop, \\192.1.6.58\RadioheadPACS\img\CR\%today%\%ID%\*, 0, 1
{
If InStr(A_LoopFileLongPath, ".jpg")
{
i++
GuiControl, 2:, c_Dcm%i%, *w0 *h0 %A_LoopFileLongPath%
}
}
}
}
Return
@CreateMenu_Action:
Menu, mnAction, Add, 无需报告, @SelectFlag
Menu, mnAction, Add, 调图, @SelectFlag
Return
@SelectFlag:
LV_GetText(Flag, curRow, 1)
LV_GetText(ID, curRow, 2)
LV_GetText(Name, curRow, 3)
LV_GetText(Pos, curRow, 4)
LV_GetText(Sex, curRow, 5)
LV_GetText(Age, curRow, 6)
LV_GetText(AccessNo, curRow, 7)
LV_GetText(Path, curRow, 8)
If (A_ThisMenuItemPos = 1)
{
LV_Delete(curRow)
today := SubStr(A_Now, 1, 8)
FileRead, ExcludeList, tmp\Exclude%today%.txt
If !InStr(ExcludeList, AccessNo)
FileAppend, %AccessNo%`n, tmp\Exclude%today%.txt
Gui, ListView, SysListView324
LV_Add("", Flag, ID, Name, Pos, Sex, Age, AccessNo, Path)
IsMenuShown := False
} Else If (A_ThisMenuItemPos = 2) {
Run, http://192.1.1.48/pkg_pacs/external_interface.aspx?LID=fsk&LPW=fsk&pid=%ID%
}
Return
@CreateGUI_Pic:
Gui, 2: Default
Gui, 2: +LastFound -Caption +Owner1
Gui, Color, FFFF00
WinSet, TransColor, FFFF00
$hGui2 := WinExist()
Gui, Add, Pic, y0 w720 h720 vc_Pic1
Loop, 10
{
If (A_Index=1) {
Gui, Add, Pic, ym w80 h100 vc_Dcm%A_Index%
} Else
Gui, Add, Pic, w80 h100 vc_Dcm%A_Index%
}
Gui, Show, x220 y0, 申请单
Return
#IfWinActive Radiohead
F5::RISDB_GetPatientList(oConn)
#IfWinActive
RISDB_GetPatientList(oConn)
{
today := SubStr(A_Now, 1, 8)
FileRead, ExcludeList, tmp\Exclude%today%.txt
sSQL=
(LTrim
SELECT write_flag, xno, name, dengjipart, sex, agetrue, accessno, picture_path, pat_type
FROM patregister, patexam
WHERE
patexam.accessno=patregister.clinicno
AND appoint_date>to_date('%today%', 'yyyyMMdd')
AND check_status='已申请'
AND dep='XRAY' AND modality<>'CR2'
ORDER BY pat_type, appoint_date ASC
)
sRet := ADO_Execute_RS(oConn, sSQL)
Loop, 4
{
Gui, ListView, c_SysListView32%A_Index%
LV_Delete()
}
Loop, Parse, sRet, `n, `r
{
IfEqual, A_LoopField, , Continue
StringSplit, aField, A_LoopField, %A_Tab%
If InStr(ExcludeList, aField7)
Gui, ListView, c_SysListView324
Else If (aField9="急诊" || aField9="绿检") {
Gui, ListView, c_SysListView321
} Else If (aField9="门诊")
Gui, ListView, c_SysListView322
Else If (aField9="住院")
Gui, ListView, c_SysListView323
Else
Continue
LV_Add("", aField1, aField2, aField3, aField4, aField5, aField6, aField7, aField8)
}
}
RISDB_GetCount(oConn)
{
sSQL = SELECT reportdoc FROM patexam WHERE reportdate>to_date('20091029','yyyyMMdd') AND dep='XRAY' AND modality<>'CR2' ORDER BY reportdoc
}
; 控件子分类
; http://www.autohotkey.com/forum/viewtopic.php?t=33476
; by majkinetor
/*
Win_Subclass(hWnd, Func, Opt="", ByRef r_WndProc="")
{
If Func is NOT integer
{
oldProc := DllCall("GetWindowLong", "uint", hWnd, "uint", -4)
IfEqual, oldProc, 0, Return 0
r_WndProc := RegisterCallback(Func, Opt, 4, oldProc)
IfEqual, r_WndProc, , Return 0
} Else {
r_WndProc := Func
}
Return DllCall("SetWindowLong", "UInt", hWnd, "Int", -4, "Int", r_WndProc, "UInt")
}
*/
WindowProc(hWnd, uMsg, wParam, lParam)
{
global $hGUI, oConn, IsMenuShown
static $bTracking := False
static TME
If (uMsg=0x200) And (!$bTracking) ; WM_MOUSEMOVE
{
Gui, SHow, x0 y0 Hide
WinAPI_AnimateWindow(hWnd, 200, 0x20001)
RISDB_GetPatientList(oConn)
VarSetCapacity(TME,16,0)
NumPut(16, TME, 0) ; cbSize
NumPut(2, TME, 4) ; dwFlags = TME_HOVER (1) | TME_LEAVE (2)
NumPut(hWnd, TME, 8) ;hwndTrack
$bTracking := DllCall("TrackMouseEvent", "uint", &TME)
}
Else If (uMsg=0x2A3) And ($bTracking) And !(IsMenuShown) ; WM_MOUSELEAVE
{
MouseGetPos, , , _curHwnd
Sleep 1 ; 没这一句有时候会无法隐藏,不知道为什么
If (_curHwnd=hWnd) {
$bTracking := DllCall("TrackMouseEvent", "uint", &TME)
Return
}
;WinMove, ahk_id %$hGUI%, , , , 220
WinAPI_AnimateWindow(hWnd, 200, 0x30002)
Gui, SHow, x-209
$bTracking := False
}
Return DllCall("CallWindowProcA", UInt, A_EventInfo, UInt, hWnd, UInt, uMsg, UInt, wParam, UInt, lParam)
}
WM_MOUSEMOVE(wParam, lParam, uMsg, hWnd)
{
global
If (hWnd=$hGUI) And (!$bTracking) {
Gui, SHow, x0 y0 Hide
WinAPI_AnimateWindow($hGUI, 200, 0x20001)
VarSetCapacity(TME, 16, 0)
NumPut(16, TME, 0) ; cbSize
NumPut(2, TME, 4) ; dwFlags = TME_HOVER (1) | TME_LEAVE (2)
NumPut(hWnd, TME, 8) ; hwndTrack
$bTracking := DllCall("TrackMouseEvent", "UInt", &TME)
;OnMessage(0x2A3, "WM_MOUSELEAVE")
}
}
WM_MOUSELEAVE(wParam, lParam, uMsg, hWnd)
{
local _curHwnd
MouseGetPos, , , _curHwnd
Sleep 1 ; 没这一句有时候会无法隐藏,不知道为什么
If (_curHwnd=$hGUI) {
$bTracking := DllCall("TrackMouseEvent", "uint", &TME)
Return
}
If (hWnd=$hGUI) And ($bTracking)
{
WinAPI_AnimateWindow(hWnd, 200, 0x30002)
Gui, SHow, x-209
$bTracking := False
;DllCall("TrackMouseEvent", "uint", &TME)
}
}
WM_MOUSEHOVER(wParam, lParam, uMsg, hWnd)
{
global
If !$bTracking
{
Gui, SHow, x0 y0 Hide
WinAPI_AnimateWindow(hWnd, 200, 0x30004)
$bTracking := True
DllCall("TrackMouseEvent", "uint", &TME)
}
}
WinAPI_AnimateWindow(p_hWnd, p_iTime, p_iFlag) {
Return DllCall("AnimateWindow","UInt", p_hWnd,"Int", p_iTime,"UInt", p_iFlag)
}