Download the example here.
File I/O under Win32 bears remarkable semblance
to that under DOS. The steps needed are the same. You only have to change
interrupts to API calls and it's done. The required steps are the followings:
include windows.inc
includelib user32.lib
includelib kernel32.lib
includelib gdi32.lib
includelib comdlg32.lib
.const
IDM_OPEN equ 1
IDM_SAVE equ 2
IDM_EXIT equ 3
MAXSIZE equ 260
MEMSIZE equ 65535
EditID equ 1 ; ID of the edit control
.data
ClassName db "Win32ASMEditClass",0
AppName db "Win32 ASM Edit",0
EditClass db "edit",0
MenuName db "FirstMenu",0
ofn OPENFILENAME <>
FilterString db "All Files",0,"*.*",0
db "Text Files",0,"*.txt",0,0
buffer db MAXSIZE dup(0)
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndEdit HWND ?
; Handle to the edit control
hFile HANDLE ?
; File handle
hMemory HANDLE ?
;handle to the allocated memory block
pMemory DWORD ?
;pointer to the allocated memory block
SizeReadWrite DWORD ?
; number of bytes actually read or write
.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
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,CW_USEDEFAULT,\
CW_USEDEFAULT,300,200,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 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
;==============================================
;
Initialize the members of OPENFILENAME structure
;==============================================
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
.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 ,\
FILE_SHARE_READ or FILE_SHARE_WRITE,\
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
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 ,\
FILE_SHARE_READ or FILE_SHARE_WRITE,\
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
.else
invoke DestroyWindow, hWnd
.endif
.endif
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start
In WM_CREATE section, we create an edit control.
Note that the parameters that specify x, y, width,height of the control
are all zeroes since we will resize the control later to cover the whole
client area of the parent window.
Note that in this case, we don't have to call
ShowWindow to make the edit control appear on the screen because we include
WS_VISIBLE style. You can use this trick in the parent window too.
;==============================================
;
Initialize the members of OPENFILENAME structure
;==============================================
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
After creating the edit control, we take this
time to initialize the members of ofn. Because we want to reuse ofn in
the save as dialog box too, we fill in only the *common* members that're
used by both GetOpenFileName and GetSaveFileName.
WM_CREATE section is a great place to do once-only
initialization.
.ELSEIF eax==WM_SIZE
invoke GetClientRect,hWnd,ADDR rec
invoke MoveWindow,hwndEdit,0,0,rec.right,rec.bottom,TRUE
We receive WM_SIZE messages when the size of the client area of our main window changes. We also receive it when the window is first created. In order to be able to receive this message, the window class styles must include CS_VREDRAW and CS_HREDRAW styles. We use this opportunity to resize our edit control to the same size as the client area of the parent window. First we have to know the current width and height of the client area of the parent window. We get this info by calling GetClientRect function which takes a pointer to a structure of type RECT which is defined as follows:
RECT structAfter GetClientRect call, the RECT structure is filled with the current dimension of the client area. We then use the information to resize the edit control by calling MoveWindow function which in addtion to change the position of the window, can alter the size too.
left LONG ?
top LONG ?
right LONG ?
bottom LONG ?
RECT ends
.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
When the user selects File/Open menu item, we fill in the Flags member of ofn structure and call GetOpenFileName function to display the open file dialog box.
.if eax==TRUE
invoke CreateFile,ADDR buffer,\
GENERIC_READ or GENERIC_WRITE ,\
FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
NULL
mov hFile,eax
After the user selects a file to open, we call CreateFile to open the file. We specifies that the function should try to open the file for read and write. After the file is opened, the function returns the handle to the opened file which we store in a global variable for future use. This function has the following syntax:
HANDLE CreateFile(
LPCTSTR lpFileName, ; Example Terragen Script
; ~~~~~~~~~~~~~~~~~~~~~~~
; A line beginning with ';' is ignored by Terragen.
; Each command must start on a separate line.
; Commands are not case sensitive, ie. Hello = hello = HELLO.
; A command must be followed by the correct number of parameters.
; Parameters can be separated by spaces and/or a single comma.
; The decimal separator must be a period, eg one tenth is 0.1 not 0,1
; Animation setup commands (v0.6.26)
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; InitAnim BaseImageFileName,StartFrameNumber
; CloudPos x,y ;the cloud position at frame 0
; CloudVel speed, heading ;cloud scroll speed per frame
; (for entire animation)
; Per-frame commands (v0.6.36)
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; CamPos x,y,z
; TarPos x,y,z
; CamH head
; CamP pitch
; CamB bank
; Zoom zoom
; Exp exposure
; SunDir head,alt
;
; FRend ;(frame render, only works after using InitAnim)
; Some notes about Animation Setup commands:
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; The InitAnim command tells Terragen that an animation is to be
; rendered, and initialises the appropriate variables. It is
; necessary to have this command before any calls to FRend.
; CloudVel is used to automatically scroll the clouds across the
; sky. It will position the clouds correctly for each frame, no
; matter what frame number the script starts at. CloudPos tells
; Terragen where the clouds would be if it were rendering frame 0.
; If you want to break up a script into smaller parts, you must
; make sure that each script begins with the same setup commands
; such as CloudVel and CloudPos. You can then use a different
; frame number with InitAnim, and provided that CloudVel etc.
; are identical in each script, all animation should be seamless.
;
; The folder specified in InitAnim must already exist.
;
; Warning: in Windows 95 and 98, the root directory (eg "C:\")
; cannot hold more than 256 files. It is recommended that you use
; a subdirectory with InitAnim, such as "C:\Anim\" or
; "C:\Anim\pic"
; Some notes about Per-frame commands:
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Per-frame commands can be used at the start of the script.
; There is no restriction on this. Likewise, CloudPos and
; CloudVel can be used for each frame, but changing CloudVel
; in the middle of an animation has weird results. If you want
; non-linear cloud motion, use CloudPos to specify exact
; positions, and set CloudVel to 0,0.
; The following script requires Terragen v0.6.26 or above,
; and the folder specified in InitAnim must already exist.
initanim "F:\Graphics\TGAnim\tganim", 1
; (necessary before using FRend)
cloudvel 10, 45
sundir 120,50
frend ;render frame and save
frend
frend
frend
frend
frend
frend
frend
frend
frend
< endl << endl << inout.str();
#else
// create a bi-directional stringstream object
stringstream inout;
// output characters
inout << "Das ist die rede von einem man" << endl;
inout << "C'est l'histoire d'un home" << endl;
inout << "This is the story of a man" << endl;
char p[100];
// extract the first line
inout.getline(p,100);
// output the first line to stdout
cout << endl << "Deutch :" << endl;
cout << p;
// extract the seconf line
inout.getline(p,100);
// output the second line to stdout
cout << endl << "Francais :" << endl;
cout << p;
// extract the third line
inout.getline(p,100);
// output the third line to stdout
cout << endl << "English :" << endl;
cout << p;
// output the all content of the
//stringstream object to stdout
cout << endl << endl << inout.str();
#endif
return 0;
}
%d %e %u %Le %le %lu %hu %hd %ld %Lf %lf 1 t T true FALSE TRUE DIllunCNeoBlob ̟0Π0CNeoPartMgr CNeoContainerLocation 0f2 has an incorrect database ID. Please choose another. CNeoLocation File close failed! File flush failed! Get file length failed! File open failed! Set file length failed! Set file mark failed! File read failed! File write failed! CNeoFileLocation File delete failed! File create failed! file:// z01 1 1}00H1#1i1:11;
1CNeoClass 11P81CNeoQuery CNeoFreeList ncNNteNNfCount fEntry CNeoIDIndex CNeoIDList CNeoIDSelect CNeoReverseSelect CNeoOrSelect CNeoAndSelect CNeoRangeSelect CNeoClassSelect CNeoTypeSelect CNeoSubclass CNeoLaundry CNeoULongIndex CNeoULongSelect CNeoLongIndex CNeoLongSelect CNeoInode 2 .?AVtype_info@@ 00F000011$1)1.1<1B1J1R1[1`1f1l11111111(202K2i22222222!3=3p333 4'4B444445505U5p5555560666Z666667.7X7^7777778@8\888889m999:#:K:o::;<< <-<@