/*! * This function modifies a window to enable resizing functionality. * This affects the window style, size, system menu and appearance. * * @param lpCreateStruct Pointer to a @c CREATESTRUCT structure, usually * passed by the system to the window procedure in a @c WM_CREATE * or @c WM_NCCREATE * * @remarks The function is intended to be called only inside a @c WM_CREATE * or @c WM_NCCREATE message handler. */ void CResizableLayout::MakeResizable(LPCREATESTRUCT lpCreateStruct) { if (lpCreateStruct->style & WS_CHILD) return; CWnd* pWnd = GetResizableWnd(); #if (_WIN32_WINNT >= 0x0501 && !defined(RSZLIB_NO_XP_DOUBLE_BUFFER)) // enable double-buffering on supported platforms pWnd->ModifyStyleEx(0, WS_EX_COMPOSITED); #endif if (!(lpCreateStruct->style & WS_THICKFRAME)) { // set resizable style pWnd->ModifyStyle(DS_MODALFRAME, WS_THICKFRAME); // keep client area CRect rect(CPoint(lpCreateStruct->x, lpCreateStruct->y), CSize(lpCreateStruct->cx, lpCreateStruct->cy)); pWnd->SendMessage(WM_NCCALCSIZE, FALSE, (LPARAM)&rect); // adjust size to reflect new style ::AdjustWindowRectEx(&rect, pWnd->GetStyle(), ::IsMenu(pWnd->GetMenu()->GetSafeHmenu()), pWnd->GetExStyle()); pWnd->SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREPOSITION); // update dimensions lpCreateStruct->cx = rect.Width(); lpCreateStruct->cy = rect.Height(); } }
// Author & Date: Almut Branner 12 May 2003 // Purpose: Replace this static control with this window // Inputs: // rcParentWindow - the window this is going to be placed into // rcNewWindow - the window that is to be created // nControlID - the ID of the control (from the resource editor) void ReplaceWindowControl(const CWnd &rcParentWindow, CWnd &rcNewWindow, int nControlID) { CWnd *pStatic = rcParentWindow.GetDlgItem(nControlID); // For debug mode ASSERT(pStatic != 0); // For released code if (pStatic == 0) return; CRect rctWindowSize; DWORD frmstyle = pStatic->GetStyle(); DWORD frmexstyle = pStatic->GetExStyle(); pStatic->GetWindowRect(rctWindowSize); // Get window coord. rcParentWindow.ScreenToClient(rctWindowSize); // change to client coord. pStatic->DestroyWindow(); CWnd *pParent = const_cast<CWnd *>(&rcParentWindow); rcNewWindow.CreateEx(frmexstyle, NULL, NULL, frmstyle, rctWindowSize, pParent, nControlID); // Use for debugging // AllocConsole(); }
/*! * This function enables or restores clipping on the specified DC when * appropriate. It should be called whenever drawing on the window client * area to avoid flickering. * * @param pDC Pointer to the target device context * @param bUndo Flag that specifies wether to restore the clipping region * * @return The return value is @c TRUE if the clipping region has been * modified, @c FALSE if clipping was not necessary. * * @remarks For anti-flickering to work, you should wrap your * @c WM_ERASEBKGND message handler inside a pair of calls to * this function, with the last parameter set to @c TRUE first * and to @c FALSE at the end. */ BOOL CResizableLayout::ClipChildren(CDC* pDC, BOOL bUndo) { #if (_WIN32_WINNT >= 0x0501 && !defined(RSZLIB_NO_XP_DOUBLE_BUFFER)) // clipping not necessary when double-buffering enabled if (real_WIN32_WINNT >= 0x0501) { CWnd *pWnd = GetRootParentWnd(GetResizableWnd()); if (pWnd == NULL) pWnd = GetResizableWnd(); if (pWnd->GetExStyle() & WS_EX_COMPOSITED) return FALSE; } #endif HDC hDC = pDC->GetSafeHdc(); HWND hWnd = GetResizableWnd()->GetSafeHwnd(); m_nOldClipRgn = -1; // invalid region by default // Some controls (such as transparent toolbars and standard controls // with XP theme enabled) send a WM_ERASEBKGND msg to the parent // to draw themselves, in which case we must not enable clipping. // We check that the window associated with the DC is the // resizable window and not a child control. if (!bUndo && (hWnd == ::WindowFromDC(hDC))) { // save old DC clipping region m_nOldClipRgn = ::GetClipRgn(hDC, m_hOldClipRgn); // clip out supported child windows CRgn rgnClip; GetClippingRegion(&rgnClip); ::ExtSelectClipRgn(hDC, rgnClip, RGN_AND); return TRUE; } // restore old clipping region, only if modified and valid if (bUndo && m_nOldClipRgn >= 0) { if (m_nOldClipRgn == 1) ::SelectClipRgn(hDC, m_hOldClipRgn); else ::SelectClipRgn(hDC, NULL); return TRUE; } return FALSE; }
void CResizableLayout::GetClippingRegion(CRgn* pRegion) { CWnd* pWnd = GetResizableWnd(); // System's default clipping area is screen's size, // not enough for max track size, for example: // if screen is 1024 x 768 and resizing border is 4 pixels, // maximized size is 1024+4*2=1032 x 768+4*2=776, // but max track size is 4 pixels bigger 1036 x 780 (don't ask me why!) // So, if you resize the window to maximum size, the last 4 pixels // are clipped out by the default clipping region, that gets created // as soon as you call clipping functions (my guess). // reset clipping region to the whole client area CRect rect; pWnd->GetClientRect(&rect); pRegion->CreateRectRgnIndirect(&rect); // clip only anchored controls LayoutInfo layout; POSITION pos = m_listLayout.GetHeadPosition(); while (pos != NULL) { // get layout info layout = m_listLayout.GetNext(pos); if (::IsWindowVisible(layout.hWnd)) ClipChildWindow(layout, pRegion); } pos = m_listLayoutCB.GetHeadPosition(); while (pos != NULL) { // get layout info layout = m_listLayoutCB.GetNext(pos); // request data if (!ArrangeLayoutCallback(layout)) continue; if (::IsWindowVisible(layout.hWnd)) ClipChildWindow(layout, pRegion); } // fix for RTL layouts (1 pixel of horz offset) if (pWnd->GetExStyle() & 0x00400000L/*WS_EX_LAYOUTRTL*/) pRegion->OffsetRgn(-1,0); }
// **************************************************************************** // // Function Name: SubclassControl( ) // // Description: Subclass control obtains the default style information // from the control to subclass, and uses this to create // a similar control based on CWnd, instead of the type // of control in the dialog template. // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // BOOLEAN SubclassControl( CWnd* pParent, UINT nControlID, CWnd& ctlChild ) { // Get the control we're stealing... CWnd* pCtl = pParent->GetDlgItem( nControlID ); CRect rcCtl; CString strText ; // // Determine all the information of the control we're // stealing, so we can use it in the creation of the new control. // DWORD dwStyle = pCtl->GetStyle() ; // Style DWORD dwExStyle = pCtl->GetExStyle() ; // Extended pCtl->GetWindowText( strText ) ; // Window Text pCtl->GetWindowRect( rcCtl ) ; // Screen Position pParent->ScreenToClient( rcCtl ) ; BOOLEAN fResult = FALSE ; // // Create the new control with all the settings // of the control we are replacing. // if (ctlChild.CreateEx( dwExStyle, NULL, strText, dwStyle, rcCtl.left, rcCtl.top, rcCtl.Width(), rcCtl.Height(), pParent->m_hWnd, (HMENU) nControlID ) ) { // Set the z order of the control ctlChild.SetWindowPos( pCtl, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ) ; } // // Okay, we have everything we need so destroy // the control that we are replacing. // pCtl->DestroyWindow(); return fResult ; }
//************************************************************************** void CBCGPRibbonComboBox::DropDownList () { ASSERT_VALID (this); if (IsDisabled ()) { return; } if (m_pWndEdit->GetSafeHwnd () != NULL && !m_pWndEdit->IsWindowVisible ()) { return; } if (CBCGPPopupMenu::GetActiveMenu () != NULL) { if (CBCGPPopupMenu::GetActiveMenu ()->GetMenuBar () != m_pParentMenu) { CBCGPPopupMenu::GetActiveMenu ()->SendMessage (WM_CLOSE); return; } } CBCGPBaseRibbonElement::OnShowPopupMenu (); if (m_bIsCalculator) { if (m_pCalcPopup != NULL) { m_pCalcPopup->SendMessage (WM_CLOSE); m_pCalcPopup = NULL; SetDroppedDown(NULL); } else { if (CBCGPPopupMenu::GetActiveMenu () != NULL) { if (CBCGPPopupMenu::GetActiveMenu ()->GetMenuBar () != m_pParentMenu) { CBCGPPopupMenu::GetActiveMenu ()->SendMessage (WM_CLOSE); return; } } CBCGPBaseRibbonElement::OnShowPopupMenu (); double dblValue = 0.; CString strValue = GetEditText (); if (!strValue.IsEmpty ()) { strValue.Replace (_T(','), _T('.')); #if _MSC_VER < 1400 _stscanf (strValue, _T("%lf"), &dblValue); #else _stscanf_s (strValue, _T("%lf"), &dblValue); #endif } m_pCalcPopup = new CBCGPCalculatorPopup (dblValue, 0, this); m_pCalcPopup->m_bAutoDestroyParent = FALSE; m_pCalcPopup->SetParentRibbonElement (this); CBCGPCalculator* pCalc = DYNAMIC_DOWNCAST (CBCGPCalculator, m_pCalcPopup->GetMenuBar()); if (pCalc != NULL) { ASSERT_VALID (pCalc); if (!m_lstCalcAdditionalCommands.IsEmpty ()) { pCalc->SetAdditionalCommands (m_lstCalcAdditionalCommands); } if (!m_lstCalcExtCommands.IsEmpty ()) { pCalc->SetExtendedCommands (m_lstCalcExtCommands); } if (!m_strCalcDisplayFormat.IsEmpty()) { pCalc->SetDisplayFormat(m_strCalcDisplayFormat); } } CRect rectWindow; m_pWndEdit->GetWindowRect (rectWindow); if (!m_pCalcPopup->Create (m_pWndEdit, rectWindow.left - m_szMargin.cx, rectWindow.bottom + m_szMargin.cy, NULL, TRUE)) { ASSERT (FALSE); m_pCalcPopup = NULL; } else { SetDroppedDown(m_pCalcPopup); m_pCalcPopup->GetMenuBar()->SetFocus (); CRect rect; m_pCalcPopup->GetWindowRect (&rect); m_pCalcPopup->UpdateShadow (&rect); } } return; } CBCGPDropDownList* pList = new CBCGPDropDownList (this); pList->SetParentRibbonElement (this); int i = 0; for (POSITION pos = m_lstItems.GetHeadPosition (); pos != NULL; i++) { CString strItem = m_lstItems.GetNext (pos); pList->AddString (strItem); if (m_bHasEditBox && strItem == m_strEdit) { m_iSelIndex = i; } } pList->SetCurSel (m_iSelIndex); pList->SetMaxHeight (m_nDropDownHeight); pList->SetMinWidth (m_rect.Width ()); CWnd* pWndParent = GetParentWnd (); if (pWndParent == NULL) { ASSERT (FALSE); return; } const BOOL bIsRTL = (pWndParent->GetExStyle () & WS_EX_LAYOUTRTL); CRect rect = m_rectCommand.IsRectEmpty () ? m_rect : m_rectCommand; pWndParent->ClientToScreen (&rect); SetDroppedDown (pList); if (m_pParent != NULL) { ASSERT_VALID (m_pParent); m_pParent->HighlightPanel (NULL, CPoint (-1, -1)); } if (m_pWndEdit->GetSafeHwnd () != NULL) { m_pWndEdit->SetFocus (); m_pWndEdit->SetSel (0, -1); } if (m_bResizeDropDownList) { pList->EnableVertResize (2 * globalData.GetTextHeight ()); } pList->Track (CPoint ( bIsRTL ? rect.right : rect.left, rect.bottom), pWndParent->GetOwner ()); }
void CXTPPropertyGridInplaceList::Create(CXTPPropertyGridItem* pItem, CRect rect) { ASSERT(pItem && pItem->GetGrid()); if (!pItem) return; CRect rcValue(rect); rcValue.left = pItem->GetGrid()->GetDividerPos() + 1; CWnd* pParent = (CWnd*)pItem->GetGrid(); m_pItem = pItem; DestroyWindow(); if (!m_hWnd) { CListBox::CreateEx(WS_EX_TOOLWINDOW | (pParent->GetExStyle() & WS_EX_LAYOUTRTL), _T("LISTBOX"), _T(""), LBS_NOTIFY | WS_CHILD | WS_VSCROLL | WS_BORDER | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS, CRect(0, 0, 0, 0), pParent, 0); SetOwner(pParent); if (m_bShowShadow && XTPSystemVersion()->IsWinXPOrGreater()) SetClassLongPtr(m_hWnd, GCL_STYLE, GetClassLongPtr(m_hWnd, GCL_STYLE) | 0x00020000); } SetFont(pParent->GetFont()); ResetContent(); CXTPPropertyGridItemConstraints* pList = pItem->GetConstraints(); int dx = rect.right - rcValue.left; CWindowDC dc(pParent); CXTPFontDC font(&dc, pParent->GetFont()); int nHeight = dc.GetTextExtent(_T(" "), 1).cy + 3; for (int i = 0; i < pList->GetCount(); i++) { CXTPPropertyGridItemConstraint* pConstraint = pList->GetConstraintAt(i); CString str = pConstraint->m_strConstraint; int nIndex = AddString(str); SetItemDataPtr(nIndex, pConstraint); CSize sz = pItem->OnMergeItemConstraint(&dc, pConstraint); dx = max(dx, sz.cx); nHeight = max(nHeight, sz.cy); if (pItem->GetValue() == str) SetCurSel(nIndex); } SetItemHeight(0, nHeight); rect.top = rect.bottom; rect.bottom += nHeight * __min(pItem->GetDropDownItemCount(), GetCount()) + 2; rect.left = rect.right - __min(dx, rect.Width() - XTP_PGI_EXPAND_BORDER); pParent->ClientToScreen(&rect); CRect rcWork = XTPMultiMonitor()->GetWorkArea(rect); if (rect.bottom > rcWork.bottom && rect.top > rcWork.CenterPoint().y) { rect.OffsetRect(0, - rect.Height() - rcValue.Height() - 1); } if (rect.left < rcWork.left) rect.OffsetRect(rcWork.left - rect.left, 0); if (rect.right > rcWork.right) rect.OffsetRect(rcWork.right - rect.right, 0); SetFocus(); SetWindowLongPtr(m_hWnd, GWLP_HWNDPARENT, 0); ModifyStyle(WS_CHILD, WS_POPUP); SetWindowLongPtr(m_hWnd, GWLP_HWNDPARENT, (LONG_PTR)pParent->m_hWnd); SetWindowPos(&CWnd::wndTopMost, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOOWNERZORDER); CXTPMouseMonitor::SetupHook(this); }
LRESULT CControlBar::OnSizeParent(WPARAM, LPARAM lParam) { AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam; DWORD dwStyle = RecalcDelayShow(lpLayout); if ((dwStyle & WS_VISIBLE) && (dwStyle & CBRS_ALIGN_ANY) != 0) { // align the control bar CRect rect; rect.CopyRect(&lpLayout->rect); CSize sizeAvail = rect.Size(); // maximum size available // get maximum requested size CSize size = CalcFixedLayout(lpLayout->bStretch, dwStyle & CBRS_ORIENT_HORZ); size.cx = min(size.cx, sizeAvail.cx); size.cy = min(size.cy, sizeAvail.cy); if (dwStyle & CBRS_ORIENT_HORZ) { lpLayout->sizeTotal.cy += size.cy; lpLayout->sizeTotal.cx = max(lpLayout->sizeTotal.cx, size.cx); if (dwStyle & CBRS_ALIGN_TOP) lpLayout->rect.top += size.cy; else if (dwStyle & CBRS_ALIGN_BOTTOM) { rect.top = rect.bottom - size.cy; lpLayout->rect.bottom -= size.cy; } } else if (dwStyle & CBRS_ORIENT_VERT) { lpLayout->sizeTotal.cx += size.cx; lpLayout->sizeTotal.cy = max(lpLayout->sizeTotal.cy, size.cy); if (dwStyle & CBRS_ALIGN_LEFT) lpLayout->rect.left += size.cx; else if (dwStyle & CBRS_ALIGN_RIGHT) { rect.left = rect.right - size.cx; lpLayout->rect.right -= size.cx; } } else { ASSERT(FALSE); // can never happen } rect.right = rect.left + size.cx; rect.bottom = rect.top + size.cy; #ifdef _MAC // account for the Macintosh grow box, if there is one CWnd* pWnd = GetParentFrame(); if (pWnd != NULL) { DWORD dwWndStyle = pWnd->GetStyle(); DWORD dwExStyle = pWnd->GetExStyle(); if (!(dwExStyle & WS_EX_MDIFRAME) && (dwExStyle & WS_EX_FORCESIZEBOX) && !(dwWndStyle & (WS_VSCROLL|WS_HSCROLL))) { CRect rectParent; pWnd->GetClientRect(rectParent); if (dwStyle & CBRS_ALIGN_BOTTOM) { if (rect.bottom > rectParent.bottom - afxData.cxVScroll + 1) rect.right -= (afxData.cxVScroll - 1); } else if (dwStyle & CBRS_ALIGN_RIGHT) { if (rect.bottom > rectParent.bottom - afxData.cyHScroll + 1) rect.bottom -= (afxData.cxVScroll - 1); } } } #endif // only resize the window if doing layout and not just rect query if (lpLayout->hDWP != NULL) AfxRepositionWindow(lpLayout, m_hWnd, &rect); } return 0; }
void CTimeSliceView::OnDraw( CDC* pDC ) { CTimeSliceDoc* pDoc = GetDocument(); ASSERT_VALID( pDoc ); CTimeSliceDoc::CameraInfo& camera = pDoc->m_arCameraInfo[ m_iCamera ]; // // Resize the window for the current bitmap size - this takes into account // the vertical tweak. // CRect vsize( 0, 0, camera.m_pbitmapinfo32->bmiHeader.biWidth, -camera.m_pbitmapinfo32->bmiHeader.biHeight ); CWnd* pframe = GetParentFrame(); ::AdjustWindowRectEx( &vsize, GetStyle(), FALSE, GetExStyle() ); ::AdjustWindowRectEx( &vsize, pframe->GetStyle(), FALSE, pframe->GetExStyle() ); pframe->SetWindowPos( NULL, 0, 0, vsize.Width(), vsize.Height(), SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER ); switch( m_viewType ) { case CTimeSliceDoc::SINGLE_CAMERA: drawImage( camera, camera.m_imageProcessed.pData, pDC ); drawAlignCross( pDoc, pDC ); break; case CTimeSliceDoc::PANNING: { char pszTitle[ 256 ]; sprintf( pszTitle, "Panning - %d", pDoc->m_cameraInfoTimeSlice.m_info.SerialNumber ); GetParentFrame()->SetWindowText( pszTitle ); drawImage( pDoc->m_cameraInfoTimeSlice, pDoc->m_cameraInfoTimeSlice.m_pTimesliceImageBuffer, pDC ); // // Update the frame rate in the status bar (do it here since // there's only one panning view. // CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; pFrame->updateFrameRate( pDoc->m_dFrameRate, pDoc->m_uiMissedImages, pDoc->m_uiOutOfSyncImages ); } break; default: ASSERT( FALSE ); } }