RGB_value:
unused: B§ 0
blue: B§ ?
green: B§ ?
red: B§ ?
Note 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. We will create 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 as follows:
; #1 = red, #2 = green, #3 = blue
[RGB
|
mov eax 0
mov ah #3
shl eax,8
mov ah #2
mov al #1]
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.
call 'User32.ShowWindow' D§WindowHandle &SW_SHOWNORMAL
call 'User32.UpdateWindow' D§WindowHandle
L1:
call 'User32.GetMessageA' FirstMessage 0 0 0 | cmp eax 0 | je L9>
call 'User32.TranslateMessage' FirstMessage
call 'User32.DispatchMessageA' FirstMessage
jmp L1<
L9: call 'Kernel32.ExitProcess' 0
____________________________________________________________________________________________
Proc
MainWindowProc:
Arguments @Adressee, @Message, @wParam, @lParam
Local @hFont
Structure @PAINTSTRUCT 64 , @hdc 0
pushad
.If D@Message = &WM_DESTROY
call 'User32.PostQuitMessage' &NULL
.Else_If D@Message = &WM_PAINT
call 'User32.BeginPaint' D@Adressee D@PAINTSTRUCT
call 'GDI32.CreateFontA' 24 16 0 0 400 0 0 0 &OEM_CHARSET,
&OUT_DEFAULT_PRECIS &CLIP_DEFAULT_PRECIS,
&DEFAULT_QUALITY &DEFAULT_PITCH+&FF_SCRIPT,
FontName
call 'GDI32.SelectObject' D@hdc eax
mov D@hfont eax
RGB 200 200 50 | call 'GDI32.SetTextColor' D@hdc eax
RGB 0 0 255 | call 'GDI32.SetBkColor' D@hdc eax
call 'GDI32.TextOutA' D@hdc 0 0 OurText D§OurTextLen
call 'GDI32.SelectObject' D@hdc D@hfont
call 'User32.EndPaint' D@Adressee D@PAINTSTRUCT
.Else
popad
call 'User32.DefWindowProcA' D@Adressee D@Message D@wParam D@lParam
Exit
.End_If
popad | mov eax &FALSE
EndP
call
'GDI32.CreateFontA' 24 16 0 0 400 0 0 0 &OEM_CHARSET,
&OUT_DEFAULT_PRECIS &CLIP_DEFAULT_PRECIS,
&DEFAULT_QUALITY &DEFAULT_PITCH+&FF_SCRIPT,
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:DWORD
nHeight
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. However, in our example,
the default width makes the characters hard to read, so I use the width
of 16 instead.
nEscapement
Specifies the orientation 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:
The description above is by no means comprehensive. You should refer to your Win32 API reference for more details.
call 'GDI32.SelectObject' D@hdc eax
mov D@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 | call 'GDI32.SetTextColor' D@hdc eax
RGB 0 0 255 | call 'GDI32.SetBkColor' D@hdc eax
Use RGB macro to create a 32-bit RGB value to be used by SetColorText and SetBkColor.
call 'GDI32.TextOutA' D@hdc 0 0 OurText D§OurTextLen
Call TextOut function to draw the text on the client area. The text will be in the font and color we specified previously.
call 'GDI32.SelectObject' D@hdc D@hfont
When
we are through with the font, we should restore the old font back into
the device context. You should always restore the object that you replaced
in the device context.