Solved

Sending data while pushbutton is down?

Posted on 1999-01-14
2
197 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

IT, Stop Being Called Into Every Meeting

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

16 Experts available now in Live!

Get 1:1 Help Now