
'====================================================================
'' Bitmap background demo, modal dialog as main.
''
'' This source sizes the dialog client area to fit the bitmap.
'' Note that the Dialog Template Unit (DTU) to pixel conversions
'' are necessary so the size of the client area and the position
'' of the button will not vary with the font used (assuming the
'' dialog uses the system font).
'====================================================================

#include "dialogs.bas"

'====================================================================

'-----------------------------------------------
'' These functions convert from pixels to DTUs,
'' using the method specified in the API.
'-----------------------------------------------

Function PixelToDtuX( Byval pixelX As Integer ) As Integer
  Return MulDiv( pixelX, 4, loword(GetDialogBaseUnits) )
End Function

Function PixelToDtuY( Byval pixelY As Integer ) As Integer
  Return MulDiv( pixelY, 8, hiword(GetDialogBaseUnits) )
End Function

'====================================================================

Function DialogProc( Byval hDlg As  HWND, _
                     Byval uMsg As UINT, _
                     Byval wParam As WPARAM, _
                     Byval lParam As LPARAM ) As Integer

  Static As HBITMAP hbmp
  Static As HBRUSH hbrush

  Select Case uMsg

    Case WM_INITDIALOG

      hbmp = LoadImage( null, "fblogo.bmp", IMAGE_BITMAP, _
                        0, 0, LR_LOADFROMFILE )

      hbrush = CreatePatternBrush( hbmp )

    Case WM_CTLCOLORDLG

      Return cast(Integer,hbrush)

    Case WM_COMMAND

      If hiword(wParam) = BN_CLICKED Then
        DeleteObject( hbmp )
        DeleteObject( hbrush )
        EndDialog( hDlg, null )
      End If

    Case WM_CLOSE

      DeleteObject( hbmp )
      DeleteObject( hbrush )
      EndDialog( hDlg, null )

  End Select

  Return 0

End Function

'====================================================================

Dim As LPDLGTEMPLATE lpdt

'----------------------------------------------------
'' The Pixel to DTU conversions will get the size of
'' the client area close to the size of the bitmap.
'----------------------------------------------------

Dialog( 1, 0, 0, PixelToDtuX(320), _
        PixelToDtuX(240 + GetSystemMetrics( SM_CYCAPTION ) + 5), _
        "Test", lpdt, WS_OVERLAPPED Or WS_SYSMENU Or DS_CENTER )

PushButton( 101, -1, PixelToDtuY(145), 30, 10, "OK", WS_TABSTOP )

CreateModalDialog( 0, @DialogProc, 0, lpdt )

'====================================================================
 