|
I use a tab control in a dialog which is as a property setup window and put three dialogs into this tab control.Here is the problem,how can i destroy this three dialog and the mian dialog,return to the mian window.
|
|
|
|
|
If the dialog is modal, it will get destroyed when you click OK or Cancel.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi!
I have an application which sits in the system tray globally listening for a combination key press event (CTRL+ALT+T). Instead of opening the app by right clicking the app icon in the tray bar (clicking Open), I would like to open the app window upon CTRL+ALT+T. When that happens, sometimes (more often than not) the window loses focus/gets inactivated and I manually need to click it to regain focus.
What else besides the following lines of code can be done to force the app foreground, topmost, focused and active?
((CMyAppDlg*) AfxGetApp()->GetMainWnd())->ShowWindow(SW_SHOW);
((CMyAppDlg*) AfxGetApp()->GetMainWnd())->SetFocus();
((CMyAppDlg*) AfxGetApp()->GetMainWnd())->SetForegroundWindow();
Thx!
/T
|
|
|
|
|
The behavior of the SetForegroundWindow Function[^] can be affected by SPI_GETFOREGROUNDLOCKTIMEOUT as described in the SystemParametersInfo Function[^]
See if this works for you:
HWND hWnd = GetForegroundWindow();
DWORD dwThread = GetCurrentThreadId();
DWORD dwProcessID = GetWindowThreadProcessId(hWnd,NULL);
if(hWnd > 0)
{
AttachThreadInput(dwProcessID,dwThread,TRUE);
(AfxGetApp()->GetMainWnd())->SetForegroundWindow();
AttachThreadInput(dwProcessID,dwThread,FALSE);
}
Best Wishes,
-David Delaune
|
|
|
|
|
Try BringWindowToTop function.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi all,
i have SDI type application,and split it in two columns.
for one column i m using a Treeview and for another one i m using a FormView.
The crash points to atlsimpstr.h line 107, trying to step through the debugger just tells me it is outside of the application, with ATLASSERT() inside CstringData in the method Release().
The debuger stops on the following "ATLASSERT()", obviously it expects nRefs to equal zero, and it is not so, but what does it refer to, I have no idea, or how do I find out either. This is inside "ATLSIMPSTR.H",
void Release() throw()
{
ATLASSERT( nRefs != 0 );
if( _AtlInterlockedDecrement( &nRefs ) <= 0 )
{
pStringMgr->Free( this );
}
}
My application's name is Test.EXE - here is the call stack dump at the point of the crash...
<br />
Test.exe!ATL::CStringData::Release() Line 107 + 0x25 bytes C++<br />
Test.exe!ATL::CSimpleStringT<wchar_t,0>::operator=(const ATL::CSimpleStringT<wchar_t,0> & strSrc="127.0.0.1") Line 300 C++<br />
Test.exe!CLeftView::ConnectNet() Line 640 + 0x2d bytes C++<br />
Test.exe!ThreadFunc(void * pT=0x01ee7d40) Line 773 C++<br />
Test.exe!_AfxThreadEntry(void * pParam=0x005eed14) Line 109 + 0xf bytes C++<br />
Test.exe!_callthreadstartex() Line 348 + 0xf bytes C<br />
Test.exe!_threadstartex(void * ptd=0x01eea230) Line 331 C<br />
kernel32.dll!760f4911() <br />
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll] <br />
ntdll.dll!775ce4b6() <br />
ntdll.dll!775ce489() <br />
<br />
Hope someone can help me out here…
thanks n regards.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
What are you doing in your CLeftView::ConnectNet function ? Show some code around the line 640, because it seems you are doing something wrong there. IT seems you are doing something wrong with a string assignement.
BTW, when you have such a crash, 99.999% of the time it means you did something wrong in your code. So, if you don't post any of the code around where the crash occurs, it's almost impossible for us to help you.
|
|
|
|
|
CString dnsbuf_str,IPdomain;
IPdomain = HostInfo(dnsbuf_str);
and
CString CLeftView::HostInfo(CString str)
{
CString str1;
struct hostent *remoteHost;
ShellExecute(NULL,_T("Open"), _T("ipconfig.exe"),_T("/flushdns"),NULL,0);
char *host_name = new char [str.GetLength()+1];
memset(host_name,0,str.GetLength()+1);
wcstombs(host_name, str, str.GetLength()+1);
struct in_addr addr;
WSADATA wsaData;
int iResult;
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0)
return _T("N/A");
remoteHost = gethostbyname(host_name);
if (remoteHost == NULL)
return _T("N/A");
else
{
addr.s_addr = *(u_long *) remoteHost->h_addr_list[0];
str1=CString(inet_ntoa(addr));
return str1;
}
}
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
I asked for the CLeftView::ConnectNet method, not the HostInfo method. Could you post the correct method (and also indicate which line is the 640 line) ?
On the other hand, you have a flaw with your code: you suppose that UNICODE is always defined (because you always convert your input string to a multibyte characters string). If you later undefine UNICODE or wants to make a non-UNICODE build, your program will probably crash. Make sure you make the conversion only when unicode is enabled.
|
|
|
|
|
void CLeftView::ConnectNet(void)
{
CString server_name=mServer;
CString dnsbuf_str = dnsBuf;
IPdomain = HostInfo(dnsbuf_str);
CString hostBuf_str = hostBuf;
IPhost = HostInfo(hostBuf_str);
if(Oncef==1)
{
hostCtr=0;
Oncef++;
LPSERVER_INFO_101 pBuf = NULL;
LPSERVER_INFO_101 pTmpBuf;
DWORD dwLevel = 101;
DWORD dwPrefMaxLen = -1;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwTotalCount = 0;
DWORD dwServerType = SV_TYPE_SERVER;
DWORD dwResumeHandle = 0;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;
DWORD i;
nStatus = NetServerEnum(NULL,dwLevel,(LPBYTE *) &pBuf,dwPrefMaxLen,&dwEntriesRead,
&dwTotalEntries,dwServerType,NULL,&dwResumeHandle);
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
for (i = 0; i < dwEntriesRead; i++)
{
if (pTmpBuf == NULL)
break;
LPWSTR szSName=pTmpBuf->sv101_name;
CString szSName_str = szSName;
IPhost=HostInfo(szSName_str);
if(_tcscmp(IPdomain,IPhost) && _tcscmp(mServer,szSName)!=0)
{
hCh1=GetTreeCtrl().InsertItem(szSName,0,0,hChild3);
GetTreeCtrl().Invalidate(1);
szHostList[hostCtr]=szSName;
hostCtr++;
}
else
{
szHostList[hostCtr]=szSName;
hostCtr++;
}
pTmpBuf++;
dwTotalCount++;
}
if (nStatus == ERROR_MORE_DATA)
{
}
}
m_bEnable1=TRUE;
m_bEnable=FALSE;
}
else
{
m_bEnable=TRUE;
m_bEnable1=FALSE;
Oncef=1;
}
if (pBuf != NULL)
NetApiBufferFree(pBuf);
}
}
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
What is this HostInfo function ? I never saw that and I can't really find something usefull when googling for it. Do you have a link to the documentation ?
|
|
|
|
|
I m already define HostInfo function in my above post.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Put a breakpoint on line 640 (when you call the HostInfo function) and inspect the content of dnsbuf_str. Does it contain something valid ?
|
|
|
|
|
So which of these statements is causing the problem?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
"_$h@nky_" wrote: str1=CString(inet_ntoa(addr));
I guess this is wrong too (and that's probably your problem): if UNICODE is defined (which is what you expect apparently), you are passing a multi-byte characters string to the CString constructor and as UNICODE is defined, it is expecting a wide characters string.
I strongly suggest that you read this article[^]. All the things related to strings and unicode will be a bit clearer afterwards.
|
|
|
|
|
Cedric Moonen wrote: str1=CString(inet_ntoa(addr));
I guess this is wrong too (and that's probably your problem): if UNICODE is defined (which is what you expect apparently), you are passing a multi-byte characters string to the CString constructor and as UNICODE is defined, it is expecting a wide characters string.
Please tell me how can i write this line
str1=CString(inet_ntoa(addr));
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
First thing, I really suggest that you read the article I mentioned in my other post. If you don't understand the basics here, you will have all the time the same problem when you manipulate strings. So, take some time to gain some valuable knowledge and understand the concept of unicode. It will make you gain a lot of time in the future.
"_$h@nky_" wrote: Please tell me how can i write this line
I think that maybe I am mistaken here: if the CString constructor was expecting a wide-char sequence only, then the code would not compile. But in your case it seems to compile fine so the problem should be somewhere else.
|
|
|
|
|
The problem is still exist please help me.....
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
I forget one thing to mention,this problem occur when i convert my code from VS-2006 to VS-2008.
its works perfectly fine in VS-2006.
so please help me.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Hello!
Let's say we have the following:
class MyClass
{
public:
void SetValue( __int64 a_i64Value );
__int64 GetValue( void ) const;
private:
__int64 m_i64Value;
};
void MyClass::SetValue( __int64 a_i64Value )
{
m_i64Value = a_i64Value;
}
__int64 MyClass::GetValue( void ) const
{
return m_i64Value;
}
We also have two threads: ThreadA and ThreadB , each setting the value of m_i64Value to something different.
Let's assume that ThreadA executes and SetValue is called. It writes 32 bits of m_i64Value , ThreadB executes, it calls SetValue which also writes 32 bits of m_i64Value , then ThreadA resumes and continues writing the other 32 bits of m_i64Value . Finally, ThreadB also writes the other half of m_i64Value . Eventually, m_i64Value contains garbage, invalid data.
Question 1: Is this scenario valid? Can it happen on a 32 bit machine?
Anyway, this can be solved using InterlockedExchange64 , right?
But let's suppose there is a ThreadC which needs to read that value, using the member function GetValue . When returning from GetValue , 32 bits of m_i64Value get written to EAX register and 32 bits to EDX .
Question 2: What if 32 bits get written to EAX , ThreadB resumes and writes to m_i64Value and after that, ThreadC resumes and the other 32 bits (changed by ThreadB ) go to EDX ? Is this also a possibility on 32 bit machines? If yes, what is the best way to return such a value (__int64, in this example)?
I guess one of the solutions could be this one:
void GetValue( __int64 *a_pi64Value )
{
if ( NULL != a_pi64Value )
{
InterlockedExchange64( *a_pi64Value, m_i64Value );
}
}
Question 3: But what if we still want to actually return the value and not copy it to the memory pointed by a_pi64Value ? Can this be done somehow thread-safely and using the return instruction?
Thanks in advance!
|
|
|
|
|
Eikthrynir wrote: Question 1: Is this scenario valid? Can it happen on a 32 bit machine?
Yes as the MSDN states in the article Interlocked Variable Access[^]:
Reads and writes to 64-bit values are not guaranteed to be atomic on 32-bit Windows. Reads and writes to variables of other sizes are not guaranteed to be atomic on any platform.
Eikthrynir wrote: Question 2: What if 32 bits get written to EAX, ThreadB resumes and writes to m_i64Value and after that, ThreadC resumes and the other 32 bits (changed by ThreadB) go to EDX? Is this also a possibility on 32 bit machines? If yes, what is the best way to return such a value (__int64, in this example)?
Eikthrynir wrote: Question 3: But what if we still want to actually return the value and not copy it to the memory pointed by a_pi64Value? Can this be done somehow thread-safely and using the return instruction?
I would personally do it like this:
LONGLONG GetValue(__int64 *a_pi64Value)
{
return InterlockedExchangeAdd64(a_pi64Value,0);
}
Best Wishes,
-David Delaune
modified on Wednesday, May 13, 2009 11:41 AM
|
|
|
|
|
Hello!
Thanks for the reply!
I would like to make a few comments regarding your version of GetValue ...
1. You call InterlockedExchange64 with a_pi64Value as the first parameter, so the __int64 variable pointed by a_pi64Value gets 0 . Then, you return the previous value of that __int64 variable which is certainly not the one we are interested in, m_i64Value .
2. GetValue returns a LONGLONG value, so we find ourselves in exactly the same situation from Question 2 (concerning the EAX and EDX registers)...
Best regards!
|
|
|
|
|
Eikthrynir wrote: 1. You call InterlockedExchange64 with a_pi64Value as the first parameter, so the __int64 variable pointed by a_pi64Value gets 0. Then, you return the previous value of that __int64 variable which is certainly not the one we are interested in, m_i64Value.
If the 64 bit integer variable you want to read atomically is m_i64Value
Then the correct way to atomically read the value is:
__int64 i64Val = InterlockedExchangeAdd64(m_i64Value,0);
Eikthrynir wrote: 2. GetValue returns a LONGLONG value, so we find ourselves in exactly the same situation from Question 2 (concerning the EAX and EDX registers)...
This statement does not make any sense to me.
Best Wishes,
-David Delaune
|
|
|
|
|
Dear All,
Can anybody please tell me how to find whether a SCSI hard disk has S.M.A.R.T. support or not and also its S.M.A.R.T. features using M.F.C?
Thank You
|
|
|
|
|
What about the previous replies[^] given to you?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|