English 中文(简体)
儿童窗口问题
原标题:RedrawWindow() issue on child windows
  • 时间:2011-04-20 20:48:34
  •  标签:
  • winapi

在我的“双赢”申请中,我创建了一个人口窗口,我利用这个窗口展示其他窗口的内容。

For example, I have a Photoshop application running. I grab a handle to its main window and make its style a child window and set its parent as my own window. This places Photoshop in my application.

Afterwards, I hide the photoshop window (set opacity to 0), and instead grab its Device Context contents into a bitmap that I created, and I draw this bitmap on my window. To do this, I set up a timer that ticks every 16 milliseconds (60 hz). This is the timer:

void CALLBACK drawProc( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime )
{
    updateFrames();

    RECT r;
    GetClientRect( hwnd, &r );

    //Erase background
    HBRUSH eraseBrush = CreateSolidBrush( RGB( 255, 255, 255 ) );
    FillRect( bbHDC, &r, eraseBrush );
    DeleteObject( eraseBrush );

    //Draw frames
    drawFrames( bbHDC );    

    RedrawWindow( hwnd, 0, 0, RDW_INVALIDATE | RDW_NOCHILDREN );
}

问题在于,这种影像店缓慢(而其他一些申请也减少了)。 我通过发表评论,发现红树造成这种情况。 我认为,重塑主要窗户可能会造成光购物,使其内容更重,因此,我补充说,RDW_NOCHILDREN,但仍然是缓慢的。

如果有人能够帮助我,我会感到高兴。

感谢。

最佳回答

我甚至不想评论为什么这是一件令人难忘的事情:

Why it s slow:

RedrawWindow is probably forcing a full repaint every time you call it. After all, you are invalidating the entire window. That will be an expensive operation - normally in a Windows app, you only paint when you know you need to (by invalidating a rectangle or region, which is a very cheap operation, and at some point processing a WM_PAINT message, and when handling that painting only the invalidated area, which is the minimum work possible.)

It is worth reading up on painting and drawing in Windows, especially when to draw in a window.

Now, to try to give an answer your question:

Most of the time, your embedded Photoshop window will not have changed. In other words, the vast, vast majority of the painting work your program is doing is completely unnecessary. What you should do instead is only paint to your window when the Photoshop window has changed and needs to repaint itself - and ideally, even then, only repaint the section that needs to be repainted. (An example is a button reacting to a mouseover: you only need to repaint the button, or the rectangle inside which the button is located, not the entire window.)

What you re doing is a general case of polling. It s very inefficient since you do a lot of work even when none needs to be done. You want instead to be notified when you need to do work, which is much more efficient.

The following is a suggestion, I haven t tried it but it should work. Windows already has a built-in framework so an application knows when it needs to paint: a WM_PAINT message will be present in its message queue. You can peek into a window s message queue and see what messages are there, without removing any, using PeekMessage. That will tell you when the window needs to be painted: repaint then. Alternatively, hook the message function or subclass the window and when a WM_PAINT message is received pass it to the original message function, and then repaint. You could use GetUpdateRect to see what area will be painted, and then after the WM_PAINT processing is complete, copy that area only to your own window. Etc.

This is a general answer: try some of those things and see what happens. Remember, if you have problems with particular parts, you can post another question!

问题回答

暂无回答




相关问题
How to read exact number of bytes from a stream (tcp) socket?

In winsock, both the sync recv and the async WSARecv complete as soon as there is data available in a stream socket, regardless of the size specified (which is only the upper limit). This means that ...

AcquireCredentialsHandle returns SEC_E_NO_CREDENTIALS

I created a self-signed certificate (created using OpenSSL) and installed it into the Certificate Store using the Certificates MMC snap-in (CertMgr.msc) on Windows Vista Ultimate. I have managed to ...

Calling Win32 EnumThreadWindows() in C#

I m trying to get a call to EnumThreadWindows working, but I always get a Wrong Parameter-Error, although my code is nearly the same as this example on pinvoke.net. I don t know why this doesn t work: ...

COM Basic links

folks can you provide me the tutorial link or .pdf for learning basic COM?. i do google it.. still i recommend answers of stackoverflow so please pass me.. Thanks

Handling multiple windows WIN32 API

HI I m trying to create an application in the Win32 environment containing more than one window. How do i do that? all the Win32 Tutorials on web i found only showed how to manage one window. How do i ...

Creating a thread in DllMain?

It seems that when a thread is created from within DllMain upon DLL_PROCESS_ATTACH it won t begin until all dll s have been loaded. Since I need to make sure the thread runs before I continue, I get a ...

热门标签