PowerBASIC Forums
  PowerBASIC for Windows
  tab from button to textbox??, text erased

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   tab from button to textbox??, text erased
Robert Alvarez
Member
posted February 21, 2006 11:11 PM     Click Here to See the Profile for Robert Alvarez     Edit/Delete Message   Reply w/Quote
I have on a dialog box two textboxes with text in it
and two buttons.

Focus is set to the button. When I tab to go from the
button to the textbox with text, the text in it is
erased and is highlighted or selected for ten charcters,
which is the string length for that box.

How can you prevent the text in textbox from being erased
when using the tab key??

------------------
Robert

IP: Logged

Clay Clear
Member
posted February 21, 2006 11:27 PM     Click Here to See the Profile for Clay Clear     Edit/Delete Message   Reply w/Quote
Sounds to me like you're manipulating the textbox text under the
WM_COMMAND window message. That is a normal thing to do, but you
should be aware that textbox's also send WM_COMMAND messages to
their parent dialog when they receive or lose the focus. So what
you need to do under the WM_COMMAND processor for the textbox is to
also test the value of HI(WORD, wparam) (if you're using DDT,
you can use the DDT CBCTLMSG statement). You will have to look in the
PB Help file to see what values are passed in CBCTLMSG for textboxes
when a textbox gets/loses the focus. Then you will need to modify
your code so it checks for those values and does whatever it needs
to instead of its default behavior for the WM_COMMAND message.

------------------

IP: Logged

Robert Alvarez
Member
posted February 22, 2006 10:19 PM     Click Here to See the Profile for Robert Alvarez     Edit/Delete Message   Reply w/Quote
Thanks for the reply Clay.

I do not manipulate text boxes using WM_COMMAND...use DDT CBCTLMSG...
or CBCTLMSG. That is something which I need to learn. I keep my code as
simple as possible.

In the sample lines of text below I also notice that tabing from the two inside textboxes
(tab and shift tab) to either side (going textbox to textbox) I loose the text in the end text boxes
and it is selected too.
Same for going from any button to the textbox. Same effect, loose text inside box
and is highlighted or selected. The two inside textboxes never loose their text in the
text box, but are selected. Hope you can help here with a sample code.


This is how I use text boxes to view my records, labels are not shown. There more textboxes but
do not shown them all in this example.

CONTROL ADD TEXTBOX, hDlg2, %CAT1 , CATA ,90,30, 25, 12, %ES_READONLY
CONTROL ADD TEXTBOX, hDlg2, %TIT1 ,TITA ,90,48, 25, 12, %ES_READONLY
CONTROL ADD TEXTBOX, hDlg2, %FNAM, FNAMA ,90,66, 75, 12, %ES_READONLY
CONTROL ADD TEXTBOX, hDlg2, %MNAM,MNAMA ,90,84, 75, 12, %ES_READONLY

This are just some of the button used.

CONTROL ADD BUTTON, hDlg2, %BU1, "&1 ADD", 5, 305, 40, 14, CALL Addr_Add
CONTROL ADD BUTTON, hDlg2, %BU2, "&2 CHG", 50, 305, 40, 14, CALL Addr_Chg
CONTROL ADD BUTTON, hDlg2, %BU3, "&3 PRT", 95, 305, 40, 14, 'CALL JOB_Prt

When I want to change a textbox field, I kill view textboxes and add textboxes like these,
buttons remain the same.

CONTROL ADD TEXTBOX, hDlg2, %CAT1, CATA ,90,30, 25, 12, 0
CONTROL ADD TEXTBOX, hDlg2, %TIT1, TITA ,90,48, 25, 12, 0
CONTROL ADD TEXTBOX, hDlg2, %FNAM, FNAMA,90,66, 75, 12, 0
CONTROL ADD TEXTBOX, hDlg2, %MNAM,MNAMA ,90,84, 75, 12, 0

------------------
Robert

IP: Logged

Chris Boss
Member
posted February 22, 2006 11:35 PM     Click Here to See the Profile for Chris Boss     Edit/Delete Message   Reply w/Quote
Robert,

Are you testing the CBCTLMSG value in the callback functions
for the button or textbox ?

If you don't you will have problems, since more than one
event occurs for both controls.

Here is how the code should look for a button or textbox:


CALLBACK FUNCTION CBF_FORM1_BUTTON1
IF CBCTLMSG=%BN_CLICKED THEN

END IF
END FUNCTION
'
' ------------------------------------------------
'
CALLBACK FUNCTION CBF_FORM1_TEXT1
IF CBCTLMSG=%EN_CHANGE THEN

