@@ -259,10 +259,19 @@ BOOL CAgoraScreenCapture::OnInitDialog()
259259
260260void CAgoraScreenCapture::InitMonitorInfos ()
261261{
262- m_monitors.EnumMonitor ();
262+ m_monitors.EnumMonitor ();
263263
264264 std::vector<CMonitors::MonitorInformation> infos = m_monitors.GetMonitors ();
265- CString str = _T (" " );
265+ for (size_t i = 0 ; i < infos.size (); i++) {
266+ char szName[MAX_PATH] = { 0 };
267+ sprintf_s (szName, MAX_PATH, " Display%d" , i + 1 );
268+ CString strDevice = infos[i].monitorInfo .szDevice ;
269+ strDevice.Replace (L" \\\\ .\\ " , L" " );
270+ m_cmbScreenRegion.InsertString (i, strDevice.GetBuffer (0 ));
271+ }
272+ m_cmbScreenRegion.SetCurSel (0 );
273+
274+ /* CString str = _T("");
266275 for (size_t i = 0; i < infos.size(); i++) {
267276 RECT rcMonitor = infos[i].monitorInfo.rcMonitor;
268277 CString strInfo;
@@ -278,8 +287,11 @@ void CAgoraScreenCapture::InitMonitorInfos()
278287 }
279288
280289 m_cmbScreenRegion.InsertString(infos.size(), _T("Select Window Hwnd Rect Area"));
281- m_staScreenInfo.SetWindowText (str);
282- m_cmbScreenRegion.SetCurSel (0 );
290+ m_staScreenInfo.SetWindowText(str);*/
291+
292+
293+ // m_cmbScreenRegion.SetCurSel(0);
294+
283295}
284296
285297// The JoinChannel button's click handler.
@@ -775,37 +787,17 @@ void CAgoraScreenCapture::OnBnClickedButtonStartShareScreen()
775787 m_screenShare = !m_screenShare;
776788 if (m_screenShare) {
777789 int sel = m_cmbScreenRegion.GetCurSel ();
778- agora::rtc::Rectangle regionRect = { 0 ,0 ,0 ,0 }, screenRegion = {0 ,0 ,0 ,0 };
779- if (sel < m_monitors.GetMonitorCount ())
780- {// share screen rect area
781- // regionRect = m_monitors.GetMonitorRectangle(sel);
782- // screenRegion = m_monitors.GetScreenRect();
783- screenRegion = m_monitors.GetMonitorRectangle (sel);
784- // m_monitors.GetMonitors()[1].scale_den;
785- regionRect = { 0 ,0 ,m_monitors.GetMonitorRectangle (sel).width ,m_monitors.GetMonitorRectangle (sel).height };
786- }
787- else {
788- // get selected window HWND
789- if (m_cmbScreenCap.GetCurSel () != m_cmbScreenCap.GetCount () - 1 ) {
790- HWND hWnd = NULL ;
791- hWnd = m_listWnd.GetAt (m_listWnd.FindIndex (m_cmbScreenCap.GetCurSel ()));
792- HMONITOR hMonitor = MonitorFromWindow (hWnd, MONITOR_DEFAULTTONEAREST);
793- if (!m_monitors.CheckMonitorValid (hMonitor)) {
794- AfxMessageBox (_T (" The monitor that window is located in can not be shared.\n The monitor rect area has negative cordinate." ));
795- return ;
796- }
797-
798- m_monitors.GetMonitorRectangle (hMonitor, screenRegion);
799- m_monitors.GetWindowRect (hWnd, regionRect);
800- }
801- }
802-
803- m_monitors.GetScreenRect ();
790+ agora::rtc::Rectangle regionRect = { 0 ,0 ,0 ,0 };
804791 ScreenCaptureParameters capParam;
805-
806- m_rtcEngine->startScreenCaptureByScreenRect (screenRegion, regionRect, capParam);
807- m_lstInfo.InsertString (m_lstInfo.GetCount () - 1 , _T (" startScreenCaptureByScreenRect" ));
808-
792+ CString displayId = L" " ;
793+ m_cmbScreenRegion.GetWindowText (displayId);
794+ int id = _ttoi (displayId.Mid (strlen (" display" ))) - 1 ;
795+ m_rtcEngine->startScreenCaptureByDisplayId (id, regionRect, capParam);
796+
797+ m_lstInfo.InsertString (m_lstInfo.GetCount () - 1 , _T (" startScreenCaptureByDisplayId" ));
798+ CString strInfo;
799+ strInfo.Format (_T (" DisplayId: %d" ), id);
800+ m_lstInfo.InsertString (m_lstInfo.GetCount () - 1 , strInfo);
809801 m_btnShareScreen.SetWindowText (screenShareCtrlStopShare);
810802 // start preview in the engine.
811803 m_rtcEngine->startPreview ();
0 commit comments