CControlUI* CMainFrame::CreateControl( LPCTSTR pstrClass ) { if (_tcsicmp(pstrClass, _T("FriendList")) == 0) { return new CFriendsUI(m_PaintManager); } else if (_tcsicmp(pstrClass, _T("GroupList")) == 0) { return new CGroupsUI(m_PaintManager); } else if (_tcsicmp(pstrClass, _T("MicroBlog")) == 0) { return new CMicroBlogUI(m_PaintManager); } if (_tcsicmp(pstrClass, _T("Wnd")) == 0) { CWndUI *pUI = new CWndUI; HWND hWnd = CreateWindow(_T("BUTTON"), _T("win32"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 0, 0, 0, 0, m_PaintManager.GetPaintWindow(), NULL, NULL, NULL); pUI->Attach(hWnd); //// 上面用的是win32的按钮,下面这段用MFC的按钮 //CButton *pBtn = new CButton; // 记得释放内存 //pBtn->Create(_T("MFC"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, CRect(0, 0, 0, 0), CWnd::FromHandle(m_PaintManager.GetPaintWindow()), 0); //pUI->Attach(*pBtn); return pUI; } return NULL; }
CControlUI* CDuiFrameWnd::CreateControl( LPCTSTR pstrClassName ) { CDuiString strXML; CDialogBuilder builder; if (_tcsicmp(pstrClassName, _T("Caption")) == 0) { strXML = _T("Caption.xml"); } else if (_tcsicmp(pstrClassName, _T("PlayPanel")) == 0) { strXML = _T("PlayPanel.xml"); } else if (_tcsicmp(pstrClassName, _T("Playlist")) == 0) { strXML = _T("Playlist.xml"); } else if (_tcsicmp(pstrClassName, _T("WndMediaDisplay")) == 0) { CWndUI *pUI = new CWndUI; HWND hWnd = CreateWindow(_T("#32770"), _T("WndMediaDisplay"), WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, m_PaintManager.GetPaintWindow(), (HMENU)0, NULL, NULL); pUI->Attach(hWnd); return pUI; } if (! strXML.IsEmpty()) { CControlUI* pUI = builder.Create(strXML.GetData(), NULL, NULL, &m_PaintManager, NULL); // 这里必须传入m_PaintManager,不然子XML不能使用默认滚动条等信息。 return pUI; } return NULL; }
CControlUI* CFrameWnd::CreateControl( LPCTSTR pstrClassName ) { if (_tcsicmp(pstrClassName, _T("Wnd")) == 0) { CWndUI *pUI = new CWndUI; HWND hWnd = CreateWindow(_T("BUTTON"), _T("win32"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 0, 0, 0, 0, m_PaintManager.GetPaintWindow(), NULL, NULL, NULL); pUI->Attach(hWnd); //// 上面用的是win32的按钮,下面这段用MFC的按钮 //CButton *pBtn = new CButton; // 记得释放内存 //pBtn->Create(_T("MFC"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, CRect(0, 0, 0, 0), CWnd::FromHandle(m_PaintManager.GetPaintWindow()), 0); //pUI->Attach(*pBtn); return pUI; } return NULL; }
void CDuiFrameWnd::InitWindow() { SetIcon(IDI_ICON1); // 根据分辨率自动调节窗口大小 MONITORINFO oMonitor = {}; oMonitor.cbSize = sizeof(oMonitor); ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTONEAREST), &oMonitor); AdaptWindowSize(oMonitor.rcMonitor.right - oMonitor.rcMonitor.left); ::GetWindowPlacement(*this, &m_OldWndPlacement); // 初始化CActiveXUI控件 std::vector<CDuiString> vctName; CActiveXUI* pActiveXUI; vctName.push_back(_T("ActiveXLib")); vctName.push_back(_T("ActiveXFind")); vctName.push_back(_T("ActiveXMine")); vctName.push_back(_T("ActiveXCloud")); for (UINT i = 0; i < vctName.size(); i++) { pActiveXUI = static_cast<CActiveXUI*>(m_PaintManager.FindControl(vctName[i])); if(pActiveXUI) { pActiveXUI->SetDelayCreate(false); pActiveXUI->CreateControl(CLSID_WebBrowser); } } // 几个常用控件做为成员变量 CSliderUI* pSilderVol = static_cast<CSliderUI*>(m_PaintManager.FindControl(_T("sliderVol"))); m_pSliderPlay = static_cast<CSliderUI*>(m_PaintManager.FindControl(_T("sliderPlay"))); m_pLabelTime = static_cast<CLabelUI*>(m_PaintManager.FindControl(_T("labelPlayTime"))); if (! pSilderVol || ! m_pSliderPlay || ! m_pLabelTime) { return; } pSilderVol->OnNotify += MakeDelegate(this, &CDuiFrameWnd::OnVolumeChanged); m_pSliderPlay->OnNotify += MakeDelegate(this, &CDuiFrameWnd::OnPosChanged); // 设置播放器的窗口句柄和回调函数 CWndUI *pWnd = static_cast<CWndUI*>(m_PaintManager.FindControl(_T("wndMedia"))); if (pWnd) { m_cAVPlayer.SetHWND(pWnd->GetHWND()); m_cAVPlayer.SetCallbackPlaying(CallbackPlaying); m_cAVPlayer.SetCallbackPosChanged(CallbackPosChanged); m_cAVPlayer.SetCallbackEndReached(CallbackEndReached); } // 加载m3u播放列表 AddFiles(m_cPlayList.GetPlaylist(), true); // 选中上一次播放文件的位置 CTreeViewUI *pTree = static_cast<CTreeViewUI*>(m_PaintManager.FindControl(_T("treePlaylist"))); if (pTree) { pTree->SelectItem(m_iPlaylistIndex, true); } }