File tree Expand file tree Collapse file tree 1 file changed +17
-31
lines changed Expand file tree Collapse file tree 1 file changed +17
-31
lines changed Original file line number Diff line number Diff line change @@ -46,39 +46,11 @@ Don't use `go run main.go`, because golang can't load x.syso files.
4646*/
4747package wingui
4848
49- /*
50- #include <windows.h>
51-
52- HWND dlg;
53-
54- // Message Loop
55- void MessageLoop(){
56- MSG msg;
57- while (GetMessage(&msg, NULL, 0, 0))
58- {
59- if(dlg){
60- if(!IsDialogMessage(dlg, &msg))
61- {
62- TranslateMessage(&msg);
63- DispatchMessage(&msg);
64- }
65- }else{
66- TranslateMessage(&msg);
67- DispatchMessage(&msg);
68- }
69- }
70-
71- }
72-
73- void SetCurrentDialog(long long int h){
74- dlg = (HWND)h;
75- }
76- */
77- import "C"
7849import (
7950 "github.com/lxn/win"
8051 "log"
8152 "os"
53+ "runtime"
8254 "syscall"
8355)
8456
@@ -99,13 +71,27 @@ func InitHInstance(lpModuleName string) {
9971 log .Println ("hInstance" , hInstance )
10072}
10173
74+ var dlg win.HWND
75+
10276// MessageLoop start windows message loop.
10377func MessageLoop () {
104- C .MessageLoop ()
78+ // message loop
79+ runtime .LockOSThread ()
80+ defer runtime .UnlockOSThread ()
81+ var msg win.MSG
82+ for win .GetMessage (& msg , 0 , 0 , 0 ) > 0 {
83+ if dlg > 0 {
84+ if win .IsDialogMessage (dlg , & msg ) {
85+ continue
86+ }
87+ }
88+ win .TranslateMessage (& msg )
89+ win .DispatchMessage (& msg )
90+ }
10591}
10692
10793// SetCurrentDialog make sure Message Loop could process dialog msg correct,such as Tabstop msg.
10894// This is a optional method.
10995func SetCurrentDialog (h win.HWND ) {
110- C . SetCurrentDialog ( C . longlong ( uintptr ( h )))
96+ dlg = h
11197}
You can’t perform that action at this time.
0 commit comments