ICZelion TUT5

zhaozj2021-02-11  205

Tutorial 5: More about text

Theory: Windows color system is based on RGB values, R = red, G = Green, B = Blue If you want to specify a color in Windows, you must state your desired color in terms of these three major colors Each color value.. HAS a Range from 0 to 255 (a byte value). For example, if You Want Pure Red Color, You Should Use 255,0,0. or if You Want Pure White Color, You Must Use 255,255,255. You can see from the Examples That Getting The Color You NEED IS VERY DIFFCIT with this system since you have to much a good gras.

For Text Color and Background, You Use SetTextColor and SetBkcolor, Both of Them Require A Handle To Device Context and a 32-bit RGB Value. The 32-bit RGB Value's Structure IS Defined AS:

RGB_VALUE STRUCT UNUSED DB 0 Blue DB? Green DB? Red DB? RGB_VALUE ENDS

Note We will create that the first byte is not used and should be zero. The order of the remaining three bytes is reversed, ie. Blue, green, red. However, we will not use this structure since it's cumbersome to initialize and use. A Macro INSTEAD. The Macro Will Receive Three Parameters: Red, Green and Blue Values. It'll Produce The Desired 32-Bit RGB Value and Store IT IN Eax. The Macro IS Follows:

RGB Macro Red, Green, Blue Xor Eax, Eax Mov Ah, Blue SHL EAX, 8 MOV AH, GREEN MOV Al, Red Endm

You can put this macro in the include file for future use You can "create" a font by calling CreateFont or CreateFontIndirect The difference between the two functions is that CreateFontIndirect receives only one parameter:.. A pointer to a logical font structure, LOGFONT. CreateFontIndirect is the more flexible of the two especially if your programs need to change fonts frequently. However, in our example, we will "create" only one font for demonstration, we can get away with CreateFont. After the call to CreateFont, it will Return a Handle to a font Which you must select into the Device Context. After That, Every TEXT API Function Will Use The Font We Have SELECTED INTO The Device Context.content:

.386

.Model flat, stdcall

Option CaseMAP: NONE

Winmain Proto: DWORD,: DWORD,: DWORD,: DWORD

include /masm32/include/windows.inc include /masm32/include/user32.inc include /masm32/include/kernel32.inc include /masm32/include/gdi32.inc includelib /masm32/lib/user32.lib includelib / masm32 / lib / kernel32.lib incrudelib /masm32/lib/gdi32.lib

RGB Macro Red, Green, Blue Xor Eax, Eax Mov Ah, Blue SHL EAX, 8 MOV AH, GREEN MOV Al, Red Endm

.data classname DB "SimpleWinclass", 0 Appname DB "Our First Window", 0 Teststring DB "Win32 Assembly Is Great And Easy!", 0 FontName DB "Script", 0

.DATA? Hinstance Hinstance? Commandline LPSTR?

. Code Start: Invoke GetModuleHandle, Null Mov Hinstance, Eax Invoke Getcommandline Mov Commandline, Eax Invoke Winmain, Hinstance, Null, CommandLine, SW_SHOWDEFAULT INVOKE EXITPROCESS, EAX

WinMain proc hInst: HINSTANCE, hPrevInst: HINSTANCE, CmdLine: LPSTR, CmdShow: DWORD 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 hInst pop wc.hInstance mov wc.hbrBackground, COLOR_WINDOW 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, CW_USEDEFAULT, / CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 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 endpWndProc proc hWnd: HWND, uMsg: UINT, wParam: WPARAM, LPARAM: LPARAM LOCAL HDC: HDC Local PS: Paintstruct local HFONT: HFONT

.IF uMsg == WM_DESTROY invoke PostQuitMessage, NULL .ELSEIF uMsg == WM_PAINT invoke BeginPaint, hWnd, ADDR ps mov hdc, eax invoke CreateFont, 24,16,0,0,400,0,0,0, OEM_CHARSET, / OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS , / DEFAULT_QUALITY, DEFAULT_PITCH or FF_SCRIPT, / ADDR FontName invoke SelectObject, hdc, eax mov hfont, eax RGB 200,200,50 invoke SetTextColor, hdc, eax RGB 0,0,255 invoke SetBkColor, hdc, eax invoke TextOut, hdc, 0,0, ADDR TestString, SIZEOF TestString invoke SelectObject, hdc, hfont invoke EndPaint, hWnd, ADDR ps .ELSE invoke DefWindowProc, hWnd, uMsg, wParam, lParam ret .ENDIF xor eax, eax ret WndProc endpend start

