2012-04-04 57 views
2

我正在開發基於C++的程序並使用SiliconSoftware界面。 當你從我的計算機運行與C++的Win32代碼的主窗口中的附加pisture看,但與圖像採集inteface創建的顯示窗口下面的代碼: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

這不是原生的Win32。您實際上使用了一些C++包裝器,以便更好地指定 – 2012-04-04 16:23:13

+0

我使用Visual Stadio創建了我的項目,但我沒有使用「Empty Project」選項,所以主窗口由Visual Studio創建,我認爲這是代碼窗口:BOOL InitInstance(HINSTANCE hInstance,int nCmdShow) HWND hWnd; hInst = hInstance; //將實例句柄存儲在我們的全局變量中 hWnd = CreateWindow(szWindowClass,szTitle,WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL); if(!hWnd) { return FALSE; } ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); return TRUE; } – user261002 2012-04-04 16:26:27

+0

在創建窗口後無法「附加」窗口。如果圖像採集卡API沒有給你選擇,那麼你運氣不好。 – 2012-04-04 16:31:36

回答

4

比方說,你有

HWND a = ... 
HWND b = ... 

assumig他們兄弟獲得無論多麼窗口的本地手柄。 爲了使B的孩子,你必須做

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

Nowm你必須從處理WM_SIZE並相應地移動B,所以它與它的(新)母公司一起調整。