首先建立乙個button空間。
然後複製以下**
option explicit
rem 轉移輸入焦點的宣告
private declare function getwindowlong lib "user32" alias "getwindowlonga" (byval hwnd as long, byval nindex as long) as long
private declare function setwindowlong lib "user32" alias "setwindowlonga" (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long
rem 禁止本窗體擁有輸入焦點的常數
private const hwnd_notopmost = -2
private const ws_disabled = &h8000000
private const gwl_exstyle = (-20)
private const gwl_style = (-16)
private sub form_load()
rem 窗體呼叫時置頂,且禁止擁有輸入焦點
setwindowlong me.hwnd, gwl_exstyle, getwindowlong(me.hwnd, gwl_exstyle) or ws_disabled
rem 開啟notepad供測試,並且寫入文字
dim a
a = shell("notepad.exe", vbnormalfocus)
sendkeys "窗體的按鈕,看看窗體有沒有獲得焦點", true
end sub
然後按下f5執行即可 vb 點選控制項移動窗體
新增模組 如下 public declare function sendmessage lib user32 alias sendmessagea byval hwnd as long,byval wmsg as long,byval wparam as long,lparam as any as ...
控制項失去焦點與獲得焦點
1.失去焦點 讓控制項失去焦點的方法,就是給該控制項傳送乙個wm killfocus的訊息。可以通過下面三種方式實現 1使用cwnd類的postmessage getdlgitem 控制項id號 postmessage wm killfocus,0,0 2獲取控制項的控制代碼,然後通過控制代碼直接給...
android中設定控制項獲得焦點
android中,要使控制項獲得焦點,需要先setfocus,再requestfocus。以button為例 btn.setfocusable true btn.setfocusableintouchmode true btn.requestfocus btn.requestfocusfromtou...