Analysis:

Invoke CreateFont, 24, 16, 0, 0, 400, 0, 0, OEM_CHARSET, /

OUT_DEFAULT_PRECIS, Clip_Default_Precis, /

Default_quality, default_pitch or ff_script, /

AddR fontname

CreateFont creates a logical font that is the closest match to the given parameters and the font data available. This function has more parameters than any other function in Windows. It returns a handle to logical font to be used by SelectObject function. We will examine its Parameters in detail.

CreateFont proto nHeight: DWORD, / nWidth: DWORD, / nEscapement: DWORD, / nOrientation: DWORD, / nWeight: DWORD, / cItalic: DWORD, / cUnderline: DWORD, / cStrikeOut: DWORD, / cCharSet: DWORD, / cOutputPrecision: DWORD , / cClipPrecision: DWORD, / cQuality: DWORD, / cPitchAndFamily: DWORD, / lpFacename:... DWORDnHeight The desired height of the characters 0 means use default size nWidth The desired width of the characters Normally this value should be 0 which allows Windows To match the width to the height. hoault width makees the characters hard to read, so i use the width of 16 instead. Nescapement Specifies the Orienta tion of the next character output relative to the previous one in tenths of a degree. Normally, set to 0. Set to 900 to have all the characters go upward from the first character, 1800 to write backwards, or 2700 to write each character from the top down. nOrientation Specifies how much the character should be rotated when output in tenths of a degree. Set to 900 to have all the characters lying on their backs, 1800 for upside-down writing, etc. nWeight Sets the line thickness of each Character. Windows Defines The Following Sizes:

FW_DONTCARE EQU 0

FW_thin EQU 100

FW_EXTRALIGHT EQU 200

FW_ULTRALIGHT EQU 200

FW_Light EQU 300

FW_NORMAL EQU 400

FW_REGULAR EQU 400

FW_MEDIUM EQU 500FW_SEMIBOLD EQU 600

FW_DEMIBOLD EQU 600

FW_BOLD EQU 700

FW_EXTRABOLD EQU 800

FW_ULTRABOLD EQU 800

FW_HEAVY EQU 900

FW_BLACK EQU 900

CITALIC 0 for Normal, Any Other Value for Italic Characters.

Cunderline 0 for Normal, Any Other Value for underlined Characters.

CSTRIKEOUT 0 for Normal, Any Other Value for Characters with a line through the center.

.

CoutputPrecision Specifies How much the selected font must be closely matched to the characteristics we want. Normal sale behavior.

cClipPrecision Specifies the clipping precision. The clipping precision defines how to clip characters that are partially outside the clipping region. You should be able to get by with CLIP_DEFAULT_PRECIS which defines the default clipping behavior.

. CQuality Specifies the output quality The output quality defines how carefully GDI must attempt to match the logical-font attributes to those of an actual physical font There are three choices:. DEFAULT_QUALITY, PROOF_QUALITY and DRAFT_QUALITY.

.

LPFACENAME A POINTER TO A NULL-TERMINATED STRING THE SPECIFIES The Typeface of The Font.

.................. ..

Invoke SelectObject, HDC, Eax Mov HFONT, EAX

After we get the handle to the logical font, we must use it to select the font into the device context by calling SelectObject. SelectObject puts the new GDI objects such as pens, brushs, and fonts into the device context to be used by GDI functions . It returns the handle to the replaced object which we should save for future SelectObject call. After SelectObject call, any text output function will use the font we just selected into the device context.RGB 200,200,50 invoke SetTextColor, hdc, eax RGB 0 , 0,255 Invoke SetBkcolor, HDC, EAX

Use rgb macro to create a 32-bit rgb value to be used by setColortext and setbkcolor.

Invoke TextOut, HDC, 0, 0, Addr Teststring, Sizeof Teststring

.

Invoke SelectObject, HDC, HFONT

WE Are Through with the font

转载请注明原文地址:https://www.9cbs.com/read-4673.html

New Post(0)