LRESULT QFrame::OnHtmlNotify( UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch(((NMHDR*)lParam)->code) { case HLN_DOCUMENT_COMPLETE: { if ( !_HasFlag(GetStyle(),WS_CHILD) ) { WTL::CRect r; GetWindowRect(&r); // 非子窗口,调整窗体为合适大小 int nWidth = max(HTMLayoutGetMinWidth(m_hWnd), (UINT)r.Width()); WTL::CRect rcNew; rcNew.SetRect(r.left, r.top, nWidth + r.left, r.top + max((UINT)r.Height(), HTMLayoutGetMinHeight(m_hWnd,nWidth))); AdjustWindowRectEx( &rcNew, GetStyle(), FALSE, GetExStyle()); // 调整大小,位置不变 SetWindowPos(NULL, 0, 0, rcNew.Width(), rcNew.Height(), SWP_NOZORDER | SWP_NOMOVE); size_min_ = rcNew.Size(); // 设置title ctl_title_ = GetCtrl("#wc-title"); if (ctl_title_.is_valid()) { SetWindowText(ctl_title_.GetText()); } } break; } } return QView::OnHtmlNotify(uMsg, wParam, lParam); }
HBRUSH AtlGetBackgroundBrush(HWND hWnd, HWND hwndParent) { ATL::CWindow wnd = hWnd; ATL::CWindow wndParent = hwndParent; WTL::CClientDC dcParent = wndParent; WTL::CRect rcParent; wndParent.GetWindowRect(&rcParent); WTL::CDC dcCompat1; dcCompat1.CreateCompatibleDC(dcParent); WTL::CBitmap bmpCompat1; bmpCompat1.CreateCompatibleBitmap(dcParent, rcParent.Width(), rcParent.Height()); HBITMAP hOldBmp1 = dcCompat1.SelectBitmap(bmpCompat1); wndParent.SendMessage(WM_ERASEBKGND, (WPARAM) (HDC) dcCompat1, 0); wndParent.SendMessage(WM_PRINTCLIENT, (WPARAM) (HDC) dcCompat1, (LPARAM)(PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT)); WTL::CRect rcWin; wnd.GetWindowRect(&rcWin); WTL::CDC dcCompat2; dcCompat2.CreateCompatibleDC(); WTL::CBitmap bmpCompat2; bmpCompat2.CreateCompatibleBitmap(dcCompat1, rcWin.Width(), rcWin.Height()); HBITMAP hOldBmp2 = dcCompat2.SelectBitmap(bmpCompat2); WTL::CRect rcSnap = rcWin; ::MapWindowPoints(NULL, wndParent, (LPPOINT) (LPRECT) &rcSnap, 2); dcCompat2.BitBlt(0, 0, rcWin.Width(), rcWin.Height(), dcCompat1, rcSnap.left, rcSnap.top, SRCCOPY); HBRUSH hBrush = ::CreatePatternBrush(bmpCompat2); dcCompat1.SelectBitmap(hOldBmp1); dcCompat2.SelectBitmap(hOldBmp2); return hBrush; }
int CListImpl::PreserveItemDivideRect(WTL::CRect rc, int index, BOOL bdivide) { WTL::CRect maintextrc = rc; WTL::CRect mainhittest = rc; WTL::CRect secondtextrc = rc; WTL::CRect secondhittest = rc; StyleParam* mainstyle = m_fontparams.GetFontParam(index); StyleParam* seconstyle = m_fontparams.GetFontParam(index, FALSE); int mainheight = mainstyle->fontsize + mainstyle->strokesize + mainstyle->shadowsize; int secondheight = seconstyle->fontsize + seconstyle->strokesize + seconstyle->shadowsize; if (!bdivide) secondheight = 0; maintextrc.top = rc.top + (rc.Height() - mainheight - secondheight) / 2; maintextrc.bottom = rc.top + (rc.Height() - mainheight - secondheight) / 2 + mainheight + 2; secondtextrc.top = maintextrc.bottom; secondtextrc.bottom = secondtextrc.top + secondheight; mainhittest.bottom = maintextrc.bottom; secondhittest.top = secondtextrc.top; if (m_listtextrc.size() / 2 > index) { m_listtextrc[2 * index] = maintextrc; m_listtextrc[2 * index + 1] = secondtextrc; m_listhittestrc[2 * index] = mainhittest; m_listhittestrc[2 * index + 1] = secondhittest; } else { m_listtextrc.push_back(maintextrc); m_listtextrc.push_back(secondtextrc); m_listhittestrc.push_back(mainhittest); m_listhittestrc.push_back(secondhittest); } return (rc.Height() - mainheight - secondheight) / 2; }
LRESULT SwitcherSettingsDialog::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) { schema_list_.SubclassWindow(GetDlgItem(IDC_SCHEMA_LIST)); schema_list_.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT); schema_list_.AddColumn(L"方案名稱", 0); WTL::CRect rc; schema_list_.GetClientRect(&rc); schema_list_.SetColumnWidth(0, rc.Width() - 20); description_.Attach(GetDlgItem(IDC_SCHEMA_DESCRIPTION)); hotkeys_.Attach(GetDlgItem(IDC_HOTKEYS)); hotkeys_.EnableWindow(FALSE); get_schemata_.Attach(GetDlgItem(IDC_GET_SCHEMATA)); get_schemata_.EnableWindow(TRUE); Populate(); CenterWindow(); BringWindowToTop(); return TRUE; }
HRESULT FMPlayerDShow::SetVideoRect(const RECT &rcPos) { HRESULT hr = S_FALSE; WTL::CRect wr = rcPos; m_VideoRect = rcPos; if (m_VideoWnd) { WTL::CSize arxy = GetVideoSize(); WTL::CRect vr = WTL::CRect(0,0,0,0); WTL::CSize ws = wr.Size(); int w = ws.cx; int h = ws.cy; double m_ZoomX = 1; double m_ZoomY = 1; double m_PosX = 0.5; double m_PosY = 0.5; BOOL bFromInside = TRUE; if(bFromInside) { h = ws.cy; w = MulDiv(h, arxy.cx, arxy.cy); if(bFromInside && w > ws.cx) { w = ws.cx; h = MulDiv(w, arxy.cy, arxy.cx); } } WTL::CSize size((int)(m_ZoomX*w), (int)(m_ZoomY*h)); WTL::CPoint pos( (int)(m_PosX*(wr.Width()*3 - m_ZoomX*w) - wr.Width()), (int)(m_PosY*(wr.Height()*3 - m_ZoomY*h) - wr.Height())); vr = WTL::CRect(pos, size); wr |= WTL::CRect(0,0,0,0); vr |= WTL::CRect(0,0,0,0); { hr = m_pBV->SetDefaultSourcePosition(); hr = m_pBV->SetDestinationPosition(vr.left, vr.top, vr.Width(), vr.Height()); hr = m_VideoWnd->SetWindowPosition(wr.left, wr.top, wr.Width(), wr.Height()); } } return hr; }
void CListImpl::DrawItem(LPDRAWITEMSTRUCT lpdis) { StyleParam* spmain = NULL; StyleParam* spsecondary = NULL; spmain = m_fontparams.GetFontParam(lpdis->itemID, TRUE); spsecondary = m_fontparams.GetFontParam(lpdis->itemID, FALSE); int top = 0; if (spsecondary) top = PreserveItemDivideRect(lpdis->rcItem, lpdis->itemID, TRUE); else top = PreserveItemDivideRect(lpdis->rcItem, lpdis->itemID, FALSE); WTL::CDC dc; WTL::CBitmap bmp; dc.CreateCompatibleDC(lpdis->hDC); bmp.CreateCompatibleBitmap(lpdis->hDC, 2 * (lpdis->rcItem.right - lpdis->rcItem.left), 2 * (lpdis->rcItem.bottom - lpdis->rcItem.top)); HBITMAP oldbmp = dc.SelectBitmap(bmp); WTL::CRect rc(0, 0, 2 * (lpdis->rcItem.right - lpdis->rcItem.left), 2 * (lpdis->rcItem.bottom - lpdis->rcItem.top)); dc.FillRect(&rc, COLOR_3DFACE); if (lpdis->itemState & ODS_SELECTED) { PaintListItemBackground(dc, rc.Width(), rc.Height()); if (m_highlightstat != 0) { WTL::CRect itemrc; WTL::CRect lightrc = rc; BOOL bmain = TRUE; itemrc = GetHittestDivideRect(2 * lpdis->itemID); lightrc.bottom = lightrc.top + 2 * itemrc.Height(); if (m_highlightstat == 2) { lightrc.top = lightrc.bottom; lightrc.bottom = rc.bottom; bmain = FALSE; } PaintHighLightListBckground(dc, lightrc, bmain); } } WTL::CRect mainrc = GetTextDivideRect( 2 * lpdis->itemID); int height = mainrc.Height(); mainrc.top = 2 * top; mainrc.bottom = mainrc.top + 2 * height; if (spmain) { m_subtitle.SetFont(*m_fontparams.GetFontParam(lpdis->itemID)); m_subtitle.SetSampleText(m_samplevec[0]); m_subtitle.Paint(dc, mainrc); } WTL::CRect seconrc = GetTextDivideRect(2 * lpdis->itemID + 1); int height2 = seconrc.Height(); seconrc.top = mainrc.bottom; seconrc.bottom = seconrc.top + 2 * height2; if (spsecondary) { m_subtitle.SetFont(*m_fontparams.GetFontParam(lpdis->itemID, FALSE)); m_subtitle.SetSampleText(m_samplevec[1]); m_subtitle.Paint(dc, seconrc); } SetStretchBltMode(lpdis->hDC, HALFTONE); SetBrushOrgEx(lpdis->hDC, 0, 0, NULL); StretchBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, lpdis->rcItem.right - lpdis->rcItem.left, lpdis->rcItem.bottom - lpdis->rcItem.top, dc, 0, 0, 2 * (lpdis->rcItem.right - lpdis->rcItem.left), 2 * (lpdis->rcItem.bottom - lpdis->rcItem.top), SRCCOPY); dc.SelectBitmap(oldbmp); }
BOOL QView::MakeTransparent(BOOL bTransparent/* = TRUE*/) { CBackHelper(this/*, CBackHelper::BACK_TRANS_RENDERPARENT*/); return TRUE; using namespace htmlayout; using namespace htmlayout::dom; // 非子窗口不可以使用透明效果 if ( ((GetStyle() & WS_CHILD) == 0) || (NULL == he_wrapper_) ) { ATLASSERT(FALSE); return FALSE; } ECtrl eThis = GetBody(); // html背景URI CStdString sBackImgURI; sBackImgURI.Format(L"%s_back_%p.png",quibase::GetModulePath(),GetSafeHwnd()); if ( !bTransparent ) { // 将背景图像删除掉 char ch = 0; return HTMLayoutDataReadyAsync(GetSafeHwnd(), L"file://" + sBackImgURI, (LPBYTE)&ch, 1, HLRT_DATA_IMAGE); } // else // { // // 写入透明标记 // eThis.set_attribute("transparent",L"true"); // } // 首先获取QView相对于Parent的位置 //!! <widget type="windowed" /> 不能使用padding属性 // 需要QView完全的覆盖到widget上面 ATLASSERT(element(he_wrapper_).get_style_attribute("padding") == NULL); WTL::CRect rcCont = element(he_wrapper_).get_location(ROOT_RELATIVE | PADDING_BOX); WTL::CRect rcClient = element(element(he_wrapper_).root()).get_location(); // 找到上层的实体窗口句柄 BOOL bRet = FALSE; image *pImgParent = image::create(rcCont.Width(), rcCont.Height()); image *pImgThis = NULL; do { // 先将父窗口整个区域的图像拷贝下来 if (NULL == (image::create(rcClient.Width(),rcClient.Height()))) break; if ( !HTMLayoutRender(GetParent().m_hWnd,pImgParent->handle(),rcCont) ) break; // 将本窗口与父亲窗口重叠区域的背景保存到图像中 if (NULL == (pImgThis = image::create(rcCont.Width(), rcCont.Height()))) break; graphics(pImgThis).blit_image(pImgParent,0,0, rcCont.left, rcCont.top, rcCont.right, rcCont.bottom); // 成功 bRet = TRUE; } while (false); // 将重叠区域图像数据写到内存缓冲区中 if ( bRet ) { struct write_to_thisback : public htmlayout::writer { QBuffer buf; virtual bool write( aux::bytes data ) { return buf.Write(data.start,data.length); } } wtt; // 参数0,指示写入格式为png格式 pImgThis->save(wtt, 0); // 使用透明效果 // 现在改写背景style和背景的图像地址,原来的自定义的背景数据将丢失 eThis.SetBkgndImage(sBackImgURI); eThis.SetBkgndRepeat(L"no-repeat"); eThis.SetBkgndPosition(0,0,0,0); // 将数据更新到指定的URI中 bRet = HTMLayoutDataReadyAsync(GetSafeHwnd(),L"file://" + sBackImgURI, wtt.buf.GetBuffer(0),wtt.buf.GetBufferLen(),HLRT_DATA_IMAGE); wtt.buf.FileWrite(L"F:/a.png"); eThis.SetBkgndImage(L"F:/a.png"); } // 释放资源 if (NULL != pImgThis) { delete pImgThis; } if (NULL != pImgParent) { delete pImgParent; } return bRet; }