WildByDesign Posted July 17 Posted July 17 I'm trying to learn more about the _WinAPI_CreateFont function. In particular, I'm trying to understand how to properly set the $iPitch parameter. The help file shows: Quote [optional] Specifies the pitch and family of the font. The two low-order bits specify the pitch of the font and can be one of the following values: $DEFAULT_PITCH, $FIXED_PITCH, $VARIABLE_PITCH The four high-order bits specify the font family and can be one of the following values: $FF_DECORATIVE - Novelty fonts. Old English is an example $FF_DONTCARE - Use default font (Default) $FF_MODERN - Fonts with constant stroke width, with or without serifs. Pica, Elite, and Courier New are examples $FF_ROMAN - Fonts with variable stroke width and with serifs. MS Serif is an example $FF_SCRIPT - Fonts designed to look like handwriting. Script and Cursive are examples $FF_SWISS - Fonts with variable stroke width and without serifs. MS Sans Serif is an example By default, most example functions throughout the forum use 0 for that parameter. The part that I don't understand here is the two low-order bits and four high-order bits for the parameter. I don't understand how that works for this specific parameter. My assumption is that this is different from doing a simple BitOR of the two values. How would I set the $iPitch parameter, for example, $DEFAULT_PITCH and $FF_SCRIPT? Thank you. Here is the example script for _WinAPI_CreateFont from the docs as a starting point: expandcollapse popup#include <FontConstants.au3> #include <StructureConstants.au3> #include <WinAPIGdi.au3> #include <WinAPIGdiDC.au3> #include <WinAPIHObj.au3> #include <WinAPISysWin.au3> Global $g_tRECT, $g_hFont, $g_hOldFont, $g_hDC HotKeySet("{ESC}", "_Exit") $g_tRECT = DllStructCreate($tagRect) DllStructSetData($g_tRECT, "Left", 5) DllStructSetData($g_tRECT, "Top", 5) DllStructSetData($g_tRECT, "Right", 250) DllStructSetData($g_tRECT, "Bottom", 50) $g_hDC = _WinAPI_GetDC(0) $g_hFont = _WinAPI_CreateFont(50, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial') $g_hOldFont = _WinAPI_SelectObject($g_hDC, $g_hFont) _WinAPI_SetTextColor($g_hDC, 0x0000FF) _WinAPI_SetBkColor($g_hDC, 0x000000) ; comment next line to get black background instead of transparent one _WinAPI_SetBkMode($g_hDC, $TRANSPARENT) While 1 _WinAPI_DrawText($g_hDC, "Hello world!", $g_tRECT, $DT_CENTER) Sleep(100) WEnd Func _Exit() _WinAPI_SelectObject($g_hDC, $g_hOldFont) _WinAPI_DeleteObject($g_hFont) _WinAPI_ReleaseDC(0, $g_hDC) _WinAPI_InvalidateRect(0, 0) $g_tRECT = 0 Exit EndFunc ;==>_Exit
Solution Nine Posted July 17 Solution Posted July 17 From MSDN : Quote An application can specify a value for the fdwPitchAndFamily parameter by using the Boolean OR operator to join a pitch constant with a family constant. Looking at the family constants they already added a 0 in front of the value (ex : $FF_DECORATIVE = 0x80, $FF_SWISS = 0x20, etc) So you just have to do a BitOR of the two constants (pitch and family). I think... WildByDesign 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
pixelsearch Posted July 17 Posted July 17 Yes BitOr() should do the job as the type of iPitchAndFamily is BYTE (as found in the msdn webpage LOGFONTW structure, where we read : The two low-order bits specify the pitch of the font [...] Bits 4 through 7 of the member specify the font family [...] The proper value can be obtained by using the bitwise OR (|) operator to join one pitch constant with one family constant. It shouldn't be a problem if the msdn webpage CreateFont indicates DWORD instead of BYTE. WildByDesign 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
WildByDesign Posted July 17 Author Posted July 17 Thank you both for clarifying and for your time. Using BitOR does appear to be working. Excellent.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now