MCPcopy Create free account
hub / github.com/NYPDK/cs2go / initWindow

Function initWindow

main.go:491–563  ·  view source on GitHub ↗
(screenWidth uintptr, screenHeight uintptr)

Source from the content-addressed store, hash-verified

489}
490
491func initWindow(screenWidth uintptr, screenHeight uintptr) win.HWND {
492
493 className, err := windows.UTF16PtrFromString("cs2goWindow")
494 if err != nil {
495 logAndSleep("Error creating window class name", err)
496 return 0
497 }
498 windowTitle, err := windows.UTF16PtrFromString("cs2go")
499 if err != nil {
500 logAndSleep("Error creating window title", err)
501 return 0
502 }
503
504 // Register window class
505 wc := win.WNDCLASSEX{
506 CbSize: uint32(unsafe.Sizeof(win.WNDCLASSEX{})),
507 Style: win.CS_HREDRAW | win.CS_VREDRAW,
508 LpfnWndProc: syscall.NewCallback(windowProc),
509 CbWndExtra: 0,
510 HInstance: win.GetModuleHandle(nil),
511 HIcon: win.LoadIcon(0, (*uint16)(unsafe.Pointer(uintptr(win.IDI_APPLICATION)))),
512 HCursor: win.LoadCursor(0, (*uint16)(unsafe.Pointer(uintptr(win.IDC_ARROW)))),
513 HbrBackground: win.COLOR_WINDOW,
514 LpszMenuName: nil,
515 LpszClassName: className,
516 HIconSm: win.LoadIcon(0, (*uint16)(unsafe.Pointer(uintptr(win.IDI_APPLICATION)))),
517 }
518
519 if atom := win.RegisterClassEx(&wc); atom == 0 {
520 logAndSleep("Error registering window class", fmt.Errorf("%v", win.GetLastError()))
521 return 0
522 }
523
524 // Create window
525 hInstance := win.GetModuleHandle(nil)
526 hwnd := win.CreateWindowEx(
527 win.WS_EX_TOPMOST|win.WS_EX_NOACTIVATE|win.WS_EX_LAYERED,
528 className,
529 windowTitle,
530 win.WS_POPUP,
531 0,
532 0,
533 int32(screenWidth),
534 int32(screenHeight),
535 0,
536 0,
537 hInstance,
538 nil,
539 )
540 if hwnd == 0 {
541 logAndSleep("Error creating window", fmt.Errorf("%v", win.GetLastError()))
542 return 0
543 }
544
545 result, _, _ := setLayeredWindowAttributes.Call(uintptr(hwnd), 0x000000, 0, 0x00000001)
546 if result == 0 {
547 logAndSleep("Error setting layered window attributes", fmt.Errorf("%v", win.GetLastError()))
548 }

Callers 1

mainFunction · 0.85

Calls 1

logAndSleepFunction · 0.85

Tested by

no test coverage detected