请教,如何取得某一种Font支持的Style?(200分)

  • 主题发起人 主题发起人 Randy_Mic
  • 开始时间 开始时间
R

Randy_Mic

Unregistered / Unconfirmed
GUEST, unregistred user!
在TFontDialog执行的时候可以看到,字体"System"的Style有"粗体,粗斜体"两种,但我自己用EnumFontFamiliesEx取出的Style怎么是空啊?<br>Up有分~~~~~~<br><br>代码如下:<br>function EnumFontFamExProc(lpelfe: PEnumLogFontEx;<br>&nbsp; lpntme: PNewTextMetricEx; FontType: DWORD; lParam: LPARAM): Integer;stdcall;<br>begin<br>{ &nbsp;tagENUMLOGFONTEXA = packed record<br>&nbsp; &nbsp; elfLogFont: TLogFontA;<br>&nbsp; &nbsp; elfFullName: array[0..LF_FULLFACESIZE - 1] of AnsiChar;<br>&nbsp; &nbsp; elfStyle: array[0..LF_FACESIZE - 1] of AnsiChar;<br>&nbsp; &nbsp; elfScript: array[0..LF_FACESIZE - 1] of AnsiChar;<br>&nbsp; end;<br>}<br>&nbsp; if lParam = 0 then<br>&nbsp; &nbsp; Form1.ListBox1.Items.Add(lpelfe.elfFullName)<br>&nbsp; else<br>&nbsp; &nbsp; Form1.ListBox2.Items.Add(lpelfe.elfStyle);<br>&nbsp; Result := 1;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; DC: HDC;<br>begin<br>&nbsp; LF.lfCharSet := DEFAULT_CHARSET;<br>&nbsp; LF.lfFaceName := '';<br>&nbsp; LF.lfPitchAndFamily := 0;<br>&nbsp; DC := GetDC(Handle);<br>&nbsp; EnumFontFamiliesEx(DC, LF, @EnumFontFamExProc, 0, 0);<br>&nbsp; ReleaseDC(Handle, DC);<br>end;
 
function StyleEnumProc(Enum: PEnumLogFontEx; <br>&nbsp; &nbsp;TextMetric: PNewTextMetricEx; FontType: Integer; <br>&nbsp; &nbsp;FaceList: TStrings): Integer; stdcall;<br>&nbsp; &nbsp;var<br>&nbsp; &nbsp; &nbsp;S: String;<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp;Result := 1;<br>&nbsp; &nbsp;S := Format('%s %s', [Enum.elfLogFont.lfFaceName, Enum^.elfStyle]);<br>&nbsp; &nbsp;if FaceList.IndexOf(S) &lt; 0 then<br>&nbsp; &nbsp; &nbsp;FaceList.Add(S) <br>end;<br><br>&nbsp;function FaceEnumProc(Enum: PEnumLogFontEx; <br>&nbsp; &nbsp;TextMetric: PNewTextMetricEx; FontType: Integer; <br>&nbsp; &nbsp;FaceList: TStrings): Integer; stdcall;<br>&nbsp; &nbsp;var<br>&nbsp; &nbsp; &nbsp;DC: THandle;<br>&nbsp; &nbsp; &nbsp;LogFont: TLogFont;<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp;Result := 1;<br>&nbsp; &nbsp;DC := GetDC(GetDesktopWindow);<br>&nbsp; &nbsp;if DC = 0 then<br>&nbsp; &nbsp; &nbsp;raise Exception.Create(SysErrorMessage(GetLastError));<br>&nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp;FillChar(LogFont, SizeOf(LogFont), 0);<br>&nbsp; &nbsp; &nbsp;with LogFont do begin<br>&nbsp; &nbsp; &nbsp; &nbsp;lfCharSet := DEFAULT_CHARSET;<br>&nbsp; &nbsp; &nbsp; &nbsp;lfFaceName := Enum.elfLogFont.lfFaceName;<br>&nbsp; &nbsp; &nbsp; &nbsp;lfPitchAndFamily := 0 end;<br>&nbsp; &nbsp; &nbsp;EnumFontFamiliesEx(DC, LogFont, @StyleEnumProc, LPARAM(FaceList),<br>&nbsp; &nbsp; &nbsp; &nbsp;0);<br>&nbsp; &nbsp;finally<br>&nbsp; &nbsp; &nbsp;ReleaseDC(GetDesktopWindow, DC) end <br>end;<br><br>&nbsp;procedure BuildFaceList(FaceList: TStrings);<br>&nbsp; &nbsp;var<br>&nbsp; &nbsp; &nbsp;DC: THandle;<br>&nbsp; &nbsp; &nbsp;LogFont: TLogFont;<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp;FaceList.Clear;<br>&nbsp; &nbsp;DC := GetDC(GetDesktopWindow);<br>&nbsp; &nbsp;if DC = 0 then<br>&nbsp; &nbsp; &nbsp;raise Exception.Create(SysErrorMessage(GetLastError));<br>&nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp;FillChar(LogFont, SizeOf(LogFont), 0);<br>&nbsp; &nbsp; &nbsp;with LogFont do begin<br>&nbsp; &nbsp; &nbsp; &nbsp;lfCharSet := DEFAULT_CHARSET;<br>&nbsp; &nbsp; &nbsp; &nbsp;lfFaceName := '';<br>&nbsp; &nbsp; &nbsp; &nbsp;lfPitchAndFamily := 0 end;<br>&nbsp; &nbsp; &nbsp;EnumFontFamiliesEx(DC, LogFont, @FaceEnumProc, LPARAM(FaceList),<br>&nbsp; &nbsp; &nbsp; &nbsp;0);<br>&nbsp; &nbsp;finally<br>&nbsp; &nbsp; &nbsp;ReleaseDC(GetDesktopWindow, DC) end <br>end;<br>
 
兄弟,不行啊,你的办法还是取不出来~~~~
 
后退
顶部