May 15, 2024, 04:07:11 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Still having a problem

Started by Rock Ridge Farm (Larry), January 20, 2006, 10:37:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rock Ridge Farm (Larry)

I have a data entry field on the screen. I want to mouse click the field and allow the
user to enter a string. When the user leaves the field or presses enter, I want to collect
the entered data in a var. How do I do that?

Parker

You have to subclass the edit control and process character messages and the WM_KILLFOCUS message.

Bruce Peaslee

Try this in your dialog class:


CEdit *pEdit;
string sText;
int value;

Select nID
{
ÂÃ,  case txtEdit:
ÂÃ,  if nNotifycode = ENKILLFOCUSÂÃ,  // focus has moved on
ÂÃ,  {
ÂÃ,  ÂÃ,  pEditÂÃ, = GetControl(txtEdit);
ÂÃ,  ÂÃ,  sText = pEdit->GetText();
ÂÃ,  ÂÃ,  value = val(result);ÂÃ, 
ÂÃ,  }
}
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Parker

And just to note, a string can only hold 255 characters. Calling GetText twice can fix the problem:
string *sText = new(byte, len(pEdit->GetText()));
*sText = pEdit->GetText();


In most single line edit cases it's fine to use just a string, but in some cases you need to use dynamic memory like this. You can also limit the length if you want through a windows message.

Rock Ridge Farm (Larry)

I still do not have this working.
The program is the listview example I posted in projects.
I added a field to the underlying container and want to read user input.
I have a couple of weeks of trial and error so far.
HELP - I know it is something simple - I just do not seem to find it.

Rock Ridge Farm (Larry)

I am creating the field:
   d1.AddControl(CTEDIT,"",95,485,60,20,0x50800800,0x200,GET_USR);
I added the code previously suggested.
I do not seem to be able to enter characters or give focus to the field.

Ionic Wind Support Team

You need to post your code so we can help.  The code snippit given by peaslee is just a fragment and belongs in the OnControl method of the dialog/window your using.

Ionic Wind Support Team

Rock Ridge Farm (Larry)

It is the same code I posted in the projects area with the addition of the code above and
the fragment from Peaslee.
Displays the data entry field - I just can not enter data there.

Ionic Wind Support Team

Yes but did you add the OnControl handler to the dialog class?

You have an OnNotify handler...in that handler you must also call the base class function for OnControl to work properly.


dlg::OnNotify(int code,int nID,NMHDR *pnmhdr),int {
CListView *pList1 = GetControl(1);
CListView *pList2 = GetControl(2);
CListView *pList3 = GetControl(3);
string sysbfr;

if(code = 0xFFFFFFFE){
if(nID = 1) {
sysbfr = pList1->GetItemText(*(NMLISTVIEW)pnmhdr.iItem,0);
pList2->DeleteAllItems();
pList3->DeleteAllItems();
DoShowUsr(sysbfr,pList2);
}
if(nID = 2){
sysbfr = pList2->GetItemText(*(NMLISTVIEW)pnmhdr.iItem,0);
pList3->DeleteAllItems();
DoShowXref(sysbfr,pList3);
}
}
        //REMEBER: Call the base class or OnControl won't work for notification messages,
return dialog!!OnNotify(code,nID,pnmhdr);
}


Also make sure you created your edit control in the dialog editor with the "Tab Stop" style.  Otherwise tabbing between the edit controls won't work and you'll not get any kill focus messages.

Add the OnControl method to your class:


class dlg:dialog
{
    ...
     declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
}


And the handler for it


dlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
....this is where peaslee's snippit goes.
}


Use member variables to save the input from the edit controls if needed.   The edit control also sends the ENCHANGE notification anytime text is entered into the control.
Ionic Wind Support Team

Rock Ridge Farm (Larry)

Had all that except the part in the OnNotify section.
What should go there?
Do I check for the mouse event?

Rock Ridge Farm (Larry)

Still not working - has to be the on-notify section.
I guess I do not understand what should be there.

Bruce Peaslee

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Rock Ridge Farm (Larry)

It is all in this thread - I just need the code to go in the onNotify class to actually do the
read. That is the only part I am missing.

Rock Ridge Farm (Larry)

Getting closer - I put some messagebox statements in the code to see where
I was getting to. I found that I am not collecting any characters in the field.
I also do not echo input chars.
The message boxes both contain null values.

