Chris,
Roland produced an example: examples\WinDynDialogs\OwnerDrawn.o2bas
Control( "", ID_Button, "BUTTON", BS_OWNERDRAW or WS_DLGFRAME, 35, 20, 20, 20 )
'====================================================================
' Owner-draw button demo, modal dialog as main.
'
' Adapted from an example in the Microsoft PSDK
' using bitmaps from: examples\GL\NeHe\data\
'====================================================================
'% review
uses dialogs
'namespace
% DS_CENTER=0x0800
% LR_LOADFROMFILE=0x0010
% IMAGE_BITMAP=0
% ODS_SELECTED=1
% WM_DRAWITEM=0x2B
% SRCCOPY=0xCC0020
type DRAWITEMSTRUCT
uint CtlType
uint CtlID
uint itemID
uint itemAction
uint itemState
sys hwndItem
sys hDC
RECT rcItem
dword itemData
end type
! StretchBlt lib "gdi32.dll" (sys hdcDest,int nXOriginDest,nYOriginDest,nWidthDest,nHeightDest,sys hdcSrc,int nXOriginSrc,nYOriginSrc,nWidthSrc,nHeightSrc,dword dwRop) as bool
% ID_Button=100
'====================================================================
function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback
static sys hBmp1, hBmp2
static sys hdcMem
select case uMsg
case WM_INITDIALOG
hBmp1 = LoadImage( null, "mask1.bmp" , IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
if hBmp1 = null then mbox "mask1.bmp missing!"
hBmp2 = LoadImage( null, "mask2.bmp" , IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
if hBmp2 = null then mbox "mask2.bmp missing!"
return true
case WM_DRAWITEM
DRAWITEMSTRUCT lpdis at lParam
hdcMem = CreateCompatibleDC( lpdis.hDC )
if (lpdis.itemState and ODS_SELECTED) then
SelectObject( hdcMem, hBmp2 )
else
SelectObject( hdcMem, hBmp1)
end if
StretchBlt( lpdis.hDC,
lpdis.rcItem.left,
lpdis.rcItem.top,
lpdis.rcItem.right - lpdis.rcItem.left,
lpdis.rcItem.bottom - lpdis.rcItem.top,
hdcMem,
0,
0,
128,
128,
SRCCOPY )
' Return hDC member of DRAWITEMSTRUCT to default state.
' This is ESSENTIAL for proper button operation.
DeleteDC( hdcMem )
return true
case WM_COMMAND
if loword(wParam) = IDCANCEL then
' This will allow the user to close the
' dialog by pressing the Escape key.
EndDialog( hDlg, null )
end if
if hiword(wParam) = BN_CLICKED then
select case loword(wParam)
case ID_Button
#ifdef review
printl "Click..."
#endif
end select
return true
end if
case WM_CLOSE
DeleteObject( hBmp1 )
DeleteObject( hBmp2 )
EndDialog( hDlg, null )
end select
return 0
end function
'====================================================================
sys lpdt
dyn::init(lpdt)
Dialog( 1, 0, 0, 100, 75, "Owner Draw Button Demo", lpdt,
WS_OVERLAPPED or WS_SYSMENU or DS_CENTER )
'Control( "", ID_Button, "BUTTON", BS_OWNERDRAW or WS_DLGFRAME, 35, 20, 20, 20 )
PushButton( "", ID_Button, 35, 20, 20, 20, BS_OWNERDRAW or WS_DLGFRAME )
CreateModalDialog( 0, @DialogProc, 0, lpdt )
'====================================================================