Solved

F3 + LMB

Posted on 1999-01-17
6
243 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

17 Experts available now in Live!

Get 1:1 Help Now