Solved

Sending data while pushbutton is down?

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 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