Using external functions in a script

This section shows an example that uses some of the external function declarations for Windows CE functions in “Sample declarations”. The example displays a Date Time Picker control from the Microsoft common controls library commctrl.dll. For more information about the constant values and other parameters to the external functions, see the Microsoft documentation.

// First set instance variables
// ulong g_hwndCal
// CONSTANT ulong ICC_DATE_CLASSES = 256 // 0x100
// CONSTANT ulong WS_BORDER = 8388608    // 0x0080 0000
// CONSTANT ulong WS_CHILD = 1073741824  // 0x4000 0000
// CONSTANT ulong WS_VISIBLE = 268435456 // 0x1000 0000
// CONSTANT ulong SWP_NOZORDER = 4
// CONSTANT long HWND_TOP      = 0
// CONSTANT ulong MCM_GETMINREQRECT = 4105
// CONSTANT ulong MCM_SETCOLOR  = 4106  // 0x100A
// CONSTANT ulong MCSC_MONTHBK = 4      // background
                                        // of a month
// CONSTANT ulong COLOR_MONTH = 12648447  // 0xC0ffff
                                     // (muted yellow)
// Specify the class of the date picker control
string ClassName = "SysDateTimePick32" 

long lret
ulong sizeRect[]
ulong xPBUnits, yPBUnits

ulong HeightTitleBar = 0      //  For PDA, set to 0 

// Initialize the Common Controls DLL
ulong aInitCtrls[2]
aInitCtrls[1] = 8      // structure size
aInitCtrls[2] = ICC_DATE_CLASSES

lret = InitCommonControlsEx( aInitCtrls ) // external
if lret = 0 then
   return 0
end if


// make the calendar control 
g_hwndCal = CreateWindowEx( 0, ClassName, "", &
      WS_BORDER + WS_CHILD + WS_VISIBLE, &
      0,0,0,0, &
      Handle(this), 0, 0, 0 )

// If really created, initialize the control
if g_hwndCal <> 0 then
   // Set the calendar color 
   SendMessageLong( g_hwndCal, MCM_SETCOLOR, &
      MCSC_MONTHBK, COLOR_MONTH )

   // Set the size to what the control requests
   sizeRect[1] = 0
   sizeRect[2] = 0
   sizeRect[3] = 0
   sizeRect[4] = 0
   // Get the minimum size required to display a
   // full month in the control
   SendMessagePtr( g_hwndCal, MCM_GETMINREQRECT, 0, &
      sizeRect )

   // set the calendar control size 
   SetWindowPos( g_hwndCal, HWND_TOP, 0, 0, &
      sizeRect[3], sizeRect[4], SWP_NOZORDER )
   
   // Set the PARENT window (this) to that size
   this.width  = PixelsToUnits( sizeRect[3],
      XPixelsToUnits! )
   this.height = PixelsToUnits
      ( sizeRect[4] + HeightTitleBar, YPixelsToUnits! )
end if