|
|
I want this in my project.
User key in data in Edit Control and press enter,
then program will get these data for process some job...
My question is
What is the message that occur when user press enter?
I try to use WM_CHAR and WM_KEYDOWN but no work.
Please help me to solve this problem
|
|
|
|
|
For a single line edit control pressing Enter key is the same as clicking the default button
(the button with the BS_DEFPUSHBUTTON style) - typically OK or Cancel in a dialog.
If you want to catch the Enter key press you can do it in response to a WM_KEYDOWN message sent
to the edit control but the edit control needs the ES_WANTRETURN|ES_MULTILINE styles set.
Mark
|
|
|
|
|
The other poster answered your question, but for future reference on other message questions, add a "PreTranslateMessage" in your dialog and you can see all the messages that come through.
|
|
|
|
|
Actually I want to generate random 12 bit unsigned int and random 4 bit signed int and stores in 2 bytes(unsigned int) which is as follow.
2 bytes unsigned int = 12 bit unsigned int*pow(10,4-bit signed int)
Thanks in advance-
|
|
|
|
|
If you have NOT constraints on the ranges of both the 12-bit unsigned numbers and 4-bit signed ones, then you can generate and store directly a 16-bit unsigned random number (the result is the same).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
no dear I have to take in to account the range and the storage.
|
|
|
|
|
OK. What are the constraints on the ranges?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
unsigned int 12 bit (0 -> +4095)
the size should be 12 bit;
signed int 4 bit (-16 -> +15)
the size shoud be 4 bit;
thx.
|
|
|
|
|
Processors can only access memory by 8-bit blocks, i.e. bytes.
If spaces is a criterion, you'll need to pack your 12-bit values into bytes yourself. You can for example store them like this:
8-bit bytes : XXXXXXXX YYYYYYYY ZZZZZZZZ
12-bit values: JJJJJJJJ JJJJKKKK KKKKKKKK
i.e. use 3 bytes to store 2 12-bit values.
To store and extract the values, use simple bit-shifting. For mapping the 4-bit parts to signed ints, you can either use a lookup table or write a simple function that gets the MSB of the 4-bit value and map it to the MSB of the byte and adjust the rest accordingly.
|
|
|
|
|
ikbahrian wrote: signed int 4 bit (-16 -> +15)
You're wrong, since -8->+7 is the range for a 4-bit signed number. Moreover, you're NOT imposing constraints over ranges (you want to fully exploit ranges) hence you can safely follow the suggestion posted below by Joergen Sigvardsson
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
uint16 num = uint16(rand() % 65535) should do the trick. To get the components from the number:
uint16 n12bit = num & 4095;
int8 n4bit = ((num >> 12) & 7) * (((num >> 12) & 8) ? -1 : 1);
[edit]Per Mark's bug report! {/edit]Last modified: 36mins after originally posted --
|
|
|
|
|
Good answer!
I would change 1 thing - use those unused upper 4 bits instead of reusing the lower 4
int8 n4bit = ((num >> 12) & 7) * ((num & 8) ? -1 : 1);
(per the OPs spec )
Cheers!
Mark
|
|
|
|
|
int8 n4bit = ((num >> 12) & 7) * (((num >> 12) & 8) ? -1 : 1); Good catch! I also fixed your code a little (you forgot to shift for getting the sign bit)
|
|
|
|
|
Thanks!
|
|
|
|
|
|
You can also use a union to extract the components
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: You can also use a union to extract the components
Going for extra credit - Yeah!
|
|
|
|
|
thanks
|
|
|
|
|
One thing that hasn't been suggested yet is to use bitfields:
USHORT twelvebitnum :12;
USHORT fourbitnum :4;
Now you can generate your 12-bit number and your 4-bit number and simply
twelvebitnum = 3500;
fourbitnum = 5;
These two values are actually stored in a single 16-bit USHORT. The location of these within the USHORT are insignificant since you access them by the variable name, but the first one defined starts with the lowest x-number of bits, then the next one takes the next y-number of bits, and so on.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Hi,
I've written a small command line program to send AT modem commands to a USB-connected GSM modem (in fact it's an old Nokia telephone). We use at work it to send SMS reports. Currently the program is still very much experimental, but has been working well. I followed Allen Denver's MSDN article "Serial Communications in Win32"
So, in my program I would open a handle to the com port to which the modem is connected. Then, I would write each of the following strings in turn, separated by a 2.5 second pause.
1) "AT+CMGF=1\x0D" to indicate SMS mode.
2) "AT+CMGS=\"+44NNNNNNNNNN\"\x0D" to indicated the destination phone number.
3) "SMS Text\x1A\x0D" to indicate the text to send in the message and terminate the message.
Each of these strings is written to the previous file handle within a function I wrote and the return value from this function indicates the success or not of writing the string.
I'm not very experienced in serial comms programming. My question is, how do you tell in code that the modem is ready for input? For example, in HyperTerminal you get the "OK" prompt back. Is this just a feature of HyperTerminal? Am I already doing enough by checking that the string was written successfully? What is the "proper" thing to do after writing the string to the com port to check that the modem is ready for more input?
I am using C++ to write the program under Windows 2000 and XP.
Originally, I posted this in the Hardware forum, but I've not have many responses.
Thanks in advance.
|
|
|
|
|
|
The "OK" response is being sent by the phone. It is not part of HyperTerminal's behavior.
The way to handle this is:
1. Send command.
2. Read command echo, if the phone 'echo's what you sent it. If, when you are using HyperTerminal, you see the characters you send, then the phone is echoing.
3. Read response to command.
Software Zen: delete this;
|
|
|
|
|
I need help in grabbing frames form a webcam stream.
I have used the ISampleGrabber filter and added it in but i cant work out how to grab the frames. I have managed to grab them via setting the filter to buffer the samples but i dont need this i just need to grab a single frame on request. Im using C++ in VS2005.
Any help would be great.
|
|
|
|
|
On the ISampleGrabber interface you can use GetCurrentBuffer() or SetCallback().
Which method are you trying to use?
Mark
|
|
|
|