[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem with changing the position of cross mark on BMP image

Posted on 2004-11-15
2
Medium Priority
?
233 Views
Last Modified: 2013-11-20
Hi,

I am displaying BMP image with cross mark by using DirectDraw. I used the following functions.
-------------------------------------------------------------------------------------------------------------------------------
HBITMAP hbitmap = (HBITMAP)LoadImage(hinstance,bmp_name,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
HBITMAP old_bitmap = (HBITMAP)SelectObject(hdc,hbitmap);
HDC surfaceDC = NULL;
HRESULT result = backSurface->GetDC(&surfaceDC);
StretchBlt(surfaceDC,0,0,reSize.cx,reSize.cy,hdc,0,0,imageSize.cx,imageSize.cy,SRCCOPY);
HPEN pen = CreatePen(PS_DOT, 1, RGB(0,0,0));
HPEN oldPen = (HPEN)SelectObject(surfaceDC, pen);
MoveToEx(surfaceDC, 0, pt.y, NULL);
LineTo(surfaceDC, reSize.cx, pt.y);
MoveToEx(surfaceDC, pt.x, 0, NULL);
LineTo(surfaceDC, pt.x, reSize.cy);
SelectObject(surfaceDC, oldPen);
backSurface->ReleaseDC(surfaceDC);
SelectObject(hdc,old_bitmap);
DeleteObject(hbitmap);
----------------------------------------------------------------------------------------------------------

I am moving the cross on image by using key events, means for each event i am redrawing image and new position of cross. Its working well.
The problem is, when i am showing multiple images in loop with 40ms sleep time, i am unable to move the cross until it completes the loop. No event is working when loop is running. How can i move cross, ie independent from loop and image?

Thanking you
Vihar
0
Comment
Question by:vihar123
  • 2
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 1500 total points
ID: 12586500
There are two ways to solve this problem:

1) Instead of loop with Sleep refresh the screen by timer. This allows to handle keyboard messages between timer ticks and change pt value.

2) Using VB-like DoEvents finction:

void DoEvents()
{
    MSG msg;
   
    while ( ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE ) )
    {  
        if ( ::GetMessage(&msg, NULL, 0, 0))
        {
            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);
        }
        else
        {
            break;
        }
    }
}

void DoSomething()
{
     while ( ... )   // some loop
    {
         // Draw, Sleep etc. - any code

         DoEvents();    // handle events. Here pt value may be changed
    }
}

By the way, this is also the way to stop long process if user presses Stop or Cancel button. Notice that DoEvents handles any messages, for example, user may close window etc. - your program should be ready for this. When I use this way, I usually disable all UI elements except those which I expect to handle.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 12586539
Another function you can use in this situation is this:

void CGeneralFunctions::DoEventsEx(UINT wMsgFilterMin, UINT wMsgFilterMax)
{
    MSG msg;
   
    while ( ::PeekMessage(&msg, NULL, wMsgFilterMin, wMsgFilterMax, PM_NOREMOVE ) )
    {  
        if ( ::GetMessage(&msg, NULL, wMsgFilterMin, wMsgFilterMax))
        {
            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);
        }
        else
        {
            break;
        }
    }
}

Passing some message interval to this function, you handle only these messages, other messages remain in the message queue. You can use this function passing interval of keyboard messages. In this case current window will not be unexpectedly closed inside of loop.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

829 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