Solved

Sending data while pushbutton is down?

Posted on 1999-01-14
2
202 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
[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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

691 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