Question

Is there any code that i can call to refresh the image display(used paint) on the win32 but maintaining the messages? I only wish to update only the fingerprint image and show the live image. The text windows + the other picture remains.

http://imgur.com/S6UcpAt

EDIT:

case WM_PAINT:

    wmId    = LOWORD(wParam);
    hdc = BeginPaint(hWnd, &ps);

refresh=!refresh;
    if((start==true)&&(refresh==true)&&(stop!=true))
    {       
        if(cycle==0)
            {
                myKad(hWnd);
                    cycle=1;
            }
    windowName = MultiByteStringToWideString(name1, CP_ACP);
    LoadAndBlitBitmap(windowName.c_str(), hdc,500,0);
    fingerprint();
    LoadAndBlitBitmap(TEXT("outresized.bmp"), hdc,500,300);
    refresh=!refresh;
    char buffer[100]; // Just to show the # of loops it is at
    sprintf(buffer,"%d",round);
     windowName = MultiByteStringToWideString(buffer, CP_ACP);
    ::MessageBox(NULL,windowName.c_str(), __T("Error"), MB_OK);//just to show #loop.
    round++;

    ::MessageBox(NULL,__T("REFRESHED"), __T("Error"), MB_OK);

    //RedrawWindow(hWnd,&fingerprintSection,NULL,RDW_INTERNALPAINT|RDW_VALIDATE|RDW_UPDATENOW|RDW_NOCHILDREN);
    InvalidateRect( hWnd, &fingerprintSection, TRUE );
    }
    EndPaint(hWnd, &ps);

OLD

this is the what i tried but still unsuccessful

RECT fingerprintSection;//area that i want to refresh
fingerprintSection.left=500;
fingerprintSection.top=300;
fingerprintSection.bottom=540;
fingerprintSection.right=660;

if (wmId!=IDM_STOP)
    {

    fingerprint(); //this function will save the fingerprint to "outresized.bmp"

    LoadAndBlitBitmap(TEXT("outresized.bmp"), hdc,500,300);
    InvalidateRect( hWnd, &fingerprintSection, TRUE );
}

this is my bitmap code if u want to see

bool LoadAndBlitBitmap(LPCWSTR szFileName, HDC hWinDC,int x,int y)
{
// Load the bitmap image file
HBITMAP hBitmap;
hBitmap = (HBITMAP)::LoadImage(NULL, szFileName, IMAGE_BITMAP, 0, 0,
    LR_LOADFROMFILE);
// Verify that the image was loaded
if (hBitmap == NULL) {
    ::MessageBox(NULL, __T("LoadImage Failed"), __T("Error"), MB_OK);
    return false;
}

// Create a device context that is compatible with the window
HDC hLocalDC;
hLocalDC = ::CreateCompatibleDC(hWinDC);
// Verify that the device context was created
if (hLocalDC == NULL) {
    ::MessageBox(NULL, __T("CreateCompatibleDC Failed"), __T("Error"), MB_OK);
    return false;
}

// Get the bitmap's parameters and verify the get
BITMAP qBitmap;
int iReturn = GetObject(reinterpret_cast<HGDIOBJ>(hBitmap), sizeof(BITMAP),
    reinterpret_cast<LPVOID>(&qBitmap));
if (!iReturn) {
    ::MessageBox(NULL, __T("GetObject Failed"), __T("Error"), MB_OK);
    return false;
}

// Select the loaded bitmap into the device context
HBITMAP hOldBmp = (HBITMAP)::SelectObject(hLocalDC, hBitmap);
if (hOldBmp == NULL) {
    ::MessageBox(NULL, __T("SelectObject Failed"), __T("Error"), MB_OK);
    return false;
}

// Blit the dc which holds the bitmap onto the window's dc
BOOL qRetBlit = ::BitBlt(hWinDC, x, y, qBitmap.bmWidth, qBitmap.bmHeight,
    hLocalDC, 0, 0, SRCCOPY);
if (!qRetBlit) {
    ::MessageBox(NULL, __T("Blit Failed"), __T("Error"), MB_OK);
    return false;
}

// Unitialize and deallocate resources
::SelectObject(hLocalDC, hOldBmp);
::DeleteDC(hLocalDC);
::DeleteObject(hBitmap);
return true;
}
Was it helpful?

Solution

You could use InvalidateRect in your case, since there is no text or part of other image over the fingerprint.

You just need the RECT of the fingerprint to pass as second parameter.

From what I see in your post, you seem to load and blit fingerprint in LoadAndBlitBitmap, so you could use that function to update some global RECT variable in order to pass it as a second parameter.

Without seeing more code all I can advise for now is this:

if (wmId!=IDM_STOP)
{
    fingerprint();

    LoadAndBlitBitmap(TEXT("outresized.bmp"), hdc,500,300);

    InvalidateRect( hWnd, &RectOfMyFingerprint, TRUE );
}

EDIT:

You can use your button to capture and save the image of the bitmap.

Then all you need to do is invalidate the window to redraw captured image.

Try moving your LoadAndBlitBitmap into WM_PAINT:

case WM_PAINT:
    {
         BeginPaint();

         LoadAndBlitBitmap();

         EndPaint;
    }

Your button handler should look like this:

if ( wmId == IDM_STARTSCANNING)
{
    fingerprint(); // capture your bitmap
}
else
    if (wmId == IDM_STOP)
    {
        // order redrawing
        InvalidateRect( hWnd, &RectOfMyFingerprint, TRUE ); 
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top