dlg::OnControl(int nID, int eNotifycode, unsigned int hControl),int {
   CEdit *pEdit;
   string sText;
   string result;
   int value;

   Select nID {
      case GET_USR:
         if nNotifycode = ENKILLFOCUS {
            pEdit = GetControl(GET_USR);
            sText = pEdit->GetText();
            messagebox(0,sText,"poo");
            value = val(result);
            messagebox(0,result,"moo");
         }
   }   
   return true;
}

Bruce Peaslee

Two things I see right away:

You have "eNotifycode" in the declaration and "nNotifycode" in the if statement. Are you cutting and pasting this code or is it just a typo. "Result" is never given a value to its use in a messagebox would produce "".

I usually put the if test "if nNotifyCode = ENKILLFOCUS within parenthases.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Rock Ridge Farm (Larry)

It should have been 'n' - typo on my part. Still both messagebox statements produce
null output.
I can get the cursor in the text box but no text ever is shown as I type.
It has got to be some simple thing I do not understand.
All I want to do is enter text in a box on the screen and be able to get it in the program.
I would also like it to trigger when the user hits return.
There has to be a simple way to do this. I have been thru all the example code and
not found a text entry example.

Bruce Peaslee

It works for me without problems. But I have to get some sleep - it's late on the West Coast.

I'll try tomorrow to piece together your code.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

Edit controls work fine here too.  Are you sure you didn't check "Read Only" in the dialog editor?
Ionic Wind Support Team

Rock Ridge Farm (Larry)

Duh - I knew it had to be something simple - it was the read-only bit.
Never thought to look at that part of the code - I was sure it was in the  oncontrol code.
Now if I can undo all the bad stuff I did trying to make it work........
Thanks Paul.

Zen

He he. Thas usually my trademark. I always expect the most complicated things. 98% of the time it turns out they are the silly things you say "ohh it would not be anything that  simple" I never learn though :D

Lewis

Bruce Peaslee

This is why I replace the codes from the dialog editor with their "english" counterparts. I have posted a modestÂÃ,  8)ÂÃ,  program to help if you're interested.

50800800 ----->ÂÃ,  AWS_CHILD|AWS_VISIBLE|AWS_BORDER|AES_READONLY  (actual program output).
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Parker

Before I knew how combining bits and bitwise operations worked, I always thought it would be easier to output the strings instead :)

But now I can see that's not the case, unfortunately.

Ionic Wind Support Team

The style and extended styles are read from the control directly in the dialog editor.  It's easier to exclude styles when there in binary form, then parsing strings of course.

Button controls are the worst since Microsoft chose to use non exclusive style bits.  From the windows header files:


#define BS_PUSHBUTTON   0x00000000L
#define BS_DEFPUSHBUTTON 0x00000001L
#define BS_CHECKBOX     0x00000002L
#define BS_AUTOCHECKBOX 0x00000003L
#define BS_RADIOBUTTON  0x00000004L
#define BS_3STATE       0x00000005L
#define BS_AUTO3STATE   0x00000006L
#define BS_GROUPBOX     0x00000007L
#define BS_USERBUTTON   0x00000008L
#define BS_AUTORADIOBUTTON  0x00000009L
#define BS_OWNERDRAW        0x0000000BL
#define BS_LEFTTEXT     0x00000020L


Instead of using a 'mask' of bits they used consecutive numbers.  For example BS_AUTOCHECKBOX contains the bit for BS_DEFPUSHBUTTON.  So you can't just test using an 'and' operation like you can with window styles.  You have to test for the highest value first.

Starting with Windows 95 they got smart and used exclusive bits for additional styles:


#define BS_TEXT             0x00000000L
#define BS_ICON             0x00000040L
#define BS_BITMAP           0x00000080L
#define BS_LEFT             0x00000100L
#define BS_RIGHT            0x00000200L
#define BS_CENTER           0x00000300L
#define BS_TOP              0x00000400L
#define BS_BOTTOM           0x00000800L
#define BS_VCENTER          0x00000C00L
#define BS_PUSHLIKE         0x00001000L
#define BS_MULTILINE        0x00002000L
#define BS_NOTIFY           0x00004000L
#define BS_FLAT             0x00008000L
#define BS_RIGHTBUTTON      BS_LEFTTEXT


However someone was smoking too much ganja again and defined BS_TEXT as 0, the same as BS_PUSHBUTTON.  It is a wonder the control even works. ;)

Ionic Wind Support Team

Parker

I used to have a fun time with IBasic Standard putting random numbers in for the style and wondering why this number does the same as that number ;D, again it was before I knew about the bitwise operations.