Below is a variation on the code Semen Matusovski publish a few
weeks ago on coloring buttons. It works well, but I'd like to
add one generalization to it:
From inside the CALLBACK function I'd like to
get access to the string declared on the DDT
CONTROL ADD BUTTON call. In this case either
the string "11111" or "22222".
I've looked thru the DRAWITEMSTRUCT definitions and find no
link to the string the button created.
Does anyone know this information, or perhaps know the fact
that it is NOT "visible" from inside the CALLBACK function?
---------------------------------------------------------------
#COMPILE EXE
#REGISTER NONE
#INCLUDE "Win32Api.Inc"
%ID_Button=301
GLOBAL BrushRed AS LONG
CALLBACK FUNCTION hDlg_CB
SELECT CASE CBMSG
CASE %WM_DRAWITEM
DIM t AS DRAWITEMSTRUCT PTR
t=CBLPARAM '**** DONT'T UNDERSTAND HOW THIS WORKs *****
x&[email protected]@t.rcItem.nleft
y&[email protected]@t.rcItem.ntop
'Fill area with Red and frame it with black
CALL FillRect(@t.hDc,@t.rcItem,BrushRed)
CALL FrameRect(@t.hDc,@t.rcItem,GetStockObject(%BLACK_BRUSH))
SetBkMode @t.hDC,%TRANSPARENT
'invert the tRectangle if the button is selected
IF(@t.itemState AND %ODS_SELECTED) THEN
CALL InvertRect(@t.hDC,@t.rcItem)
SetTextColor @t.hDC,%BLACK
ELSE
SetTextColor @t.hDC,%WHITE
END IF
DrawText @t.hDC,"",-1,BYVAL VARPTR(@t.RcItem),%DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
FUNCTION=%True
END SELECT
END FUNCTION
FUNCTION PBMAIN() AS LONG
DIM BrushRed AS LONG
LOCAL hDlg AS LONG
LOCAL Lb AS LOGBRUSH
Lb.lbStyle=%BS_SOLID
Lb.lbColor=%Red:BrushRed=CreateBrushIndirect(Lb)
DIALOG NEW 0,"Color Button Example",0,0,105,120,%DS_CENTER OR %WS_SYSMENU TO hDlg
CONTROL ADD BUTTON,hDlg,%ID_Button+0,"11111",10,10,80,12,%WS_TABSTOP OR %BS_OWNERDRAW
CONTROL ADD BUTTON,hDlg,%ID_Button+1,"22222",10,50,80,12,%WS_TABSTOP OR %BS_OWNERDRAW
DIALOG SHOW MODAL hDlg CALL hDlg_CB
END FUNCTION
weeks ago on coloring buttons. It works well, but I'd like to
add one generalization to it:
From inside the CALLBACK function I'd like to
get access to the string declared on the DDT
CONTROL ADD BUTTON call. In this case either
the string "11111" or "22222".
I've looked thru the DRAWITEMSTRUCT definitions and find no
link to the string the button created.
Does anyone know this information, or perhaps know the fact
that it is NOT "visible" from inside the CALLBACK function?
---------------------------------------------------------------
#COMPILE EXE
#REGISTER NONE
#INCLUDE "Win32Api.Inc"
%ID_Button=301
GLOBAL BrushRed AS LONG
CALLBACK FUNCTION hDlg_CB
SELECT CASE CBMSG
CASE %WM_DRAWITEM
DIM t AS DRAWITEMSTRUCT PTR
t=CBLPARAM '**** DONT'T UNDERSTAND HOW THIS WORKs *****
x&[email protected]@t.rcItem.nleft
y&[email protected]@t.rcItem.ntop
'Fill area with Red and frame it with black
CALL FillRect(@t.hDc,@t.rcItem,BrushRed)
CALL FrameRect(@t.hDc,@t.rcItem,GetStockObject(%BLACK_BRUSH))
SetBkMode @t.hDC,%TRANSPARENT
'invert the tRectangle if the button is selected
IF(@t.itemState AND %ODS_SELECTED) THEN
CALL InvertRect(@t.hDC,@t.rcItem)
SetTextColor @t.hDC,%BLACK
ELSE
SetTextColor @t.hDC,%WHITE
END IF
DrawText @t.hDC,"",-1,BYVAL VARPTR(@t.RcItem),%DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
FUNCTION=%True
END SELECT
END FUNCTION
FUNCTION PBMAIN() AS LONG
DIM BrushRed AS LONG
LOCAL hDlg AS LONG
LOCAL Lb AS LOGBRUSH
Lb.lbStyle=%BS_SOLID
Lb.lbColor=%Red:BrushRed=CreateBrushIndirect(Lb)
DIALOG NEW 0,"Color Button Example",0,0,105,120,%DS_CENTER OR %WS_SYSMENU TO hDlg
CONTROL ADD BUTTON,hDlg,%ID_Button+0,"11111",10,10,80,12,%WS_TABSTOP OR %BS_OWNERDRAW
CONTROL ADD BUTTON,hDlg,%ID_Button+1,"22222",10,50,80,12,%WS_TABSTOP OR %BS_OWNERDRAW
DIALOG SHOW MODAL hDlg CALL hDlg_CB
END FUNCTION
Comment