Link to home
Start Free TrialLog in
Avatar of st2599
st2599

asked on

F3 + LMB

Hi,

when I used MOTIF three years ago, it was very easy to define a func. for F3+LMB message. Anybody know how to write the callback func. in MFC 5.0.

Thanks in advance,

Robin
Avatar of migel
migel

Hi!
You must add message nahdler for LMB press and inside this handler you must ask state of the F3 key.
for example:
CMyWnd::OnLButtonDow(CPoint pt, UINT uFlags)
{
if (::GetKeyState(VK_F3) < 0) //<- key pressed
{
//... do something
}
}
ASKER CERTIFIED SOLUTION
Avatar of sunj
sunj

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of st2599

ASKER


sunj's answer is correct. But I am a little confusing why GetKeyState(VK_F3) == -128. I looked up the manual that if key is down, the higher order bit of GetKeyState() is 1. that means GetKeyState() will return 10000000 00000000(in bits) since the return value is a short. then it should be 2^15=32768. Why, Sunj?

About migel's comment, you may try. We will never be able to get a negative value ::GetKeyState(VK_F3) < 0) //<- key pressed
like you used.

Thanks, guys.


Robin
Hi,

  I think migel's comment is correct and is actually better than my answer. (Strictly speaking, my answer is not correct). According to the manual, the higher order bit of GetKeyState() is 1 when the key is down, this means exactly that the return value is a negative number. It does not have to be -128, although most of the case it is.
  By the way, 10000000 00000000 is not 2^15 because the first bit '1' is treated as the sign bit.
  Instead of checking GetKeyState() == -128, I think you should do GetKeyState() < 0.

sunj
Avatar of st2599

ASKER

Hi,

I theory, I agree that  GetKeyState() < 0. since the high order bit of 10000000 00000000 indicates the sign. But in my program, I pressed F3 and click LMB, when prog. comes to

short t1, t2;
t1 = :: GetKeyState(VK_F3);
t2 = :: GetKeyState(VK_F2);

In the watch window, t1 = -128 and t2=1. You may try yourself. I don't why. It seems that MFC does not recognize the first sign bit.

Tao
GetKeyState is not MFC function it is Windows API !