Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
have the following code ...
    case WM_PAINT:
    {
        hdc = BeginPaint(hwnd,&paintSt);
        temphdc = hdc;
        GetClientRect(hwnd,&aRect);
        if(hBitmap!=NULL)
        {               
            HDC memDC = CreateCompatibleDC(hdc);
            if(memDC!=NULL)
            {
                BITMAP bmp;
		GetObject(hBitmap,sizeof(bmp),&bmp);
		SelectObject(memDC,hBitmap);
		SetStretchBltMode(hdc,HALFTONE);
		
                StretchBlt(hdc,0,0,aRect.right,aRect.bottom,
	        memDC,0,0,bmp.bmWidth,bmp.bmHeight,
		SRCCOPY);
		
                // Delete the BITMAP structure
		DeleteObject(&bmp);
		//ReleaseDC(hwnd,memDC);
		DeleteDC(memDC);  
					    
                SendMessage(picBoxCrop,STM_SETIMAGE,NULL,NULL);
            }
        }           
        // the code for painting 
        EndPaint(hwnd,&paintSt);
    }
    break;
..... now here is the code from the proc of picBoxCrop
LRESULT CALLBACK cropWndProc(HWND hwnd,UINT msg, WPARAM wParam, LPARAM lParam)
{
	static HDC hdc;
	PAINTSTRUCT paintSt;
	RECT aRect;
	switch(msg)
	{
		case WM_PAINT:
		{
			hdc = BeginPaint(hwnd,&paintSt);
			GetClientRect(hwnd,&aRect);
				// The code 
			if(hBitmap!=NULL)
			{
				HDC memDC = CreateCompatibleDC(hdc);
				if(memDC!=NULL)
				{
					SelectObject(memDC,hBitmap);
				     if(StretchBlt(hdc,0,0,aRect.right,aRect.bottom,
                                             memDC,0,0,100,100,SRCCOPY)==false)
				     {
				       MessageBox(NULL,"StretchBlt()  
                                       failed...","Error!! Bad Programming.",MB_OK);
					}
				}
				else
				MessageBox(NULL,"memDC of cropDisp cant be 
                                created","Error!! Bad Programming.",MB_OK);
				
                                DeleteDC(memDC);
			}			
			EndPaint(hwnd,&paintSt);
		}
		break;
		case STM_SETIMAGE:
			{
				InvalidateRect(hwnd,&aRect,true);
			}
			break;
		case WM_CREATE:
			{}break;	
		case WM_ERASEBKGND:
			{
				InvalidateRect(hwnd,&aRect,true);
			}break;
		default:
		 return DefWindowProc(hwnd,msg,wParam,lParam);
	}
	return 0;
}

Now the problem is .... the image in picBoxCrop is displayed when we minimize or disable the window once (by bringing some other window to front)... once that is done after that both the images are displayed correctly...

My objective here is to crop the part of the image from the original box to this picBoxCrop....

I am a newbie in WIN32 programming. . .. . . any help will be appreciated...

thanks in advance,

[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
Posted
Updated 7-May-11 2:35am
v2

1 solution

You don't receive WM_PAINT, that's why. It's triggered when you minimize or mask a windows by some other window and show a part of your window again. To trigger is programmatically you need to invalidate the window where you render your graphics.

The simplest way of doing so is Windows API InvalidateRect, see http://msdn.microsoft.com/en-us/library/dd145002(v=vs.85).aspx[^]. Another way is API InvalidateRgn, see http://msdn.microsoft.com/en-us/library/dd145195(v=vs.85).aspx[^].

MFC has the function CWnd::Invalidate, see http://msdn.microsoft.com/en-us/library/ax04k970(v=VS.100).aspx[^].

[EDIT]
You already use InvalidateRect in your STM_SETIMAGE, but why do you think this message is sent? I don't see where you "associate a new image with a static control" (I refer to http://msdn.microsoft.com/en-us/library/bb760782(v=vs.85).aspx[^]). The pattern of using invalidation is simple: you render some data in WM_PAIN handler. At the moment the data is changed, you need to invalidate your window explicitly to trigger WM_PAINT.

—SA
 
Share this answer
 
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900