// 適用於Windows 2K/XP/2003
// 所需 Windows API
Function Long SetForegroundWindow (Long Hwnd) Library "user32.dll" Alias For "SetForegroundWindow"
FUNCTION Long GetForegroundWindow() LIBRARY "user32.dll"
FUNCTION Long GetWindowThreadProcessId(long hwnd, ref Long lpdwProcessId) LIBRARY "user32.dll"
FUNCTION Long AttachThreadInput(long idAttach,long idAttachTo,long fAttach) LIBRARY "user32.dll"



long lProcessId, lCurID, lForeID, lHandle, lHandle2

lHandle = GetForegroundWindow () // 目前視窗焦點所在 handle
lHandle2 = Handle(this)  // 自己的 handle

// 焦點不是自己
if lHandle <> lHandle2 then

    lCurID    = GetWindowThreadProcessId (lHandle, lProcessId) 
    lForeID    = GetWindowThreadProcessId (lHandle2, lProcessId)

    // 焦點設為自己
    AttachThreadInput (lCurID,   lForeID,   1)
    SetForegroundWindow (lHandle2)
    AttachThreadInput (lCurID,   lForeID,   0)
end if
文章標籤
全站熱搜
創作者介紹
創作者 neio 的頭像
neio

計算紙﹍

neio 發表在 痞客邦 留言(0) 人氣(0)