no więc nie chce rzucać mięsem ale chyba nie długo będę… problem jest banalny napisać aplikację winAPI robiącą nic.
z pięć kliknięć w Visual Studio, dowolnym, tak na prawdę średnio rozgarnięta osoba wiedząca co to jest Windows to zrobi w godzinę.
tylko zrób to w asemblerze.
o coś takiego::
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
; Dolphinz’s win32ASM Tutorial 3
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
.386p ; use 80386 instructions set
.model flat, stdcall ; memory model I want to use
include win32.inc
%list ; my win32 include file
extrn GetModuleHandleA: PROC
extrn LoadIconA : PROC
extrn LoadCursorA : PROC
extrn RegisterClassA : PROC
extrn CreateWindowExA : PROC
extrn PostQuitMessage : PROC
extrn GetMessageA : PROC
extrn TranslateMessage: PROC
extrn DispatchMessageA: PROC
extrn DefWindowProcA : PROC
extrn DialogBoxParamA : PROC
extrn ExitProcess : PROC
extrn ShowWindow : PROC
extrn UpdateWindow : PROC
extrn EndDialog : PROC
DialogBoxParam equ <DialogBoxParamA>
ID_ICON equ 100 ; My icon, as defined in resource file
IDR_MENU equ 200 ; and here is my menu identifier.
IDM_EXIT equ 300
IDD_DIALOG1 equ 103
IDD_ABOUTBOX equ 2001
IDM_ABOUT equ 400
TRUE equ 1
FALSE equ 0
IDOK = 1
IDCANCEL = 2
.DATA
msg MSG <?>
wc WNDCLASS <?>
;========== Handles
hMain dd 0 ; handle for main window
hInst dd 0 ; handle Instance
;========== Strings
szProgName db ’Tutorial 3 – Using Resources’,0
szMainClass db ’MENUASM’,0
.CODE
;—————————————————————————–
start: ; Entrypoint
call GetModuleHandleA, 0
mov hInst, eax
mov [wc.style], CS_HREDRAW + CS_VREDRAW
mov [wc.lpfnWndProc], offset WndProc
mov [wc.cbClsExtra], 0
mov [wc.cbWndExtra], 0
mov eax, [hInst]
mov [wc.hInstance], eax
call LoadIconA, hInst, ID_ICON ; Load icon I want to use
mov [wc.hIcon], eax
call LoadCursorA, 0, IDC_ARROW ; Load default cursor
mov [wc.hCursor], eax
mov [wc.hbrBackground], COLOR_WINDOW + 1
mov dword ptr [wc.lpszMenuName], IDR_MENU ; My menu resource
mov dword ptr [wc.lpszClassName], offset szMainClass
push offset wc
call RegisterClassA
call CreateWindowExA, 0, offset szMainClass, offset szProgName,\
WS_VISIBLE OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME,\
100,50,300,100,0,0, hInst, 0
mov hMain, eax
call ShowWindow, hMain, SW_SHOWNORMAL
call UpdateWindow, hMain
msg_loop:
call GetMessageA, offset msg, 0, 0, 0
cmp ax, 0
je end_loop
call TranslateMessage, offset msg
call DispatchMessageA, offset msg
jmp msg_loop
end_loop:
call ExitProcess, 0
;—————————————————————————–
WndProc proc Hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
movzx eax, WORD PTR wmsg
.if eax == WM_DESTROY
jmp wmdestroy
.elseif eax== WM_COMMAND
jmp wmcommand
.else
call DefWindowProcA, Hwnd, wmsg, wparam, lparam
jmp @@End
.endif
xor eax, eax
@@End:
ret
wmcommand:
mov eax, [wparam]
cwde
cmp eax, IDM_EXIT
je wmdestroy
cmp eax, IDM_ABOUT
je idmabout
xor eax, eax
ret
wmdestroy:
call PostQuitMessage, 0
xor eax, eax
ret
idmabout:
push 0 ;LPARAM to pass to dialog
push offset AboutDlg ;DLGPROC lpDialogFunc
push [hwnd] ;window handle of this window
push IDD_ABOUTBOX ;Dialog ID
push [hInst] ;Module Instance
call DialogBoxParam ;Invoke Dialog
jmp return0
WndProc endp
public WndProc
;*******************************************************************
;* ABOUTBOX DIALOG PROCEDURE *
;*******************************************************************
AboutDlg proc hdlg:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
cmp [wmsg],WM_COMMAND ;Is message is a WM_COMMAND?
jne MyDlgDone ;No, then just return
mov eax,[wparam] ;Otherwise, see if it’s OK or CANCEL
cmp eax,IDOK ;That was pressed
je @@1 ;and if not either of these
cmp eax,IDCANCEL ;then just
jne AboutDone ;return
@@1: push [wparam] ;terminate with wparam as the return
push [hdlg] ;handle of the dialog
call EndDialog ;end the dialog
mov eax,TRUE ;return
jmp AboutRet ;with TRUE
AboutDone:
mov eax,FALSE ;return with FALSE
AboutRet:
ret ;return
AboutDlg endp
public AboutDlg
MyDlgDone:
mov eax,FALSE ;return with FALSE
return0: xor eax,eax
;——————————————————-
end start
.386p ; use 80386 instructions set
.model flat, stdcall ; memory model I want to use
include win32.inc
%list ; my win32 include file
extrn GetModuleHandleA: PROC
extrn LoadIconA : PROC
extrn LoadCursorA : PROC
extrn RegisterClassA : PROC
extrn CreateWindowExA : PROC
extrn PostQuitMessage : PROC
extrn GetMessageA : PROC
extrn TranslateMessage: PROC
extrn DispatchMessageA: PROC
extrn DefWindowProcA : PROC
extrn DialogBoxParamA : PROC
extrn ExitProcess : PROC
extrn ShowWindow : PROC
extrn UpdateWindow : PROC
extrn EndDialog : PROC
DialogBoxParam equ <DialogBoxParamA>
ID_ICON equ 100 ; My icon, as defined in resource file
IDR_MENU equ 200 ; and here is my menu identifier.
IDM_EXIT equ 300
IDD_DIALOG1 equ 103
IDD_ABOUTBOX equ 2001
IDM_ABOUT equ 400
TRUE equ 1
FALSE equ 0
IDOK = 1
IDCANCEL = 2
.DATA
msg MSG <?>
wc WNDCLASS <?>
;========== Handles
hMain dd 0 ; handle for main window
hInst dd 0 ; handle Instance
;========== Strings
szProgName db ’Tutorial 3 – Using Resources’,0
szMainClass db ’MENUASM’,0
.CODE
;—————————————————————————–
start: ; Entrypoint
call GetModuleHandleA, 0
mov hInst, eax
mov [wc.style], CS_HREDRAW + CS_VREDRAW
mov [wc.lpfnWndProc], offset WndProc
mov [wc.cbClsExtra], 0
mov [wc.cbWndExtra], 0
mov eax, [hInst]
mov [wc.hInstance], eax
call LoadIconA, hInst, ID_ICON ; Load icon I want to use
mov [wc.hIcon], eax
call LoadCursorA, 0, IDC_ARROW ; Load default cursor
mov [wc.hCursor], eax
mov [wc.hbrBackground], COLOR_WINDOW + 1
mov dword ptr [wc.lpszMenuName], IDR_MENU ; My menu resource
mov dword ptr [wc.lpszClassName], offset szMainClass
push offset wc
call RegisterClassA
call CreateWindowExA, 0, offset szMainClass, offset szProgName,\
WS_VISIBLE OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME,\
100,50,300,100,0,0, hInst, 0
mov hMain, eax
call ShowWindow, hMain, SW_SHOWNORMAL
call UpdateWindow, hMain
msg_loop:
call GetMessageA, offset msg, 0, 0, 0
cmp ax, 0
je end_loop
call TranslateMessage, offset msg
call DispatchMessageA, offset msg
jmp msg_loop
end_loop:
call ExitProcess, 0
;—————————————————————————–
WndProc proc Hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
movzx eax, WORD PTR wmsg
.if eax == WM_DESTROY
jmp wmdestroy
.elseif eax== WM_COMMAND
jmp wmcommand
.else
call DefWindowProcA, Hwnd, wmsg, wparam, lparam
jmp @@End
.endif
xor eax, eax
@@End:
ret
wmcommand:
mov eax, [wparam]
cwde
cmp eax, IDM_EXIT
je wmdestroy
cmp eax, IDM_ABOUT
je idmabout
xor eax, eax
ret
wmdestroy:
call PostQuitMessage, 0
xor eax, eax
ret
idmabout:
push 0 ;LPARAM to pass to dialog
push offset AboutDlg ;DLGPROC lpDialogFunc
push [hwnd] ;window handle of this window
push IDD_ABOUTBOX ;Dialog ID
push [hInst] ;Module Instance
call DialogBoxParam ;Invoke Dialog
jmp return0
WndProc endp
public WndProc
;*******************************************************************
;* ABOUTBOX DIALOG PROCEDURE *
;*******************************************************************
AboutDlg proc hdlg:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
cmp [wmsg],WM_COMMAND ;Is message is a WM_COMMAND?
jne MyDlgDone ;No, then just return
mov eax,[wparam] ;Otherwise, see if it’s OK or CANCEL
cmp eax,IDOK ;That was pressed
je @@1 ;and if not either of these
cmp eax,IDCANCEL ;then just
jne AboutDone ;return
@@1: push [wparam] ;terminate with wparam as the return
push [hdlg] ;handle of the dialog
call EndDialog ;end the dialog
mov eax,TRUE ;return
jmp AboutRet ;with TRUE
AboutDone:
mov eax,FALSE ;return with FALSE
AboutRet:
ret ;return
AboutDlg endp
public AboutDlg
MyDlgDone:
mov eax,FALSE ;return with FALSE
return0: xor eax,eax
;——————————————————-
end start
to tak jakby ktoś nie wiedział jak wygląda asembler
no to powodzenia.