C ++ Win32:将子窗口附加到主窗口

时间:2012-04-04 16:12:55

标签: c++ window mdi

我正在开发基于C ++的程序,并且还使用SiliconSoftware接口。 正如您从连接的活塞中看到的那样,我正在运行带有c ++ win32代码的主窗口,但显示窗口是使用带有以下代码的帧抓取器接口创建的:

int Bits=8; int nId =::CreateDisplay(Bits,GrabberOptions::getWidth(),GrabberOptions::getHeight());SetBufferWidth(nId,GrabberOptions::getWidth(),GrabberOptions::getHeight());::DrawBuffer(nId,Fg_getImagePtrEx(fg,lastPicNr,0,_memoryAllc),lastPicNr,"");

但我想要这个Diplay窗口,在主窗口中打开。 我该怎么做 ?任何的想法? enter image description here

1 个答案:

答案 0 :(得分:5)

假设你有

HWND a = ...
HWND b = ...
无论如何,他们都是兄弟窗口的原生句柄。 要使b成为a的孩子,你必须做

Setparent(b,a); //a will be the new parent b
DWORD style = GetWindowLong(b,GWL_STYLE); //get the b style
style &= ~(WS_POPUP|WS_CAPTION); //reset the "caption" and "popup" bits
style |= WS_CHILD; //set the "child" bit
SetWindowLong(b,GWL_STYLE,style); //set the new style of b
RECT rc; //temporary rectangle
GetClientRect(a,&rc); //the "inside border" rectangle for a
MoveWindow(b,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top); //place b at (x,y,w,h) in a
UpdateWindow(a);

现在你必须从a处理WM_SIZE并相应地移动b,以便它与其(新)父级一起调整大小。

相关问题