PDA

View Full Version : control get text



sandyrepope
16-03-2007, 06:02
Is control get text working? I've been trying to use it to get the text in a label and can't seem to understand how to do this.


CONTROL GET TEXT hwnd, ctrlID TO txtVarName
is all the help file says. I think that hwnd needs to be the number of the label. What I can't figure out is what does 'ctrlID to txtvarname' means. What should I put here?

Thanks
Sandy

kryton9
16-03-2007, 06:18
Sandy, hwnd is the handle to the window or dialog. CtrlID is the ID number of the control and the to txtVarName is the variable you assign the text too.

Here is an example:

'---03-16-2007

USES "UI"

' *******************************************************************
' * CONSTANTS *
' *******************************************************************

'---Control ID's
%Txt2 = 2
%Btn3 = 3

' *******************************************************************
' * GLOBAL VARIABLES *
' *******************************************************************
'General Vars
GLOBAL hDlg AS LONG
GLOBAL msg, wParam,lParam as long
GLOBAL txt as ASCIIZ*255

' *******************************************************************
' * MAIN PROGRAM *
' *******************************************************************
DIALOG NEW PIXELS , 0, "MyApp", 310, 0, 490, 480, %WS_SYSMENU, 0 TO hDlg
DIALOG SHOW modeless hDlg

'------------------------------Program Loop
while isWindow(hDlg)
msg = GetMessage(hDlg, wParam, lParam)
select case msg
case %WM_INITDIALOG
CONTROL ADD TEXTBOX , hDlg, %Txt2, "Txt 2", 4, 4, 384, 24
CONTROL ADD BUTTON , hDlg, %Btn3, "Btn 3", 252, 48, 128, 24

CASE %WM_COMMAND
SELECT CASE wParam

CASE %Btn3
'---Btn 3 Code Here
CONTROL GET TEXT hDlg, %Txt2 TO txt
'--- in this case the dialog handle is used, so instead of hwnd it is hDlg, this could be any variable name of type long
'--- but hWnd and hDlg seem to be used a lot.
'--- %Txt2 is a constant declared above, but it can be any integer or long, it is what you would use when adding
'--- the control with CONTROL ADD TEXTBOX

'--- now we can set the value in txt to the window caption
DIALOG SET TEXT hDlg, txt

END SELECT
CASE %WM_SYSCOMMAND
SELECT CASE wParam
CASE %SC_CLOSE
EXIT WHILE
END SELECT
END SELECT
wend

'------------------------------Program Clean Up
DIALOG END hDlg

ErosOlmi
16-03-2007, 08:54
Writing help file is the hardest and longest part in developing thinBasic.
At every new version I try my best to implement it but still not able to add all the info I would like. Sorry.

---Ken,
thanks for the support. Perfect.
I've just amended little parts in your example. Most important was last line that I change DIALOG END hDlg

---Sandy,
almost all statement in User Interface module have the window handle as first paramater followed by the control unique id. In this case

CONTROL GET TEXT hwnd, ctrlID TO txtVarName
hWnd is the handle of the window (or dialog) where the label control is
ctrlID is the unique number you assigned to the label with CONTROL ADD ...
txtVarName is the text variable name you want the text goes to

Eros

Michael Hartlef
16-03-2007, 11:10
Writing help file is the hardest and longest part in developing thinBasic.

In general this is the hardest part. For sure something most developers don't like.