Dialog1 ::Onok()
{
HWND hShareWnd = NULL;
UpdateData();
bDesktopShareStarted = !bDesktopShareStarted ;
if(bDesktopShareStarted)
{
int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);
int x = 0;
int y =0;
CVariableRegion VariableRgnDlg; if(VariableRgnDlg.DoModal() ==IDOK)
{
hShareWnd = VariableRgnDlg.GetShareWindow();
width = VariableRgnDlg.GetShareWidth();
height = VariableRgnDlg.GetShareHeight();
x = VariableRgnDlg.GetShareXPosition();
y= VariableRgnDlg.GetShareYPosition();
if(m_bEnableAVIRecording)
EnableAVIRecording();
else
EnableAVIRecording(FALSE);
ZeroMemory(szBuffer,sizeof(szBuffer));
GetDlgItemText(IDC_EDIT_CODE,szBuffer,sizeof(szBuffer));
lLength = _tcslen(szBuffer) + 1 ;
SetRegInfo(LASTUSED_SESSION,szBuffer,REG_SZ,&lLength);
ZeroMemory(szBuffer,sizeof(szBuffer));
GetDlgItemText(IDC_EDIT_PASS,szBuffer,sizeof(szBuffer));
lLength = _tcslen(szBuffer);
SetRegInfo(LASTUSED_SESSION_PASS,szBuffer,REG_SZ,&lLength);
ZeroMemory(szBuffer,sizeof(szBuffer));
GetDlgItemText(IDC_EDIT_CLIENT_NAME,szBuffer,sizeof(szBuffer));
lLength = _tcslen(szBuffer);
SetRegInfo(LASTUSED_USERNAME,szBuffer,REG_SZ,&lLength);
lLength = sizeof(m_bEnableAVIRecording);
m_bEnableAVIRecording = IsDlgButtonChecked(IDC_CHECK_AVI_REC);
SetRegInfo(LASTOPTION_AVI,(LPTSTR)&m_bEnableAVIRecording,REG_DWORD,&lLength);
StartDesktopShare(hShareWnd,width,height,x,y,GetDlgItem(IDC_TARGETWND)->m_hWnd);
GetDlgItem(IDC_BUTTON_DSK_SHARE)->SetWindowText(TEXT("Stop Share"));
}
else
{
StopDesktopShare();
GetDlgItem(IDC_BUTTON_DSK_SHARE)->SetWindowText(TEXT("Start Share"));
bDesktopShareStarted = !bDesktopShareStarted ;
}
}
else
{
StopDesktopShare();
GetDlgItem(IDC_BUTTON_DSK_SHARE)->SetWindowText(TEXT("Start Share"));
}
}
dialog 2 code
in dialog 2 on button click this function is called.
long CVariableRegion::GetWindowsList()
{
HWND hListBox = NULL;
TCHAR sWindowCount[100] = {0};
int nWindowsCount = 0;
CWnd *hDeskopWnd = NULL;
TCHAR szWindowCountTitle[MAX_PATH]={0};
hListBox = GetDlgItem(IDC_WIN_LIST)->m_hWnd;
ListBox_ResetContent(hListBox);
ZeroMemory(sWindowCount,sizeof(sWindowCount));
ZeroMemory(szWindowCountTitle,sizeof(szWindowCountTitle));
LoadString(GetModuleHandle(NULL),IDS_STRING_PLEASEWAIT,szWindowCountTitle,sizeof(szWindowCountTitle));
SetDlgItemText(IDC_WIN_CNT,szWindowCountTitle);
Sleep(100);
hDeskopWnd = GetDesktopWindow() ;
WindowsHandle ( hDeskopWnd -> m_hWnd, ( LPARAM ) hListBox ) ;
EnumWindows ( WindowsHandle, ( LPARAM ) hListBox ) ;
nWindowsCount = ListBox_GetCount(hListBox);
_stprintf(sWindowCount,TEXT("Windows : %d"),nWindowsCount);
SetDlgItemText(IDC_WIN_CNT,sWindowCount);
return 0;
}
BOOL CALLBACK WindowsHandle ( HWND hwnd, LPARAM lParam )
{
DWORD dwExtent;
HDC hDCListBox;
HFONT hFontOld;
HFONT hFontNew;
TEXTMETRIC tm;
CWnd *hWindow;
CString strTitle;
SIZE Size;
TCHAR szCurTitle[MAX_PATH] ={0};
TCHAR szCurParentTitle[MAX_PATH] ={0};
HWND hListBox;
CWnd *pComboBox;
HWND hWndListBox;
long lExtent;
hWindow = NULL;
dwExtent = 0;
hDCListBox = NULL;
hFontNew = NULL;
hFontOld = NULL;
Size.cx = 0;
Size.cy = 0;
pComboBox = NULL;
hWndListBox = NULL;
lExtent = 0;
hListBox = ( HWND ) lParam ;
hWindow = CWnd::FromHandle ( hwnd ) ;
hWindow -> GetWindowText ( strTitle ) ;
if(hWindow->IsWindowVisible() && (strlen(strTitle) > 0 ) )
{
ZeroMemory(szCurTitle,sizeof(szCurTitle));
ZeroMemory(szCurParentTitle,sizeof(szCurParentTitle));
pComboBox = CWnd::FromHandle ( hListBox ) ;
GetWindowText(GetParent(pComboBox->m_hWnd),szCurTitle,sizeof(szCurTitle));
GetWindowText(GetParent(GetParent(pComboBox->m_hWnd)),szCurParentTitle,sizeof(szCurParentTitle));
if( (_tcsicmp(szCurTitle,strTitle) != 0 ) && (_tcsicmp(szCurParentTitle,strTitle) != 0 ) )
if(_tcsicmp(strTitle,TEXT("Program Manager")) !=0 )
( ( CListBox * ) pComboBox )->AddString (strTitle ) ;
hWndListBox = pComboBox->m_hWnd;
hDCListBox = GetDC(hWndListBox);
hFontNew = (HFONT)::SendMessage(hWndListBox, WM_GETFONT, NULL, NULL);
hFontOld = (HFONT)SelectObject(hDCListBox, hFontNew);
GetTextMetrics(hDCListBox,&tm);
dwExtent = GetTextExtentPoint(hDCListBox, strTitle , (strlen(strTitle )+ tm.tmAveCharWidth),&Size);
SelectObject(hDCListBox, hFontOld);
ReleaseDC(hWndListBox, hDCListBox);
lExtent = pComboBox->SendMessage(LB_GETHORIZONTALEXTENT);
if(lExtent < Size.cx)
{
lExtent = Size.cx;
pComboBox->SendMessage(LB_SETHORIZONTALEXTENT,lExtent);
}
}
return TRUE ;
}
I pasted the code snippet for dialog 1 and dialog 2
|