'====================================================================
' MONTHCAL_CLASS common control demo, modal dialog as main.
'====================================================================
' a little bit modified 

$ filename "Calendar.exe"
'uses rtl32
'uses rtl64

'% review

uses dialogs

macro RGB(r,g,b) {r+(g<<8)+(b<<16)}
macro MonthCal_SetColor(hmc,iColor,clr) (SendMessaGE(hmc,MCM_SETCOLOR,iColor,clr))

% MCM_SETCOLOR=0x100A
% MCSC_BACKGROUND=0
% MCSC_MONTHBK=4
% MCSC_TEXT=1
% MCSC_TITLEBK=2
% MCSC_TITLETEXT=3
% MCSC_TRAILINGTEXT=5

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

function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback
  sys calendar = GetDlgItem(hDlg,100)

  select case uMsg

    case WM_INITDIALOG
       MonthCal_SetColor(calendar, MCSC_TITLETEXT    , RGB(0,0,0))
       MonthCal_SetColor(calendar, MCSC_TITLEBK      , RGB(245,175,0))
       MonthCal_SetColor(calendar, MCSC_BACKGROUND   , RGB(175,175,175))
       MonthCal_SetColor(calendar, MCSC_MONTHBK      , RGB(248,245,225))
       MonthCal_SetColor(calendar, MCSC_TEXT         , RGB(0,0,225))
       MonthCal_SetColor(calendar, MCSC_TRAILINGTEXT , RGB(0,225,0))
    
    case WM_COMMAND
       if loword(wParam) = IDCANCEL then
         EndDialog( hDlg, null )
       end if

    case WM_CLOSE
       EndDialog( hDlg, null )

    case WM_SIZE
       int cxClient = LOWORD (lParam)
       int cyClient = HIWORD (lParam)
       SetWindowPos( calendar, 0, 0, 0, cxClient, cyClient, SWP_NOMOVE or SWP_NOREDRAW )

  end select

  return 0
end function

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

init_common_controls()

Dialog( 0, 0, 120, 110, "Nice Calendar",
        WS_OVERLAPPEDWINDOW or DS_CENTER )
Control( "", 100,  MONTHCAL_CLASS, 0, -1, 0, 120, 100 )

CreateModalDialog( 0, @DialogProc, 0 )

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