Link to home
Start Free TrialLog in
Avatar of sunshine737
sunshine737

asked on

Problem with changing the position of cross mark on BMP image

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
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlexFM
AlexFM

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.