Solved

Sending data while pushbutton is down?

Posted on 1999-01-14
2
201 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
string initialization in java 11 117
scoreUp challenge 14 69
Bartender label printing - switch on and off graphics 3 74
I could not set window to top 4 44
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

733 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