|
|
What have you tried so far? Do you have a starting address from which to read?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi I have using MFC dialog application. in that it is calling another dialog.
in 2nd dialog i am enumerating the windows using enumwindows api. after calling the enumwindows application is freezing or hanging. any idea about this.
|
|
|
|
|
Does your callback get called at all?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Please post the code snippet where the application hangs.
APIs never hang application, only the way of using it.
Something might went wrong in the callback.
--
"Programming is an art that fights back!"
|
|
|
|
|
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
|
|
|
|
|
<br />
<br />
int i =2;<br />
int j = ++i + ++i;<br />
<br />
cout<<" value of j is : " << j;<br />
<br />
in the above code the output value of j is 8,I am confused about that.Please help?
|
|
|
|
|
No need to be confused
++i => i = 3
++i => i = 4
+ => 4+4 = 8
|
|
|
|
|
where does the 2nd '4' come from, in your bottom line ?
|
|
|
|
|
There is only one instance of i, so i will be incremented twice before the addition occurs.
|
|
|
|
|
|
Just playing devil's advocate...
But you're not adding i twice, you're adding the results of the expression ++i which is either going to be 3 or 4 depending on how many times you've done the ++ operation.
Cheers,
Ash
|
|
|
|
|
...but if you add 3 and 4 you will not get 8, and the OP would not have been confused in the first place. It would be a shame if once in a while you didn't get an unexpected result. (The testing department might disagree on that though)
|
|
|
|
|
This is a common issue and the rules are: don't do this as the results are not guaranteed. Whatever answer you get you may get a different answer with another manufacturer's compiler. If you really need to evaluate such an expression you need to break it into steps like:
int i = 2;
int j = ++i;
j += ++i;
It's time for a new signature.
|
|
|
|
|
It's pretty subtle. Here's a breakdown of what's hapenning:
++i increments i (so i =3) and returns a reference to i .- The second
++i increments i (so i =4) and returns a reference to i . - The
+ is called with the two references. Both are dereferenced and added (4+4).
Steve
|
|
|
|
|
int i = 2;<br />
<br />
int j = ++i + i++ + ++i + i++ + ++i;<br />
<br />
cout<<"Value of j: "<<j;
The value getting for 'j' is 19. As you have said the three ++i statements will execute and the value of i become 5. How will execute the i++ statements? Could you please explain.
|
|
|
|
|
Firstly there are two cases here, the pre-increment and (++i ) the post-increment (i++ ). The pre-increment case increments the variable and returns a reference to it. The post-increment case copies the variable, increments the original and returns the copy.
Steve
|
|
|
|
|
To reinforce what Richard said, while this is cute, it's always counterproductive. It's so subtle that even if you KNOW what you're doing, you're going to screw it up and in a production environment, you're going to confuse someone who's not was good with obfurscated code as you think you are. Just write it out in the clearest possible terms and let the compiler worry about optimizing it these days. The compiler can do optimizations that would curl your hair if you looked at what it was doing.
Once you agree to clans, tribes, governments...you've opted for socialism. The rest is just details.
|
|
|
|
|
Hi all
i have been experimenting with CAsyncSocket and have derived my own class. I am able to connect a client to a server app that I have written (VC6) and all is working well.
My first question is why does the server have to accept on another socket?
My second question is if the server is to be designed to accept 64 clients connecting to it, does that mean I need to define 128 sockets
Thanks for having a look at this!
Regards
Mike
|
|
|
|
|
MikeRWinter wrote: My first question is why does the server have to accept on another socket?
TCP is a connection oriented protocol, the server needs to accept the connection and a handshake is performed before further communication will be possible (which is part of TCP's reliable data transfer). On the other hand, if you are working with UDP, which is not connection oriented, you don't have to call accept(), sockets can just send data when they feel like (which could also mean nobody is listening to them).
MikeRWinter wrote: My second question is if the server is to be designed to accept 64 clients connecting to it,
Where does this limit come from, not sure what you mean?
/Moak
|
|
|
|
|
Greetings,
I am trying to populate a CTabCtrl in my dialog with child dialogs but I am having terrible problems with inheritance of the CWnd*.
Now I assume that is what it is as the dialogs I create are spawning in their own window rather than the client window of the control. Below is snippet of my class
CTabManage::CTabManage()
{
m_tab[0]=new CDetails;
...
void CTabManage::Init()
{
m_tabActive=0;
m_tab[0]->Create(IDD_TAB_DETAILS, this);
...
and here is where it is initialised
::OnInitDialog()
...
m_cTabManage.InsertItem(0, _T("Details"));
m_cTabManage.Init();
...
Any pointers would be appreciated as it has been driving me nuts.
Alan
|
|
|
|
|
Is the WS_CHILD set for you child dialogs? In the resource properties for your dialogs make sure Style=Child , and you probably would like Control=True as well.
|
|
|
|
|
Thank you. That got it.
That was the one thing I had not checked.
Alan
|
|
|
|
|
Hi everyone,
Can anyone tell me how to convert a vector (of doubles) to a variant?
I am receiving the following error message from vc++ 2008:
error C2664: 'CiPlotChannelX::AddXYArrays' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'const VARIANT &'
I have close to 1 million values so I'm trying to avoid any "for" loops.
Thanks!
|
|
|
|
|
Never needed to do this but i read somewhere that you can use CComSafeArray[^] to get a variant, or something that you can use with variant from an array. I think you need to wrap your array into this CComSafeArray thing (it is a template i believe) and then use Detach or maybe it's LPSAFEARRAY operator to get a SAFEARRAY wich can be used with VARIANT.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers don't kill programs, users kill programs <
> "It doesn't work, fix it" does not qualify as a bug report. <
|
|
|
|