Листинг программы.
Работа с текстовой информацией при программировании в Windows
Invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT. Bitmap moveable pure loadoncall discardable «toolbar.bmp». Read_File_In proc lpszDiskFile: DWORD, hEditControl: DWORD. Invoke SendMessage, hStatus, SB_SETTEXT, 2, ADDR txtBuffer. Invoke SendMessage, hStatus, SB_SETTEXT, 2, ADDR txtBuffer. Icon moveable pure loadoncall discardable «mainicon.ico». Invoke SendMessage, hStatus, SB_SETTEXT… Читать ещё >
Листинг программы. Работа с текстовой информацией при программировании в Windows (реферат, курсовая, диплом, контрольная)
Листинг файла rsrc. rc
#include «masm32include esource. h» .
- 500 ICON MOVEABLE PURE LOADONCALL DISCARDABLE «MAINICON.ICO»
- 750 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE «TOOLBAR.BMP»
- 600 MENUEX MOVEABLE IMPURE LOADONCALL DISCARDABLE
BEGIN.
POPUP «&File», ,, 0.
BEGIN.
MENUITEM «&New», 1000.
MENUITEM «&Open», 1001.
MENUITEM «», , 0×0800 /*MFT_SEPARATOR*/.
MENUITEM «&Save», 1002.
MENUITEM «Save &As», 1003.
MENUITEM «», , 0×0800 /*MFT_SEPARATOR*/.
MENUITEM «&Exit», 1010.
END.
POPUP «&Edit», 0.
BEGIN.
MENUITEM «&Undo Ctrl+Z», 1100.
MENUITEM «», , 0×0800 /*MFT_SEPARATOR*/.
MENUITEM «&Cut Ctrl+X», 1101.
MENUITEM «C&opy Ctrl+C», 1102.
MENUITEM «&Paste Ctrl+V», 1103.
MENUITEM «», , 0×0800 /*MFT_SEPARATOR*/.
MENUITEM «&Delete Delete», 1104.
MENUITEM «», , 0×0800 /*MFT_SEPARATOR*/.
MENUITEM «&Wordwrap F9», 1105.
END.
POPUP «&Help», ,, 0.
BEGIN.
MENUITEM «&About», 1900.
END.
END.
Листинг файла qikpad. asm
.386.
.model flat, stdcall.
option casemap: none.
include qikpad.inc.
; #########################################################################.
.code.
start:
invoke GetModuleHandle, NULL.
mov hInstance, eax.
invoke GetCommandLine.
mov CommandLine, eax.
invoke InitCommonControls.
invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT.
invoke ExitProcess, eax.
; #########################################################################.
WinMain proc hInst: DWORD,.
hPrevInst :DWORD,.
CmdLine :DWORD,.
CmdShow :DWORD.
LOCAL wc: WNDCLASSEX.
LOCAL msg: MSG.
LOCAL Wwd: DWORD.
LOCAL Wht: DWORD.
LOCAL Wtx: DWORD.
LOCAL Wty: DWORD.
LOCAL clBuffer[128] :BYTE.
invoke LoadIcon, hInst, 500.
mov hIcon, eax.
szText szClassName," QikPad_Class" .
mov wc. cbSize, sizeof WNDCLASSEX.
mov wc. style, CS_HREDRAW or CS_VREDRAW.
or CS_BYTEALIGNWINDOW.
mov wc. lpfnWndProc, offset WndProc.
mov wc. cbClsExtra, NULL.
mov wc. cbWndExtra, NULL.
m2m wc. hInstance, hInst.
invoke GetStockObject, HOLLOW_BRUSH.
mov wc. hbrBackground, eax.
mov wc. lpszMenuName, NULL.
mov wc. lpszClassName, offset szClassName.
m2m wc. hIcon, hIcon.
invoke LoadCursor, NULL, IDC_ARROW.
mov wc. hCursor, eax.
m2m wc. hIconSm, hIcon.
invoke RegisterClassEx, ADDR wc.
mov Wwd, 500.
mov Wht, 350.
invoke GetSystemMetrics, SM_CXSCREEN.
invoke TopXY, Wwd, eax.
mov Wtx, eax.
invoke GetSystemMetrics, SM_CYSCREEN.
invoke TopXY, Wht, eax.
mov Wty, eax.
invoke CreateWindowEx, WS_EX_LEFT,.
ADDR szClassName,.
ADDR szUntitled,.
WS_OVERLAPPEDWINDOW,.
Wtx, Wty, Wwd, Wht,.
NULL, NULL,.
hInst, NULL.
mov hWnd, eax.
invoke LoadMenu, hInst, 600.
invoke SetMenu, hWnd, eax.
invoke GetAppPath, ADDR PthBuffer.
invoke GetCL, 1, ADDR clBuffer.
.if eax == 1.
invoke Read_File_In, ADDR clBuffer, hEdit.
.endif.
invoke ShowWindow, hWnd, SW_SHOWNORMAL.
invoke UpdateWindow, hWnd.
StartLoop:
invoke GetMessage, ADDR msg, NULL, 0,0.
cmp eax, 0.
je ExitLoop.
invoke TranslateMessage, ADDR msg.
invoke DispatchMessage, ADDR msg.
jmp StartLoop.
ExitLoop:
return msg.wParam.
WinMain endp.
; #########################################################################.
WndProc proc hWin: DWORD,.
uMsg :DWORD,.
wParam :DWORD,.
lParam :DWORD.
LOCAL var: DWORD.
LOCAL caW: DWORD.
LOCAL caH: DWORD.
LOCAL tbh: DWORD.
LOCAL sbh: DWORD.
LOCAL wWid: DWORD.
LOCAL wHgt: DWORD.
LOCAL hDC: DWORD.
LOCAL Rct: RECT.
LOCAL tbab: TBADDBITMAP.
LOCAL tbb: TBBUTTON.
LOCAL buffer1[128] :BYTE.
LOCAL buffer2[128] :BYTE.
.if uMsg == WM_COMMAND.
.if wParam == 50.
jmp New_File.
.elseif wParam == 51.
jmp Open_File.
.elseif wParam == 52.
invoke SaveFile.
.elseif wParam == 53.
jmp Edit_Cut.
.elseif wParam == 54.
jmp Edit_Copy.
.elseif wParam == 55.
jmp Edit_Paste.
.elseif wParam == 56.
jmp Edit_Undo.
.endif.
;======== menu commands ========.
.if wParam == 1000.
New_File:
invoke SendMessage, hEdit, EM_GETMODIFY, 0,0.
.if eax == TRUE.
invoke Confirmation, hWin.
.if eax == IDYES.
invoke SaveFile.
.elseif eax == IDCANCEL.
mov eax, 0.
ret.
.endif.
.endif.
invoke SetWindowText, hEdit, NULL.
invoke SetWindowText, hWin, ADDR szUntitled.
invoke SendMessage, hStatus, SB_SETTEXT, 2, NULL.
.elseif wParam == 1001.
Open_File:
invoke SendMessage, hEdit, EM_GETMODIFY, 0,0.
.if eax == TRUE.
invoke Confirmation, hWin.
.if eax == IDYES.
invoke SaveFile.
.elseif eax == IDCANCEL.
mov eax, 0.
ret.
.endif.
.endif.
jmp @F.
szTitleO db «Open A File», 0.
szFilterO db «All files», 0," *.*", 0,.
" Text files", 0," *.TEXT", 0,0.
@@:
invoke FillBuffer, ADDR szFileName, length szFileName, 0.
invoke GetFileName, hWin, ADDR szTitleO, ADDR szFilterO.
cmp szFileName[0], 0.
je @F.
invoke Read_File_In, ADDR szFileName, hEdit.
invoke SetWindowText, hWin, ADDR szFileName.
@@:
.elseif wParam == 1002.
invoke SaveFile.
.elseif wParam == 1003.
invoke SaveFileAs.
.endif.
.if wParam == 1010.
invoke SendMessage, hWin, WM_SYSCOMMAND, SC_CLOSE, NULL.
.elseif wParam == 1900.
invoke About.
.endif.
.if wParam == 1100.
Edit_Undo:
invoke SendMessage, hEdit, WM_UNDO, 0,0.
.elseif wParam == 1101.
Edit_Cut:
invoke SendMessage, hEdit, WM_CUT, 0,0.
.elseif wParam == 1102.
Edit_Copy:
invoke SendMessage, hEdit, WM_COPY, 0,0.
.elseif wParam == 1103.
Edit_Paste:
invoke SendMessage, hEdit, WM_PASTE, 0,0.
.elseif wParam == 1104.
invoke SendMessage, hEdit, WM_CLEAR, 0,0.
.elseif wParam == 1105.
invoke WordWrap.
.endif.
;====== end menu commands ======.
.elseif uMsg == WM_SETFOCUS.
invoke SetFocus, hEdit.
.elseif uMsg == WM_SYSCOLORCHANGE.
invoke Do_ToolBar, hWin.
.elseif uMsg == WM_CREATE.
invoke Do_ToolBar, hWin.
invoke Do_Status, hWin.
mov WrapFlag, 0.
invoke EditML, NULL, 0,30,300,200,hWin, 700, WrapFlag.
mov hEdit, eax.
invoke SetWindowLong, hEdit, GWL_WNDPROC, EditProc.
mov lpEditProc, eax.
szText OFFWrap," Wrap OFF" .
invoke SendMessage, hStatus, SB_SETTEXT, 1, ADDR OFFWrap.
.elseif uMsg == WM_SIZE.
invoke SendMessage, hToolBar, TB_AUTOSIZE, 0,0.
invoke MoveWindow, hStatus, 0,0,0,0,TRUE.
invoke GetClientRect, hToolBar, ADDR Rct.
push Rct.bottom.
pop tbh.
invoke GetClientRect, hStatus, ADDR Rct.
push Rct.bottom.
pop sbh.
invoke GetClientRect, hWin, ADDR Rct.
push Rct.right.
pop wWid.
push Rct.bottom.
pop wHgt.
mov eax, tbh.
sub wHgt, eax.
mov eax, sbh.
sub wHgt, eax.
add tbh, 2.
sub wHgt, 2.
invoke MoveWindow, hEdit, 0, tbh, wWid, wHgt, TRUE.
.elseif uMsg == WM_CLOSE.
invoke SendMessage, hEdit, EM_GETMODIFY, 0,0.
.if eax == TRUE.
invoke Confirmation, hWin.
.if eax == IDYES.
invoke SaveFile.
.elseif eax == IDCANCEL.
mov eax, 0.
ret.
.endif.
.endif.
.elseif uMsg == WM_DESTROY.
invoke PostQuitMessage, NULL.
return 0.
.endif.
invoke DefWindowProc, hWin, uMsg, wParam, lParam.
ret.
WndProc endp.
TopXY proc wDim: DWORD, sDim: DWORD.
shr sDim, 1.
shr wDim, 1.
mov eax, wDim.
sub sDim, eax.
return sDim.
TopXY endp.
; ########################################################################.
EditML proc szMsg: DWORD, tx: DWORD, ty: DWORD, wd: DWORD, ht: DWORD,.
hParent:DWORD, ID: DWORD, Wrap: DWORD.
LOCAL hCtl: DWORD.
LOCAL hFnt: DWORD.
LOCAL eStyle: DWORD.
szText CtlStyle," EDIT" .
mov eStyle, WS_VISIBLE or WS_CHILDWINDOW or.
WS_VSCROLL or ES_NOHIDESEL or.
ES_AUTOVSCROLL or ES_MULTILINE.
.if Wrap == 0.
or eStyle, WS_HSCROLL or ES_AUTOHSCROLL.
.endif.
invoke CreateWindowEx, WS_EX_CLIENTEDGE, ADDR CtlStyle, szMsg,.
eStyle, tx, ty, wd, ht, hParent, ID, hInstance, NULL.
mov hCtl, eax.
invoke GetStockObject, SYSTEM_FIXED_FONT.
mov hFnt, eax.
invoke SendMessage, hCtl, WM_SETFONT, hFnt, TRUE.
mov eax, hCtl.
ret.
EditML endp.
; ########################################################################.
Read_File_In proc lpszDiskFile: DWORD, hEditControl: DWORD.
LOCAL hFile: DWORD.
LOCAL hMem$ :DWORD.
LOCAL ln: DWORD.
LOCAL br: DWORD.
LOCAL txtBuffer[64] :BYTE.
invoke CreateFile, lpszDiskFile, GENERIC_READ, FILE_SHARE_READ,.
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL.
mov hFile, eax.
invoke GetFileSize, hFile, NULL.
mov ln, eax.
.if ln > 32 767.
invoke CloseHandle, hFile.
szText tooBig," Sorry, file is too large for QIKPAD" .
invoke MessageBox, hWnd, ADDR tooBig, ADDR szDisplayName, MB_OK.
xor eax, eax.
ret.
.endif.
invoke SysAllocStringByteLen, 0, ln.
mov hMem$, eax.
invoke ReadFile, hFile, hMem$, ln, ADDR br, NULL.
invoke SetWindowText, hEditControl, hMem$.
invoke SysFreeString, hMem$.
invoke CloseHandle, hFile.
invoke lnstr, ADDR szOpenedAt.
inc eax.
invoke MemCopy, ADDR szOpenedAt, ADDR txtBuffer, eax.
invoke dwtoa, ln, ADDR sizeBuffer.
invoke lstrcat, ADDR txtBuffer, ADDR sizeBuffer.
invoke lstrcat, ADDR txtBuffer, ADDR bytes.
invoke SendMessage, hStatus, SB_SETTEXT, 2, ADDR txtBuffer.
ret.
Read_File_In endp.
; ########################################################################.
Confirmation proc hMain: DWORD.
szText ConfirmMsg," File not saved, save it now ?" .
invoke MessageBox, hMain, ADDR ConfirmMsg, ADDR szDisplayName,.
MB_YESNOCANCEL or MB_ICONQUESTION.
ret.
Confirmation endp.
; ########################################################################.
Write2_Disk proc lpszFile_Name:DWORD.
LOCAL ln: DWORD.
LOCAL hMem$ :DWORD.
LOCAL hFile: DWORD.
LOCAL bw: DWORD.
LOCAL txtBuffer[64].
invoke CreateFile, lpszFile_Name,.
GENERIC_WRITE,.
NULL,.
NULL,.
CREATE_ALWAYS,.
FILE_ATTRIBUTE_NORMAL,.
NULL.
mov hFile, eax.
invoke GetWindowTextLength, hEdit.
mov ln, eax.
inc ln.
invoke SysAllocStringByteLen, 0, ln.
mov hMem$, eax.
invoke GetWindowText, hEdit, hMem$, ln.
invoke WriteFile, hFile, hMem$, ln, ADDR bw, NULL.
invoke SysFreeString, hMem$.
invoke CloseHandle, hFile.
invoke SendMessage, hEdit, EM_SETMODIFY, FALSE, 0.
invoke lnstr, ADDR szSavedAt.
inc eax.
invoke MemCopy, ADDR szSavedAt, ADDR txtBuffer, eax.
invoke dwtoa, ln, ADDR sizeBuffer.
invoke lstrcat, ADDR txtBuffer, ADDR sizeBuffer.
invoke lstrcat, ADDR txtBuffer, ADDR bytes.
invoke SendMessage, hStatus, SB_SETTEXT, 2, ADDR txtBuffer.
ret.
Write2_Disk endp.
SaveFileAs proc.
jmp @F.
szTitleS db «Save file as», 0.
szFilterS db «All files», 0," *.*", 0,.
" Text files", 0," *.TEXT", 0,0.
@@:
invoke FillBuffer, ADDR szFileName, length szFileName, 0.
invoke SaveFileName, hWnd, ADDR szTitleS, ADDR szFilterS.
cmp szFileName[0], 0.
je @F.
invoke Write2_Disk, ADDR szFileName.
invoke SetWindowText, hWnd, ADDR szFileName.
@@:
ret.
SaveFileAs endp.
; #########################################################################.
SaveFile proc.
LOCAL buffer[128]: BYTE.
invoke GetWindowText, hWnd, ADDR buffer, 128.
invoke lstrcmp, ADDR buffer, ADDR szUntitled.
.if eax == 0.
invoke SaveFileAs.
ret.
.endif.
invoke Write2_Disk, ADDR buffer.
ret.
SaveFile endp.
; #########################################################################.
WordWrap proc.
LOCAL mFlag: DWORD.
LOCAL ln: DWORD.
LOCAL hMem$:DWORD.
invoke SendMessage, hEdit, EM_GETMODIFY, 0,0.
mov mFlag, eax.
invoke GetWindowTextLength, hEdit.
mov ln, eax.
inc ln.
invoke SysAllocStringByteLen, 0, ln.
mov hMem$, eax.
invoke GetWindowText, hEdit, hMem$, ln.
invoke DestroyWindow, hEdit.
.if WrapFlag == 0.
mov WrapFlag, 1.
szText WrapON," Wrap ON" .
invoke SendMessage, hStatus, SB_SETTEXT, 1, ADDR WrapON.
.elseif WrapFlag == 1.
mov WrapFlag, 0.
szText WrapOFF," Wrap OFF" .
invoke SendMessage, hStatus, SB_SETTEXT, 1, ADDR WrapOFF.
.endif.
invoke EditML, NULL, 0,30,300,200,hWnd, 700, WrapFlag.
mov hEdit, eax.
invoke SetWindowLong, hEdit, GWL_WNDPROC, EditProc.
mov lpEditProc, eax.
invoke SendMessage, hWnd, WM_SIZE, 0,0.
invoke SetWindowText, hEdit, hMem$.
invoke SysFreeString, hMem$.
invoke SendMessage, hEdit, EM_SETMODIFY, mFlag, 0.
invoke SetFocus, hEdit.
ret.
WordWrap endp.
; #########################################################################.
EditProc proc hCtl: DWORD,.
uMsg :DWORD,.
wParam :DWORD,.
lParam :DWORD.
.if uMsg == WM_KEYUP.
.if wParam == VK_F1.
invoke About.
.elseif wParam == VK_F9.
invoke WordWrap.
.elseif wParam == VK_ESCAPE.
invoke SendMessage, hWnd, WM_SYSCOMMAND, SC_CLOSE, NULL.
return 0.
.endif.
.endif.
invoke CallWindowProc, lpEditProc, hCtl, uMsg, wParam, lParam.
ret.
EditProc endp.
; #########################################################################.
About proc.
szText AboutMsg," QikPad Text Editor", 13,10,.
" Copyright © MASM32 1999″ .
invoke ShellAbout, hWnd, ADDR szDisplayName, ADDR AboutMsg, hIcon.
ret.
About endp.
; #########################################################################.
end start.