#Include once "window9.bi"

Dim Shared cf As ChooseFont
Dim Shared As LOGFONT lf
Function FontRequester(hwnd As HWND = 0, nColor As Integer = 0) As Integer Export
  Dim As HFONT hfont
  ZeroMemory(@cf, sizeof(cf))
  cf.lStructSize = sizeof (cf)
  cf.hwndOwner = hwnd
  cf.lpLogFont = @lf
  cf.rgbColors = nColor
  cf.Flags = 1 or 256
  if (ChooseFont(Cast(LPCHOOSEFONT,@cf))=TRUE) Then
    hfont = CreateFontIndirect(cast(LOGFONT ptr,cf.lpLogFont))
  EndIf
  Return Cast(integer,hfont)
End Function

Function SelectedFontColor() As Integer Export
  Return cf.rgbColors
End Function

Function SelectedFontName() As string Export
  Return lf.lfFaceName
End Function

Function SelectedFontSize() As Integer Export
  Dim As HDC hdc=GetDC( 0 )
  Function =  -MulDiv(lf.lfHeight,72 , GetDeviceCaps(hdc,LOGPIXELSY) )
  ReleaseDC(0,hdc)
End Function

Function SelectedFontStyle(ByVal style As Byte) As byte Export
  Select Case style
    Case 1
      If lf.lfWeight<>700 Then
        Return 0
      Else
        Return 1
      EndIf
    Case 2
      Return -lf.lfItalic
    Case 3
      Return lf.lfUnderline
    Case 4
      Return lf.lfStrikeOut
  End Select
End Function
