?
Solved

How to simulate a press button action

Posted on 2007-10-01
8
Medium Priority
?
1,174 Views
Last Modified: 2008-01-09
How to simulate a press button action
0
Comment
Question by:MobyMoebius
7 Comments
 
LVL 10

Expert Comment

by:Phatzer
ID: 19994134
In what code?
0
 

Author Comment

by:MobyMoebius
ID: 19994259
MFC CButton.

I want to turn a VK_RETURN into a WM_COMMAND BN_CLICKED. The following code is executed but no visible effect in the UI when I subclass the button as a CButtonR with the following PreTranslateMessage:.

BOOL CButtonR::PreTranslateMessage(MSG* pMsg)
{
    if (pMsg->message == WM_KEYDOWN && (int) pMsg->wParam == VK_RETURN)
    {
         GetParent()->SendMessage(WM_COMMAND,  BN_CLICKED, (LPARAM)m_hWnd);
     }
  return CButton::PreTranslateMessage(pMsg);
}
0
 

Author Comment

by:MobyMoebius
ID: 19994393
I figured it out: the second parameter to SendMessage should have encoded the button resource ID:

GetParent()->SendMessage(WM_COMMAND,  MAKEWPARAM(IDC_BUTTON_THIS_ONE, BN_CLICKED), (LPARAM)m_hWnd);

where IDC_BUTTON_THIS_ONE is the ID of the button in question.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 29

Expert Comment

by:chilternPC
ID: 19994830
I think its the second parameter to SendMessage it should have encoded the button resource ID:

GetParent()-> SendMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_THIS_ONE, BN_CLICKED), (LPARAM)m_hWnd);
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 19999434
You could use 2 functions like

        static double ConvertHoursToDecimal(double h1)
        {
            return (int)h1 + ((h1 * 10 % 10) / 6);
        }
// 7.3 will return 7.5

        static double ConvertDecimalToHours(double h1)
        {
            return (int)h1 + ((h1 - (int)h1)*0.6);
        }

// 7.6 will return 7.36
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 19999444
ignore above -- posted in error
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20209469
PAQed with points refunded (50)

Computer101
EE Admin
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

864 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