Solved

F3 + LMB

Posted on 1999-01-17
6
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
notReplace  challenge 53 153
if loop in java 3 174
zeroFront challenge 7 136
sumHeights2  challenge 7 139
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

739 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