Click to See Complete Forum and Search --> : Send a character to an edit box


Gyannea
October 25th, 2004, 10:57 AM
I would like to send a received character to an edit box as if I had typed it. I thought about using the WM_CHAR message but there is an ugly problem with the parameters. THe WPARAM is easy since it is just the ASCII code or virtual key code (not a problem here). However, the LPARAM is a problem since it is the key state which includes the OEM scan codes. In other words, there is no way I know of how to get the correct key state to send with this message that corresponds with the character I want to display. I have no idea what the scan codes are and they are manufacturer dependent. And of course, I have no idea what use the edit procedure makes of this parameter.

Does anyone know a way to send a character to be displayed in a edit box?

Thanks,

Brian

TBONE917
October 25th, 2004, 11:05 AM
One way to call SetWindowText on the edit box... if you used the class wizard you can call that variable or you can create your own and call SetWindowText on it

CEdit *pEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
pEdit->SetWindowText(char *);

this will set the edit box to whatever you pass in... if you want to append to what is in the edit box... call GetWindowText to retrieve the current text and then append using strcat or another function

Gyannea
October 25th, 2004, 12:48 PM
The downside to that approach is that I have to unload the whole buffer (which may be quite large) to input a single character which comes in as an intermitted stream from someone elses terminal as they are received over the radio. That is why I would like to send something like a WM_CHAR message.

It's also important to make it appear as close to the actual input rate by the sender.

There might be a way to access the Edit box buffer and add the character indirectly and update the screen...but this starts getting deleicate as one needs to make assumptions about how the edit box actually handles things like that.

Brian

MrViggy
October 25th, 2004, 01:25 PM
Have you tried using WM_CHAR?

lParam - Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table.
0-15
Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
16-23
Specifies the scan code. The value depends on the OEM.
24
Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25-28
Reserved; do not use.
29
Specifies the context code. The value is 1 if the ALT key is held down while the key is pressed; otherwise, the value is 0.
30
Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31
Specifies the transition state. The value is 1 if the key is being released, or it is 0 if the key is being pressed.
These are all bits in the LPARAM parameter. If you don't need any of them, just pass 0 for the lParam. Also, the MSDN says:
Because there is not necessarily a one-to-one correspondence between keys pressed and character messages generated, the information in the high-order word of the lParam parameter is generally not useful to applications. The information in the high-order word applies only to the most recent WM_KEYDOWN message that precedes the posting of the WM_CHAR message.
So, I would just pass '0' for those bits.

Viggy

Gyannea
October 28th, 2004, 03:31 PM
Yes, I tried the WM_CHAR approach with 0 as the lParam and it seems to work. So far I have not found any inconsistencies in the behavior of the Edit Box. I hope it stays that way.

Brian

kawasaki056
October 29th, 2004, 01:58 AM
May be already you know, you can try,


// in case , for example,add 'A' , to the end of the Edit Control ,
char sztext[3] ; sztext[0] = 'A' ; sztext[1] = '\0' ;
SendMessage( hEdit , EM_SETSEL , -1,-1 ) ;
SendMessage( hEdit , EM_REPLACESEL , TRUE , (LPARAM)&sztext ) ;



thank you.

Gyannea
October 29th, 2004, 05:35 AM
I use that for deleting a character...but I didn't notice the -1, -1. I'll have to check what that combination means.

But I have been looking for a way to easily extract the last character entered into the edit box (the last character in the buffer) without unloading the entire buffer.

Does the -1, -1 mean the last entry in the buffer?

Brian

kannanbalu
October 31st, 2004, 02:27 PM
One dirty workaround could be to send a WM_KEYUP followed by WM_KEYDOWN message.