satpro

Create Main Window

Feb 16th, 2026
17,380
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 4.03 KB | Source Code | 0 0
  1.  
  2.  
  3.  
  4.  
  5. ; ========================================================================================
  6.  
  7. align 16
  8. export Window_Startup:
  9.  
  10.   sub rsp, 78h
  11.  
  12.   mov [rsp+60h], rsi
  13.   mov [rsp+68h], rdi
  14.   mov [rsp+70h], rbx
  15.  
  16. ; -----  Enter  -----
  17.  
  18.  
  19. ; ----------------------------
  20. ; clear WNDCLASSEXA stucture
  21. ; ----------------------------
  22.   lea edi, win                                    ; win = address of the structure
  23.   mov ecx, 10                                     ; ecx: loop limit = # of bytes / 8
  24.   xor eax, eax                                    ; eax: fillvalue = 0
  25.   dec ecx                                         ; ecx: loop counter - 1
  26.  
  27. ; loop
  28. : mov [edi+ecx*8], rax                            ; use indexed*8 addressing
  29.   dec ecx
  30.   jns <                                           ; until loop counter = loop limit
  31.  
  32. ; --------------------------------------
  33. ;     fill the WNDCLASSEXA structure
  34. ; --------------------------------------
  35.   mov D[win.cbSize], sizeof(WNDCLASSEXA)          ; (50h) structure size in bytes
  36.  
  37.   mov rax, [hInstance]                            ; get program's instance handle
  38.   mov   [win.hInstance], rax                        ; store handle in the window structure
  39.    
  40.   lea ebx, ClassName
  41.   lea eax, WndProc
  42.   mov [win.lpszClassName], ebx                    ; ptr to window class name
  43.   mov [win.lpfnWndProc], eax                      ; ptr to window procedure
  44.  
  45.  
  46. ; win.hbrBackground = CreateSolidBrush(RGB(color));
  47.   mov ecx, 0 ;AlmostBlack                            ; p1:  COLORREF crColor (brush color)
  48.   mov [GUISkinColor], ecx                         ; save a copy for gui updates
  49.  
  50. ; convert the color to Windows: bgr = rgb
  51.   bswap ecx                   ; flip the alpha channel into bits 0-7
  52.   shr ecx, 8                  ; get rid of bits 0-7
  53.  
  54.   call CreateSolidBrush       ; returns: handle of a logical brush for LoadCursor
  55.     test rax, rax
  56.     jz >> wcError
  57.   mov [win.hbrBackground], rax                    ; store the handle
  58.  
  59. ; ----------------------------
  60. ;     load the hand cursor
  61. ; ----------------------------
  62.   xor ecx, ecx                                    ; p1: NULL
  63.   mov edx, IDC_HAND                               ; p2: const for the hand
  64.   call LoadCursorA
  65.     test rax, rax
  66.     jz >> wcError
  67.  
  68.   mov [win.hCursor], rax                          ; = hand cursor
  69.  
  70. ; ----------------------------
  71. ;     register the window
  72. ; ----------------------------
  73.   lea ecx, win                ; p1: &win
  74.   call RegisterClassExA       ; register the window
  75.     test eax, eax
  76.     jz >> wcError
  77.  
  78. ; --------------------------------------
  79. ;   create a centered 1920x1080 window
  80. ; --------------------------------------
  81.   xor ecx, ecx                ; p1: DWORD dwExStyle (0)
  82.   lea edx, ClassName          ; p2: LPCTSTR lpClassName
  83.   lea r8d, WindowTitle        ; p3: LPCTSTR lpWindowName
  84.   mov r9d, WS_POPUP+WS_VISIBLE ; p4: DWORD dwStyle
  85.    
  86.   mov [rsp+20h], ecx          ; p5: int x (x=0)
  87.   mov [rsp+28h], ecx          ; p6: int y (y=0)
  88.  
  89.   mov eax, [monitor_w]
  90.   mov ebx, [monitor_h]
  91.   mov [rsp+30h], eax          ; p7: int nWidth (monitor width)
  92.   mov [rsp+38h], ebx          ; p8: int nHeight (monitor height)
  93.  
  94.   mov [rsp+40h], rcx          ; p9: HWND hWndParent (0 = top level)
  95.   mov [rsp+48h], rcx          ; p10: HMENU hMenu (0 = no menu)
  96.  
  97.   mov rax, [hInstance]
  98.   mov [rsp+50h], rax          ; p11: HINSTANCE hInstance
  99.  
  100.   mov [rsp+58h], rcx          ; p12: LPVOID lpParam  (0)
  101.  
  102. ; ------------------
  103. ; create the window
  104. ; ------------------
  105.   call CreateWindowExA
  106.     test rax, rax
  107.     jz >> wcError
  108.  
  109.   mov [hWindow], rax     ; store the window handle
  110.  
  111. ; ---------------
  112. ; hide the cursor
  113. ; ---------------
  114.   mov ecx, 0
  115.   call ShowCursor
  116.  
  117.  
  118. ; ----- REPORT SUCCESS -----
  119.  
  120.   mov eax, TRUE     ; 1 signals success
  121.  
  122.  
  123. ; ----- EXIT -----
  124.  
  125. ; if eax = 0, then an error occurred
  126. wcError:
  127.   mov rsi, [rsp+60h]
  128.   mov rdi, [rsp+68h]
  129.   mov rbx, [rsp+70h]
  130.   add rsp, 78h
  131.  
  132.   ret
  133.  
  134. ; ========================================================================================
  135.  
Tags: asm x86-64
Advertisement