Lance asked to to post a sample program of a
problem I'm having reading text from a combobox using
CONTROL GET TEXT hDlg,Id& TO text$
The documentation says that
"hDlg& refers to the dialog that owns the control.
Id& is the unique control identifier you assigned
to the control with the CONTROL ADD statement. Any
text in the control is placed into the text$
variable. If the control is a combobox or listbox,
it will receive all of the strings in the control,
each one separated by NULs (CHR$(0))."
I get only a 4 byte hex value from my list.
- - - -
Start the program, Click the CHECK BOX and then
respond to the MSGBOX to write the full log of
all Dialog CB functions resceived, plus the text$
values read during handling of the %WM_DRAWITEM
message.
BTW, a second problem is the inability to find
a way to have a CHECKBOX allow the owner to draw it.
%MFT_OWNERDRAW does not seem to generate
%WM_DRAWITEM mesages!?
------------------------------------------------------
#COMPILE EXE
#INCLUDE "Win32Api.Inc"
%ID_Combo = 401
%ID_Check = 501
GLOBAL hDlg AS LONG
GLOBAL Audit() AS STRING
GLOBAL AuditCount AS LONG
CALLBACK FUNCTION Button_CB
STATIC nCall AS LONG
MSGBOX "Click to Write CB Msg Log"
OPEN "Audit.Dat" FOR OUTPUT AS #1:FOR i&=1 TO AuditCount:PRINT #1,Audit(i&):NEXT:close#1
END FUNCTION
CALLBACK FUNCTION CB
INCR AuditCount:Audit(AuditCount)=RIGHT$(" "+STR$(CBCTL),4)+"|"+RIGHT$(" "+HEX$(CBMSG),5)+"|"
DIM BrushLtBr AS STATIC LONG, BrushWhite AS STATIC LONG, BrushBlue AS STATIC LONG, BrushRed AS STATIC LONG
SELECT CASE CBMSG
CASE %WM_INITDIALOG
LOCAL Lb AS LOGBRUSH
Lb.lbStyle = %BS_SOLID
Lb.lbColor = &H80C0FF: BrushLtBr = CreateBrushIndirect(Lb)
Lb.lbColor = %White : BrushWhite = CreateBrushIndirect(Lb)
Lb.lbColor = %Blue : BrushBlue = CreateBrushIndirect(Lb)
Lb.lbColor = %Red : BrushRed = CreateBrushIndirect(Lb)
FUNCTION = %TRUE
CASE %WM_DESTROY
DeleteObject BrushLtBr: DeleteObject BrushWhite: DeleteObject BrushBlue: DeleteObject BrushRed
CASE %WM_CTLCOLORDLG ' Return the handle of the dialog background brush.
FUNCTION = BrushLtBr
CASE %WM_CTLCOLORSTATIC ', %WM_CTLCOLOREDIT
CASE %WM_DRAWITEM
DIM cx AS LONG, cy AS LONG
DIM tDrawItem AS DRAWITEMSTRUCT PTR
tDrawItem = CBLPARAM
SELECT CASE @tDrawItem.CtlID
CASE 401
cx = @tDrawItem.rcItem.nright - @tDrawItem.rcItem.nleft
cy = @tDrawItem.rcItem.nbottom - @tDrawItem.rcItem.ntop
'Fill area with white and frame it with black
CALL FillRect(@tDrawItem.hDc,@tDrawItem.rcItem, BrushRed)
CALL FrameRect(@tDrawItem.hDc,@tDrawItem.rcItem, GetStockObject(%BLACK_BRUSH))
'invert the tRectangle if the button is selected
' Control Set Text CbHndl, %ID_Button, Time$
CONTROL GET TEXT CBHNDL, CBCTL TO text$ '<< according to PB DOC should be list
INCR AuditCount:Audit(AuditCount)="*** Text from Combo List Box |"+text$+"|"
IF (@tDrawItem.itemState AND %ODS_SELECTED) THEN
CALL InvertRect(@tDrawItem.hDC, @tDrawItem.rcItem)
SetBkMode @tDrawItem.hDC, %TRANSPARENT
SetTextColor @tDrawItem.hDC, %BLACK
ELSE
SetBkMode @tDrawItem.hDC, %TRANSPARENT
SetTextColor @tDrawItem.hDC, %WHITE
END IF
DrawText @tDrawItem.hDC,BYCOPY text$, -1, BYVAL VARPTR(@tDrawItem.RcItem), %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
' draw a focus tRectangle ifthe button has the focus
IF (@tDrawItem.itemState AND %ODS_FOCUS) THEN
InflateRect BYVAL VARPTR(@tDrawItem.RcItem), -cx / 32, -cy / 16
CALL DrawFocusRect(@tDrawItem.hDC, @tDrawItem.rcItem)
END IF
FUNCTION = %False
CASE ELSE
FUNCTION = %True
END SELECT
END SELECT
END FUNCTION
FUNCTION PBMAIN()
LOCAL AuditCount AS LONG
DIM Audit(1:100000) AS STRING
DIM Listing(1:3) AS STRING:Listing(1)="aaaaaaaa":Listing(2)="bbbbbbbbb":Listing(3)="cccccccc":
DIALOG NEW 0 ,"Stupid sample",0,0, 105, 200, %DS_CENTER OR %WS_SYSMENU TO hDlg
CONTROL ADD COMBOBOX,hDlg,%ID_Combo,Listing(),10,105,82,50,%CBS_DROPDOWNLIST OR %WS_TABSTOP OR %CBS_OWNERDRAWFIXED
CONTROL ADD CHECKBOX,hDlg,%ID_Check,"Here",10,125,30,14,%BS_LEFT OR %WS_TABSTOP OR %MFT_OWNERDRAW CALL Button_CB
DIALOG SHOW MODAL hDlg CALL CB
END FUNCTION
------------------------------------------------------
problem I'm having reading text from a combobox using
CONTROL GET TEXT hDlg,Id& TO text$
The documentation says that
"hDlg& refers to the dialog that owns the control.
Id& is the unique control identifier you assigned
to the control with the CONTROL ADD statement. Any
text in the control is placed into the text$
variable. If the control is a combobox or listbox,
it will receive all of the strings in the control,
each one separated by NULs (CHR$(0))."
I get only a 4 byte hex value from my list.
- - - -
Start the program, Click the CHECK BOX and then
respond to the MSGBOX to write the full log of
all Dialog CB functions resceived, plus the text$
values read during handling of the %WM_DRAWITEM
message.
BTW, a second problem is the inability to find
a way to have a CHECKBOX allow the owner to draw it.
%MFT_OWNERDRAW does not seem to generate
%WM_DRAWITEM mesages!?
------------------------------------------------------
#COMPILE EXE
#INCLUDE "Win32Api.Inc"
%ID_Combo = 401
%ID_Check = 501
GLOBAL hDlg AS LONG
GLOBAL Audit() AS STRING
GLOBAL AuditCount AS LONG
CALLBACK FUNCTION Button_CB
STATIC nCall AS LONG
MSGBOX "Click to Write CB Msg Log"
OPEN "Audit.Dat" FOR OUTPUT AS #1:FOR i&=1 TO AuditCount:PRINT #1,Audit(i&):NEXT:close#1
END FUNCTION
CALLBACK FUNCTION CB
INCR AuditCount:Audit(AuditCount)=RIGHT$(" "+STR$(CBCTL),4)+"|"+RIGHT$(" "+HEX$(CBMSG),5)+"|"
DIM BrushLtBr AS STATIC LONG, BrushWhite AS STATIC LONG, BrushBlue AS STATIC LONG, BrushRed AS STATIC LONG
SELECT CASE CBMSG
CASE %WM_INITDIALOG
LOCAL Lb AS LOGBRUSH
Lb.lbStyle = %BS_SOLID
Lb.lbColor = &H80C0FF: BrushLtBr = CreateBrushIndirect(Lb)
Lb.lbColor = %White : BrushWhite = CreateBrushIndirect(Lb)
Lb.lbColor = %Blue : BrushBlue = CreateBrushIndirect(Lb)
Lb.lbColor = %Red : BrushRed = CreateBrushIndirect(Lb)
FUNCTION = %TRUE
CASE %WM_DESTROY
DeleteObject BrushLtBr: DeleteObject BrushWhite: DeleteObject BrushBlue: DeleteObject BrushRed
CASE %WM_CTLCOLORDLG ' Return the handle of the dialog background brush.
FUNCTION = BrushLtBr
CASE %WM_CTLCOLORSTATIC ', %WM_CTLCOLOREDIT
CASE %WM_DRAWITEM
DIM cx AS LONG, cy AS LONG
DIM tDrawItem AS DRAWITEMSTRUCT PTR
tDrawItem = CBLPARAM
SELECT CASE @tDrawItem.CtlID
CASE 401
cx = @tDrawItem.rcItem.nright - @tDrawItem.rcItem.nleft
cy = @tDrawItem.rcItem.nbottom - @tDrawItem.rcItem.ntop
'Fill area with white and frame it with black
CALL FillRect(@tDrawItem.hDc,@tDrawItem.rcItem, BrushRed)
CALL FrameRect(@tDrawItem.hDc,@tDrawItem.rcItem, GetStockObject(%BLACK_BRUSH))
'invert the tRectangle if the button is selected
' Control Set Text CbHndl, %ID_Button, Time$
CONTROL GET TEXT CBHNDL, CBCTL TO text$ '<< according to PB DOC should be list
INCR AuditCount:Audit(AuditCount)="*** Text from Combo List Box |"+text$+"|"
IF (@tDrawItem.itemState AND %ODS_SELECTED) THEN
CALL InvertRect(@tDrawItem.hDC, @tDrawItem.rcItem)
SetBkMode @tDrawItem.hDC, %TRANSPARENT
SetTextColor @tDrawItem.hDC, %BLACK
ELSE
SetBkMode @tDrawItem.hDC, %TRANSPARENT
SetTextColor @tDrawItem.hDC, %WHITE
END IF
DrawText @tDrawItem.hDC,BYCOPY text$, -1, BYVAL VARPTR(@tDrawItem.RcItem), %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
' draw a focus tRectangle ifthe button has the focus
IF (@tDrawItem.itemState AND %ODS_FOCUS) THEN
InflateRect BYVAL VARPTR(@tDrawItem.RcItem), -cx / 32, -cy / 16
CALL DrawFocusRect(@tDrawItem.hDC, @tDrawItem.rcItem)
END IF
FUNCTION = %False
CASE ELSE
FUNCTION = %True
END SELECT
END SELECT
END FUNCTION
FUNCTION PBMAIN()
LOCAL AuditCount AS LONG
DIM Audit(1:100000) AS STRING
DIM Listing(1:3) AS STRING:Listing(1)="aaaaaaaa":Listing(2)="bbbbbbbbb":Listing(3)="cccccccc":
DIALOG NEW 0 ,"Stupid sample",0,0, 105, 200, %DS_CENTER OR %WS_SYSMENU TO hDlg
CONTROL ADD COMBOBOX,hDlg,%ID_Combo,Listing(),10,105,82,50,%CBS_DROPDOWNLIST OR %WS_TABSTOP OR %CBS_OWNERDRAWFIXED
CONTROL ADD CHECKBOX,hDlg,%ID_Check,"Here",10,125,30,14,%BS_LEFT OR %WS_TABSTOP OR %MFT_OWNERDRAW CALL Button_CB
DIALOG SHOW MODAL hDlg CALL CB
END FUNCTION
------------------------------------------------------
Comment