Solved

F3 + LMB

Posted on 1999-01-17
6
246 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:st2599
  • 2
  • 2
  • 2
6 Comments
 
LVL 12

Expert Comment

by:migel
ID: 1327859
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
}
}
0
 
LVL 1

Accepted Solution

by:
sunj earned 50 total points
ID: 1327860
How about checking GetKeyState(VK_F3) == -128 in your OnLButtonUp(UINT nFlags, CPoint point) callback?

sunj

0
 

Author Comment

by:st2599
ID: 1327861

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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:sunj
ID: 1327862
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
0
 

Author Comment

by:st2599
ID: 1327863
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
0
 
LVL 12

Expert Comment

by:migel
ID: 1327864
GetKeyState is not MFC function it is Windows API !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
if loop in java 3 129
bigDiff challenge 17 84
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 193
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now