END IF
END FUNCTION

You must test the CBCTLMSG value to make sure it is the correct
event (message).

These controls also will get events when the focus is changed
so it is possible your code is being executed when the focus
changes from control to control.

The callback functions in PB are responding to the events that
occur in the WM_COMMAND message of the parent dialog. DDT calls
the callbacks when the parent dialog gets the WM_COMMAND message
and it passes the values for that message to the callback.
Each control may receive more than one event through this
mechanism, so you must test the CBCTLMSG value to see what
the event is.

------------------
Chris Boss
Computer Workshop
Developer of "EZGUI"
http://ezgui.com

IP: Logged

Robert Alvarez
Member
posted February 23, 2006 10:52 PM     Click Here to See the Profile for Robert Alvarez     Edit/Delete Message   Reply w/Quote
Thank you for the reply Chris

Do not quite understand how to use CBCTLMSG. (looking at the help it is used different)
Here is what I did to my code. Added the callback function, and added call to two lines
as shown below. Do not understand how to add call to buttons since it already has
a call function there. Running the program resulted in no change. Did I have the code
in the wrong places? I also combined to two callback. Is that going to work?

Since I am just tabing past the buttons and not clicking them, here I do understand
where the code would be pluged in.

Coming from Dos to window programming is a task for me. I only have two
programs in window pb and never had this problems. Code is different for
this new program I am doing.


CALLBACK FUNCTION CBF_FORM1_BUTTON1
IF CBCTLMSG=%BN_CLICKED THEN
END IF
IF CBCTLMSG=%EN_CHANGE THEN
END IF
END FUNCTION

.......
......
CONTROL ADD TEXTBOX, hDlg2, %CAT1, CATA ,90,30, 25, 12, 0, CALL CBF_FORM1_BUTTON1
CONTROL ADD TEXTBOX, hDlg2, %TIT1, TITA ,90,48, 25, 12, 0
CONTROL ADD TEXTBOX, hDlg2, %FNAM, FNAMA,90,66, 75, 12, 0
CONTROL ADD TEXTBOX, hDlg2, %MNAM,MNAMA ,90,84, 75, 12, 0, CALL CBF_FORM1_BUTTON1

CONTROL ADD BUTTON, hDlg2, %BU1, "&1 ADD", 5, 305, 40, 14, CALL Addr_Add
CONTROL ADD BUTTON, hDlg2, %BU2, "&2 CHG", 50, 305, 40, 14, CALL Addr_Chg
CONTROL ADD BUTTON, hDlg2, %BU3, "&3 PRT", 95, 305, 40, 14, 'CALL JOB_Prt
.......
.......

------------------
Robert

IP: Logged

Chris Boss
Member
posted February 24, 2006 12:07 PM     Click Here to See the Profile for Chris Boss     Edit/Delete Message   Reply w/Quote
Robert,

First thing I noticed you did wrong:


CALLBACK FUNCTION CBF_FORM1_BUTTON1
IF CBCTLMSG=%BN_CLICKED THEN
END IF
IF CBCTLMSG=%EN_CHANGE THEN ' ERROR !!!!!
END IF
END FUNCTION

When processing events in a control callback, you must always
use notification messages associated with the control and not
others.

For example, all notification messages (events through WM_COMMAND)
for the Button control start with %BN_

You use a notification messages for Edit control (%EN_CHANGE)
which is not usable for a button control.

The first characters (up to the _ character) are considered
a prefix which indicates what control the message is associated
with.

The button control messages all start with %BM_ (B for Button, M for Message).
Those messages are sent using SendMessage.
The button notification messages (messages sent from control
to the parent dialog or notification of an event) all start
with %BN_ (B for button, N for notification).

The edit control messages start with %EM_ (E for edit, M for message)
and notification messages start with %EN_ (E for edit, N for notification).

The same goes for other controls.

Do not mix messages with other controls they aren't for !

------------------
Chris Boss
Computer Workshop
Developer of "EZGUI"
http://ezgui.com

IP: Logged

Robert Alvarez
Member
posted February 25, 2006 04:40 PM     Click Here to See the Profile for Robert Alvarez     Edit/Delete Message   Reply w/Quote
Found the problem, after fixing the code as you suggested it still had the same problem.

Fix was making the textbox larger to fit the longer string size. When I tabed into that textbox
the text was not erased it was just to the right and out of view. Hitting the home key showed
the text. (had only one character in textbox)

Well I'll add this member help topic to my library in case I later I do encounter a problem where
the text box is really erased.

Thanks Chris & Clay for your help

------------------
Robert

IP: Logged

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2007 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c