MAKE YOUR NEXT PROGRAM A WIN32 ASSEMBLER !!.
NEW CHANGES ADDED
Sept 4th 1999 - NEW PROGRAMMING SITE - WIN32, DIRECTX
WIN32 ASSEMBLER, C/C++, DIRECTX, VRML
Aug 19th 1999 - Registry Subroutines
Aug 12th 1999 - DirectSound Page with source code
Aug 6th 1999 - Flipin' Screens with source
Aug 4th 1999 - DirectDraw examples added - Enjoy!
July 15 1999 - DIALOG, SOUND, SHELL32 DEMO WITH SOURCE CODE
here is a small program to get you started with win32
include windows.inc ;PROTO TYPE DEFINTIONS
includelib user32.lib
includelib kernel32.lib
includelib gdi32.lib
includelib comdlg32.lib
.const
IDM_NEW equ 1
IDM_OPEN equ 2
IDM_SAVE equ 3
IDM_PRINT equ 4
IDM_EXIT equ 5
IDM_CUT equ 6
IDM_COPY equ 7
IDM_PASTE equ 8
IDM_HTML equ 9
IDM_CONTENTS equ 10
IDM_HELP equ 11
IDM_ABOUT equ 12
IDC_EDIT equ 3000
IDC_EXIT equ 3002
IDC_BUTTON equ 3001
MAXSIZE equ 32690 ;MAX FILE SIZE CHANGE AS NESS!
MEMSIZE equ 65535
EditID equ 1
.data
ClassName db "Win32ASMEditClass",0 ;CLASS
AppName db "Assembler Win32 HTML Editor",0 ;TITLE
EditClass db "edit",0
MenuName db "FirstMenu",0 ;MENU NAME IN RC FILE
new_string db "TO BE CODED...BY DAVID",0
about_string db "(c)1999 David Dalby in WIN32 Assembler",0
ofn OPENFILENAME <>
FilterString db "All Files",0,"*.*",0
db "Text Files",0,"*.txt",0,0
db "Html Files",0,"*.htm",0,0
buffer db MAXSIZE dup(0) ;MAKE BUFFER FOR FILE
DlgName db "MyDialog",0
TestString db "Hello, everbody",0
hwndDlg dd 0 ; Handle to the dialog box
.data?
hInstance HINSTANCE ? ;POINTERS
CommandLine LPSTR ?
hwndEdit HWND ?
hFile HANDLE ?
hMemory HANDLE ?
pMemory DWORD ?
SizeReadWrite DWORD ?
.code
start:
invoke GetModuleHandle, NULL ;USE A WIN32 C CODE BOOK
mov hInstance,eax ;AND FOLLOW ALONG
invoke GetCommandLine
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:SDWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,0
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,WS_EX_CLIENTEDGE,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW or WS_VSCROLL or WS_HSCROLL,CW_USEDEFAULT,\
CW_USEDEFAULT,400,300,NULL,NULL,\
hInst,NULL
mov hwnd,eax
INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
INVOKE UpdateWindow, hwnd
.WHILE TRUE ;MAIN LOOP
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
.if hwndDlg!=0
invoke IsDialogMessage,hwndDlg,ADDR msg
.if eax==TRUE
.continue
.endif
.endif
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg ;BACK TO WINDOWS
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc uses ebx hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL rec:RECT
mov eax,uMsg
.IF eax==WM_CREATE
INVOKE CreateWindowEx,NULL,ADDR EditClass,NULL,\
WS_VISIBLE or WS_CHILD or ES_LEFT or ES_MULTILINE or\
ES_AUTOHSCROLL or ES_AUTOVSCROLL,0,\
0,0,0,hWnd,EditID,\
hInstance,NULL
mov hwndEdit,eax
invoke SetFocus,hwndEdit
mov ofn.lStructSize,SIZEOF ofn
push hWnd
pop ofn.hwndOwner
push hInstance
pop ofn.hInstance
mov ofn.lpstrFilter, OFFSET FilterString
mov ofn.lpstrFile, OFFSET buffer
mov ofn.nMaxFile,MAXSIZE
.ELSEIF eax==WM_SIZE
invoke GetClientRect,hWnd,ADDR rec
invoke MoveWindow,hwndEdit,0,0,rec.right,rec.bottom,TRUE
.ELSEIF eax==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF eax==WM_COMMAND
mov eax,wParam
.if lParam==0 ;OPEN FILE MENU OPTION
.if ax==IDM_OPEN
mov ofn.Flags, OFN_FILEMUSTEXIST or \
OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
invoke GetOpenFileName, ADDR ofn
.if eax==TRUE
invoke CreateFile,ADDR buffer,\
GENERIC_READ or GENERIC_WRITE,0,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
invoke GlobalLock,hMemory
mov pMemory,eax
invoke ReadFile,hFile,pMemory,MEMSIZE-1,ADDR SizeReadWrite,NULL
invoke SendMessage,hwndEdit,WM_SETTEXT,NULL,pMemory
invoke CloseHandle,hFile
invoke GlobalUnlock,pMemory
invoke GlobalFree,hMemory
.endif
invoke SetFocus,hwndEdit
.elseif eax==IDM_SAVE ;SAVE FILE MENU OPTION
mov ofn.Flags,OFN_LONGNAMES or\
OFN_EXPLORER or OFN_HIDEREADONLY
invoke GetSaveFileName, ADDR ofn
.if eax==TRUE
invoke CreateFile,ADDR buffer,\
GENERIC_READ or GENERIC_WRITE,0,\
NULL,CREATE_NEW,FILE_ATTRIBUTE_ARCHIVE,\
NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
invoke GlobalLock,hMemory
mov pMemory,eax
invoke SendMessage,hwndEdit,WM_GETTEXT,MEMSIZE-1,pMemory
invoke lstrlen,pMemory
invoke WriteFile,hFile,pMemory,eax,ADDR SizeReadWrite,NULL
invoke CloseHandle,hFile
invoke GlobalUnlock,pMemory
invoke GlobalFree,hMemory
.endif
invoke SetFocus,hwndEdit
.elseif ax==IDM_NEW
invoke MessageBox,NULL,ADDR new_string,OFFSET AppName,MB_OK
.elseif ax==IDM_ABOUT
invoke MessageBox,NULL,ADDR about_string,OFFSET AppName,MB_OK
.elseif ax==IDM_PRINT
invoke MessageBox,NULL,ADDR new_string,OFFSET AppName,MB_OK
.elseif ax==IDM_CUT
invoke MessageBox,NULL,ADDR new_string,OFFSET AppName,MB_OK
.elseif ax==IDM_COPY
invoke MessageBox,NULL,ADDR new_string,OFFSET AppName,MB_OK
.elseif ax==IDM_PASTE
invoke MessageBox,NULL,ADDR new_string,OFFSET AppName,MB_OK
.elseif ax==IDM_HTML
invoke MessageBox,NULL,ADDR new_string,OFFSET AppName,MB_OK
.elseif ax==IDM_CONTENTS
invoke MessageBox,NULL,ADDR new_string,OFFSET AppName,MB_OK
.elseif ax==IDM_HELP
invoke DialogBoxParam,hInstance,addr DlgName,hWnd,OFFSET DlgProc,NULL
mov hwndDlg,eax
.else
invoke DestroyWindow, hWnd
.endif
.else
.endif
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
;DIALOG BOX ROUTINE WITH BUTTON CODE
DlgProc PROC hWnd:HWND,iMsg:DWORD,wParam:WPARAM,lParam:LPARAM
mov eax,iMsg
.if eax==WM_INITDIALOG
invoke GetDlgItem,hWnd,IDC_EDIT
invoke SetFocus,eax
.elseif eax==WM_CLOSE
invoke EndDialog,hWnd,NULL
mov hwndDlg,0
.elseif eax==WM_COMMAND
mov eax,wParam
.if eax==IDC_EXIT
invoke SendMessage,hWnd,WM_CLOSE,NULL,NULL
.elseif eax==IDC_BUTTON
invoke SetDlgItemText,hWnd,IDC_EDIT,ADDR TestString
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
end start
using MASM WIN32 kit you can write quick programs
and build a library of routines quickly.
WIN32 ASSEMBLER IS EXCITING AND REWARDING AND JUST AS EASY A C PROGRAMMING.
To compile first produce a file.rc (resource file) which contains
the menu and dialog box definitions.
rc file.rc (this compiles the resource file)
ml /c /coff /Cp file.asm (this will compile the assembler code into an obj file)
NOW WE ARE READY TO LINK file.obj and file.res together to get an exe file.
Use the following format to LINK:
ml /c /coff /Cp file.asm
rc file.rc
link /SUBSYSTEM:WINDOWS /LIBPATH:c:\masm file.obj file.res
NOTE: TIP: creating a batch (.bat) file will greatly increase your
productivity and save lots of typing too. Simply type the above
three lines into a batch file and save as GOFILE.BAT. Now every
time you make changes simply execute GOFILE.BAT to assemble both
files to get FILE.EXE.
// developed by david dalby 12/20/98
// constants for dialog box
#define IDC_EDIT 3000
#define IDC_BUTTON 3001
#define IDC_EXIT 3002
#define DS_CENTER 0x0800L
#define DS_CENTER 0x0800L
#define WS_MINIMIZEBOX 0x00020000L
#define WS_SYSMENU 0x00080000L
#define WS_VISIBLE 0x10000000L
#define WS_OVERLAPPED 0x00000000L
#define DS_MODALFRAME 0x80L
#define DS_3DLOOK 0x0004L
#define WS_CAPTION 0xC00000L
#define ES_AUTOHSCROLL 0x80L
#define ES_LEFT 0
// Constants for menu
#define IDM_NEW 1
#define IDM_OPEN 2
#define IDM_SAVE 3
#define IDM_PRINT 4
#define IDM_EXIT 5
#define IDM_CUT 6
#define IDM_COPY 7
#define IDM_PASTE 8
#define IDM_HTML 9
#define IDM_CONTENTS 10
#define IDM_HELP 11
#define IDM_ABOUT 12
FirstMenu MENU
{
POPUP "&File"
{
MENUITEM "&New File",IDM_NEW
MENUITEM "&Open",IDM_OPEN
MENUITEM "&Save As",IDM_SAVE
MENUITEM SEPARATOR
MENUITEM "&Print",IDM_PRINT
MENUITEM "E&xit",IDM_EXIT
}
POPUP "&Code"
{
MENUITEM "&HTML",IDM_HTML
}
POPUP "&Help"
{
MENUITEM "&Contents",IDM_CONTENTS
MENUITEM "&Help",IDM_HELP
MENUITEM SEPARATOR
MENUITEM "&About",IDM_ABOUT
}
}
MyDialog DIALOG 10, 10, 205, 60
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Our Second Dialog Box"
BEGIN
EDITTEXT IDC_EDIT, 15,17,111,13, ES_AUTOHSCROLL | ES_LEFT
DEFPUSHBUTTON "Say Hello", IDC_BUTTON, 141,10,52,13
PUSHBUTTON "E&xit", IDC_EXIT, 141,26,52,13
END
HERE is an example of a RESOURCES file. eg file.rc
This file defines the MENUS and DIALOGS used by the MAIN program.
HERE IS THE NEW TEXT EDITING CODE FOR THE ABOVE PROGRAM:
.elseif ax==IDM_UNDO
invokeSendMessage,hwndEdit,WM_UNDO,0,0
.elseif ax==IDM_CUT
invoke SendMessage,hwndEdit,WM_CUT,0,0
.elseif ax==IDM_COPY
invoke SendMessage,hwndEdit,WM_COPY,0,0
.elseif ax==IDM_PASTE
invoke SendMessage,hwndEdit,WM_PASTE,0,0
THIS WILL ALLOW YOU TO CUT , COPY AND PASTE TEXT.
OF COURSE YOU'LL HAVE TO ADD UNDO,COP,CUT AND PASTE TO THE MENU, I'LL
LEAVE THIS AS AN EXERCISE FOR THE READER !!!
[email protected]
WIN32 EXAMPLES TO DOWNLOAD
SOURCE CODE EXAMPLES
WIN 32 APPLICATION
WIN 32 APPLICATION WITH SOURCE FILES
SOUND, SHELL32 DEMO WITH SOURCE FILES (662KB)
Graphic Demo with source
Directx Demo from Book
Flippin' Screens with full source code
FastCounter by LinkExchange