user261002
user261002

Reputation: 2252

how to change the position of the child window inside the parent window and show the toolbar?

I have the following code which passes a window handler form OpenCV window to win32 handler, therefore I can show the grabbed images from camera to the screen and the images will show as a child window of my main API. but the problem is that when I want to add a tooldbar to my program, the image window handler comes at the top of the toolbar. how can I sort this out?

//create a window and set the handler from openCV to win32 
cv::namedWindow("test",cv::WINDOW_AUTOSIZE);                        
hWnd2 = (HWND) cvGetWindowHandle("test"); 
hParent = ::GetParent(hWnd2);       
::SetParent(hWnd2, hWnd);                       
::ShowWindow(hParent, SW_HIDE); 
_liveCapturing=true;
lastPicNr = 0;  
SetWindowTextW(hStatus, L"Live Capturing ... ");
if(FullScreen()){
    ::ShowWindow(hWnd, SW_MAXIMIZE);
}

code for the toolbar :

HWND CreateToolbar(HWND hwnd){
    HWND hTbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | CCS_TOP  , 0, 0, 0, 0, hwnd, (HMENU)12, GetModuleHandle(NULL), NULL);
    SendMessage(hTbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);

    TBBUTTON tbb[3];
    TBADDBITMAP tbab;

    tbab.hInst = HINST_COMMCTRL;
    tbab.nID = IDB_STD_SMALL_COLOR; 
    SendMessage(hTbar, TB_ADDBITMAP, 0, (LPARAM)&tbab);
    return hTbar;
}

Screebshot of the window overlapping the toolbar

Upvotes: 1

Views: 3268

Answers (2)

SELLAM
SELLAM

Reputation: 71

Probably you have found the solution a long time ago, but i want to post my anwers in case other users need it.

You can simply add the OpenCV window with the same code you have to a child window in your window (which you set it position in advance). For example you can add it to a static text window (label) ...

Upvotes: 2

Deanna
Deanna

Reputation: 24253

If you want to move the OpenCV window, call SetWindowPos() with the desired coordinates.

SetWindowPos(hWnd2, 0, 0, 30, 0, 0, SWP_NOSIZE | SWP_NOZORDER);

Upvotes: 1

Related Questions