Solved

Sending data while pushbutton is down?

Posted on 1999-01-14
2
198 Views
Last Modified: 2013-11-20
I am using a CButton pushbutton on a VC++5 formview app.  I want to send data to the serial port while I keep the button down and it must stop to send when I release the button. I have sorted out sending data to the serial port.  How can I send it WHILE THE BUTTON IS DOWN?
0
Comment
Question by:heinv
2 Comments
 

Author Comment

by:heinv
ID: 1327658
Edited text of question
0
 

Accepted Solution

by:
koskia earned 30 total points
ID: 1327659
I guess you map both WM_LBUTTONDOWN and WM_LBUTTONUP, what you need to do is just send your data while you're in the OnLButtonDown() function, and check every X time, if a WM_LBUTTONUP message was recieved by the window, the function for that is PeekMessage:

void CMyButton::OnLButtonDown(UINT nFlags, CPoint point)
{
    bool IsUp = false;
    LPMSG pMsg;

    SetCapture();
    while (!IsUp)
    {
        if (PeekMessage(pMsg, m_hWnd, WM_LBUTTONUP,
        WM_LBUTTONUP, PM_NOREMOVE))
                IsUp = true;
        else
                SendSomeData();
    }
}

It's pretty self explanatory, but I'll explain anyway,
PeekMessage function checks if there are any messages of a given range in the windows queue,
the first parameter is a pointer to a message function (you don't really need that because you're only interested in 1 message).
if there are no messages of the given range, the function return 0, and you only have to check this return value.

the second parameter is a handle to the window (m_hWnd is a public member of every CWnd derived class)

the second and third parameters are the first and last message in a range of messages.
the last parameter is a flag, which indicates if a found message should be removed from the queue.

you check each X milliseconds, and send some more data, no simpler than that.
       
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

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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

11 Experts available now in Live!

Get 1:1 Help Now