UICombo.cpp ( 文件浏览 )
- keepall 发布于 2016-08-23 13:24
- 浏览次数:410
- 下载次数: 1
- 下载需 20 积分
-
- 侵权举报
#include "StdAfx.h" namespace DuiLib { ///////////////////////////////////////////////////////////////////////////////////// // // class CComboWnd : public CWindowWnd { public: void Init(CComboUI* pOwner); LPCTSTR GetWindowClassName() const; void OnFinalMessage(HWND hWnd); LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam); void EnsureVisible(int iIndex); void Scroll(int dx, int dy); public: CPaintManagerUI m_pm; CComboUI* m_pOwner; CVerticalLayoutUI* m_pLayout; int m_iOldSel; }; void CComboWnd::Init(CComboUI* pOwner) { m_pOwner = pOwner; m_pLayout = NULL; m_iOldSel = m_pOwner->GetCurSel(); // Position the popup window in absolute space SIZE szDrop = m_pOwner->GetDropBoxSize(); RECT rcOwner = pOwner->GetPos(); RECT rc = rcOwner; rc.top = rc.bottom; rc.bottom = rc.top + szDrop.cy; if( szDrop.cx > 0 ) rc.right = rc.left + szDrop.cx; SIZE szAvailable = { rc.right - rc.left, rc.bottom - rc.top }; int cyFixed = 0; for( int it = 0; it < pOwner->GetCount(); it++ ) { CControlUI* pControl = static_cast<CControlUI*>(pOwner->GetItemAt(it)); if( !pControl->IsVisible() ) continue; SIZE sz = pControl->EstimateSize(szAvailable); cyFixed += sz.cy; } cyFixed += 4; // CVerticalLayoutUI 默认的Inset 调整 rc.bottom = rc.top + MIN(cyFixed, szDrop.cy); ::MapWindowRect(pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc); MONITORINFO oMonitor = {}; oMonitor.cbSize = sizeof(oMonitor); ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); CRect rcWork = oMonitor.rcWork; if( rc.bottom > rcWork.bottom ) { rc.left = rcOwner.left; rc.right = rcOwner.right; if( szDrop.cx > 0 ) rc.right = rc.left + szDrop.cx; rc.top = rcOwner.top - MIN(cyFixed, szDrop.cy); rc.bottom = rcOwner.top; ::MapWindowRect(pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc); } Create(pOwner->GetManager()->GetPaintWindow(), NULL, WS_POPUP, WS_EX_TOOLWINDOW, rc); // HACK: Don't deselect the parent's caption HWND hWndParent = m_hWnd; while( ::GetParent(hWndParent) != NULL ) hWndParent = ::GetParent(hWndParent); ::ShowWindow(m_hWnd, SW_SHOW); ::SendMessage(hWndParent, WM_NCACTIVATE, TRUE, 0L); } LPCTSTR CComboWnd::GetWindowClassName() const { return _T("ComboWnd"); } void CComboWnd::OnFinalMessage(HWND hWnd) { m_pOwner->m_pWindow = NULL; m_pOwner->m_uButtonState &= ~ UISTATE_PUSHED; m_pOwner->Invalidate(); delete this; } LRESULT CComboWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) { if( uMsg == WM_CREATE ) { m_pm.Init(m_hWnd); // The trick is to add the items to the new container. Their owner gets // reassigned by this operation - which is why it is im[!==More==!]
...
展开> <收缩
Sponsored links
源码文件列表
温馨提示: 点击源码文件名可预览文件内容哦 ^_^ Sponsored links