How to resolve the algorithm Window creation step by step in the X86 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Window creation step by step in the X86 Assembly programming language

Table of Contents

Problem Statement

Display a GUI window. The window need not have any contents, but should respond to requests to be closed.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Window creation step by step in the X86 Assembly programming language

Source code in the x86 programming language

;GTK imports and defines etc.
%define GTK_WINDOW_TOPLEVEL 0

extern gtk_init
extern gtk_window_new
extern gtk_widget_show
extern gtk_signal_connect
extern gtk_main
extern g_print
extern gtk_main_quit

bits 32

section .text
	global _main
	
        ;exit signal
	sig_main_exit:
		push exit_sig_msg
		call g_print
		add esp, 4
		call gtk_main_quit
		ret
		
	_main:
		mov ebp, esp	
		sub esp, 8
		push argv
		push argc
		call gtk_init
		add esp, 8				;stack alignment.
		push GTK_WINDOW_TOPLEVEL
		call gtk_window_new
		add esp, 4
		mov [ebp-4], eax		;ebp-4 now holds our GTKWindow pointer.
		push 0
		push sig_main_exit
		push gtk_delete_event
		push dword [ebp-4]
		call gtk_signal_connect
		add esp, 16
		push dword [ebp-4]
		call gtk_widget_show
		add esp, 4
		call gtk_main	
		
section .data
;sudo argv 
argc                dd 1
argv                dd args
args                dd title   
						  dd 0
                  
title               db "GTK Window",0
gtk_delete_event   db 'delete_event',0
exit_sig_msg      db "-> Rage quitting..",10,0


.586
.model flat, stdcall
option casemap:none

include /masm32/include/windows.inc
include /masm32/include/kernel32.inc
include /masm32/include/user32.inc

includelib /masm32/lib/kernel32.lib
includelib /masm32/lib/user32.lib

WinMain proto :dword,:dword,:dword,:dword

.data
   ClassName db "WndClass",0
   AppName   db "Window!",0
.data? 
   hInstance   dd ?
   CommandLine dd ?

.code
start:
   invoke GetModuleHandle, NULL
   mov hInstance, eax
   invoke GetCommandLine
   mov CommandLine, eax
   invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT

   WinMain proc hInst:dword, hPervInst:dword, CmdLine:dword, CmdShow:dword
   LOCAL wc:WNDCLASSEX
   LOCAL msg:MSG
   LOCAL hwnd:HWND

   wc.cbSize, sizeof WNDCLASSEX
   wc.style, CS_HREDRAW or CS_VREDRAW
   wc.lpfnWndPRoc, offset WndProc
   wc.cbClsExtra,NULL
   wc.cbWndExtra, NULL
   push hInstance
   pop wc.hInstance
   mov wc.hbrBackground, COLOR_BTNFACE+1
   mov wc.lpszMenuName NULL
   mov wc.lpszClassName, offset ClassName
   invoke LoadIcon, NULL, IDI_APPLICATION
   mov wc.hIcon, eax
   mov wc.hIconSm, eax
   invoke LoadCursor, NULL, IDC_ARROW
   mov wc.hCursor, eax
   invoke RegisterClassEx, addr wc
   invoke CreateWindowEx, NULL, addr ClassName, addr AppName, WS_OVERLAPPEDWINDOW, CS_USEDEFAULT, CW_USEDEFAUT,\
   CW_USEDEFAUT, CW_USEDEFAUT, NULL, NULL, hInst, NULL
   mov hwnd, eax
   invoke ShowWindow, hwnd, SW_SHOWNORMAL
   invoke UpdateWindow, hwnd
   .while TRUE
      invoke GetMessage, addr msg, NULL, 0,0
      .break .if (!eax)
      invoke TranslateMessage, addr msg
      invoke DispatchMessage, addr msg
   .endw
   mov eax, msg.wParam
   ret
   WinMain endp

   WndProc proc hWnd:dword, uMsg:dword, wParam:dword, lParam:dword
   mov eax, uMsg
   .if eax==WM_DESTROY
      invoke PostQuitMessage, NULL
   .else
      invoke DefWindowProc, hWnd, uMsg, wParam, lParam
   .endif
   xor eax, eax
   ret
   WndProc endp
end start


  

You may also check:How to resolve the algorithm Special characters step by step in the OCaml programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm ABC problem step by step in the Ruby programming language
You may also check:How to resolve the algorithm Regular expressions step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Bioinformatics/Sequence mutation step by step in the Raku programming language