为什么仅在最小化Window之后才显示图像? [英] Why the image is displayed only after I minimize the Window ?

查看:107
本文介绍了为什么仅在最小化Window之后才显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有以下代码...

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;
}


现在的问题是....当我们最小化或禁用一次窗口(通过将其他窗口置于最前面)时,会显示picBoxCrop中的图像...一旦完成,两个图像都将正确显示...

我的目的是将图像的一部分从原始框裁剪到此picBoxCrop ....

我是WIN32编程的新手. . .. .任何帮助将不胜感激...

预先感谢,

[edit]已添加代码块,忽略HTML ..."选项已禁用-OriginalGriff [/edit]


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]

推荐答案

您没有收到WM_PAINT,表明"是为什么.当您最小化某个窗口或用其他窗口遮盖一个窗口并再次显示该窗口的一部分时,就会触发该事件.要以编程方式触发,您需要使无效化渲染图形的窗口.

最简单的方法是Windows API InvalidateRect,请参见 http://msdn.microsoft.com/en-us/library/dd145002(v=vs.85).aspx [ http://msdn.microsoft. com/en-us/library/dd145195(v = vs.85).aspx [ http://msdn.microsoft. com/en-us/library/ax04k970(v = VS.100).aspx [
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[^].


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


这篇关于为什么仅在最小化Window之后才显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