@@ -61,6 +61,8 @@ type WindowOptions struct {
61
61
Title string
62
62
Width uint
63
63
Height uint
64
+ IconId uint
65
+ Center bool
64
66
}
65
67
66
68
type WebViewOptions struct {
@@ -98,7 +100,6 @@ func NewWithOptions(options WebViewOptions) WebView {
98
100
99
101
chromium := edge .NewChromium ()
100
102
chromium .MessageCallback = w .msgcb
101
- chromium .Debug = options .Debug
102
103
chromium .DataPath = options .DataPath
103
104
chromium .SetPermission (edge .CoreWebView2PermissionKindClipboardRead , edge .CoreWebView2PermissionStateAllow )
104
105
@@ -107,6 +108,22 @@ func NewWithOptions(options WebViewOptions) WebView {
107
108
if ! w .CreateWithOptions (options .WindowOptions ) {
108
109
return nil
109
110
}
111
+
112
+ settings , err := chromium .GetSettings ()
113
+ if err != nil {
114
+ log .Fatal (err )
115
+ }
116
+ // disable context menu
117
+ err = settings .PutAreDefaultContextMenusEnabled (options .Debug )
118
+ if err != nil {
119
+ log .Fatal (err )
120
+ }
121
+ // disable developer tools
122
+ err = settings .PutAreDevToolsEnabled (options .Debug )
123
+ if err != nil {
124
+ log .Fatal (err )
125
+ }
126
+
110
127
return w
111
128
}
112
129
@@ -252,10 +269,16 @@ func (w *webview) CreateWithOptions(opts WindowOptions) bool {
252
269
var hinstance windows.Handle
253
270
_ = windows .GetModuleHandleEx (0 , nil , & hinstance )
254
271
255
- icow , _ , _ := w32 .User32GetSystemMetrics .Call (w32 .SystemMetricsCxIcon )
256
- icoh , _ , _ := w32 .User32GetSystemMetrics .Call (w32 .SystemMetricsCyIcon )
257
-
258
- icon , _ , _ := w32 .User32LoadImageW .Call (uintptr (hinstance ), 32512 , icow , icoh , 0 )
272
+ var icon uintptr
273
+ if opts .IconId == 0 {
274
+ // load default icon
275
+ icow , _ , _ := w32 .User32GetSystemMetrics .Call (w32 .SystemMetricsCxIcon )
276
+ icoh , _ , _ := w32 .User32GetSystemMetrics .Call (w32 .SystemMetricsCyIcon )
277
+ icon , _ , _ = w32 .User32LoadImageW .Call (uintptr (hinstance ), 32512 , icow , icoh , 0 )
278
+ } else {
279
+ // load icon from resource
280
+ icon , _ , _ = w32 .User32LoadImageW .Call (uintptr (hinstance ), uintptr (opts .IconId ), 1 , 0 , 0 , w32 .LR_DEFAULTSIZE | w32 .LR_SHARED )
281
+ }
259
282
260
283
className , _ := windows .UTF16PtrFromString ("webview" )
261
284
wc := w32.WndClassExW {
@@ -278,13 +301,28 @@ func (w *webview) CreateWithOptions(opts WindowOptions) bool {
278
301
if windowHeight == 0 {
279
302
windowHeight = 480
280
303
}
304
+
305
+ var posX , posY uint
306
+ if opts .Center {
307
+ // get screen size
308
+ screenWidth , _ , _ := w32 .User32GetSystemMetrics .Call (w32 .SM_CXSCREEN )
309
+ screenHeight , _ , _ := w32 .User32GetSystemMetrics .Call (w32 .SM_CYSCREEN )
310
+ // calculate window position
311
+ posX = (uint (screenWidth ) - windowWidth ) / 2
312
+ posY = (uint (screenHeight ) - windowHeight ) / 2
313
+ } else {
314
+ // use default position
315
+ posX = w32 .CW_USEDEFAULT
316
+ posY = w32 .CW_USEDEFAULT
317
+ }
318
+
281
319
w .hwnd , _ , _ = w32 .User32CreateWindowExW .Call (
282
320
0 ,
283
321
uintptr (unsafe .Pointer (className )),
284
322
uintptr (unsafe .Pointer (windowName )),
285
- 0xCF0000 , // WS_OVERLAPPEDWINDOW
286
- 0x80000000 , // CW_USEDEFAULT
287
- 0x80000000 , // CW_USEDEFAULT
323
+ 0xCF0000 , // WS_OVERLAPPEDWINDOW
324
+ uintptr ( posX ),
325
+ uintptr ( posY ),
288
326
uintptr (windowWidth ),
289
327
uintptr (windowHeight ),
290
328
0 ,
0 commit comments