|
Thanx It seem useful.
I will try it.
|
|
|
|
|
I have created a Ribbon MDI Application and it is working fine. My problem is I am unable to reposition the frame window after restoring the frame window.What is the problem?
Ashok.R
|
|
|
|
|
Sample code is as follows:
class TestClass
{
CCriticalSection m_csTest;
void Fun1()
{
m_csTest.Lock();
Fun2();
MessageBox("In Fun1 critical section.");
m_csTest.Unlock();
}
void Fun2()
{
m_csTest.Lock();
MessageBox("In Fun2 critical section.");
m_csTest.Unlock();
}
};
I am pretty aware we should not do this. But what will be the situation? Do I need to unlock the critical section twice as shown in the code or only one time unlock is sufficient?
|
|
|
|
|
Nothing happens if you lock the critical section from the same thread twice.It prevents the thread from dead lock.
But in above case calling
m_csTest.Unlock();
twice might create problem. i am not sure about this.
May be some one else will comment on it.
Regards,
Sandip.
|
|
|
|
|
Thanks for quick response. I will wait for more replies.
|
|
|
|
|
Member 3066459 wrote: I am pretty aware we should not do this. But what will be the situation? Do I need to unlock the critical section twice as shown in the code or only one time unlock is sufficient?Confused
From MSDN:
After a thread has ownership of a critical section, it can make additional calls to EnterCriticalSection or TryEnterCriticalSection without blocking its execution. This prevents a thread from deadlocking itself while waiting for a critical section that it already owns.
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
According to the docs:
http://msdn.microsoft.com/en-us/library/ms682608.aspx[^]
"A thread must call LeaveCriticalSection once for each time that it entered the critical section."
Which seems pretty clear. Even without reading them, it would be good to do a Leave for every Enter. At worst you are wasting your time. At best, it is needed.
Iain.
|
|
|
|
|
I guess only one unlock() is sufficient since it is the same critical section being requested again.
|
|
|
|
|
When call lock() its lock count will be 1. When we call again lock count will increment by 1.Hence it is necessary to call unlock() as many times you have called lock().
|
|
|
|
|
Hi all,
I just want to know why my progress bar wont move at all.
void CUpdateDlg::DownloadThread(string SavePath, string Link, string Name, string NameVersion)
{
int dloadPos, finalPos;
FILE * pFile = NULL;
DWORD dwPacketSize =5;
PBYTE pBuffer = new BYTE[dwPacketSize * 1024];
double dOffsetToSeek =0;
std::string strTmpFileName = SavePath.c_str();
strTmpFileName.append(".tmp");
std::string strFileNameAtLocalMachine= SavePath.c_str();
int res = DeleteFile(strFileNameAtLocalMachine.c_str());
double dCurrentFileSize;
if(IfLocalFileExist(strTmpFileName.c_str(), &dCurrentFileSize))
{
dOffsetToSeek = dCurrentFileSize;
}
ATL::CString strRangeQuest;
dloadPos = dCurrentFileSize;
ProgressBar.SetPos(dloadPos);
if(dCurrentFileSize>0){
strRangeQuest.Format( _T("%sRange: bytes=%d-\r\n"), szHeaders,static_cast<ULONGLONG>(dCurrentFileSize));
}
else
strRangeQuest = szHeaders;
if (!(pFile = fopen (strTmpFileName.c_str(), "a+b" ) ) )
{
return;
}
try
{
CInternetSession Session(_T("UpdateService"));
CHttpConnection Connection1(Session,Link.c_str());
BYTE Buffer[4096];
CHttpFile dFile(Session,Link.c_str());
CInternetFile::CInfo Info(dFile);
dFile.SendRequest(strRangeQuest);
DWORD dwFileLength;
dFile.GetLength(dwFileLength);
DWORD dwRead;
finalPos = dwFileLength;
ProgressBar.SetRange(dloadPos, finalPos);
for (dwRead = 1 ; dwRead;)
{
dFile.Read(Buffer,sizeof(Buffer),dwRead);
if (dwRead>0)
fwrite(Buffer, sizeof (char), dwRead , pFile);
IfLocalFileExist(strTmpFileName.c_str(), &dCurrentFileSize);
dloadPos = dCurrentFileSize;
ProgressBar.SetPos(dloadPos);
}
fclose (pFile);
BOOL moved = MoveFile(strTmpFileName.c_str(), strFileNameAtLocalMachine.c_str());
if(moved)
{
DloadCompNotify.EnableWindow(TRUE);
EmailUser(strFileNameAtLocalMachine.c_str());
}
DeleteFile(strTmpFileName.c_str());
HKEY hkey;
TCHAR szKey[256];
int nValue = 0;
szKey[0] = _T('\0');
_tcscpy(szKey, ServiceRegEntry);
_tcscat(szKey, UPDATEMGR);
_tcscat(szKey, ServiceParam);
_tcscat(szKey, _T("\\"));
_tcscat(szKey, Name.c_str());
_tcscat(szKey, _T("\\"));
_tcscat(szKey, NameVersion.c_str());
if (RMRegOpenKeyEx(HKEY_LOCAL_MACHINE,szKey,0,KEY_QUERY_VALUE | KEY_SET_VALUE,&hkey) == ERROR_SUCCESS)
{
nValue = 1;
RMRegSetValueEx(hkey,UPDATESTAT,0,REG_DWORD,(BYTE*)&nValue,sizeof(nValue));
RMRegCloseKey(hkey);
}
}
catch(CInternetException& err)
{
err.GetErrorMessage();
}
}
Please advise what you can find out.
thanks,
Jayjay
|
|
|
|
|
You should not update UI from the worker thread.
You can send message to Main UI thread to update the progress bar.
I hope it makes sense.
Regards,
Sandip.
|
|
|
|
|
SandipG wrote: I hope it makes sense.
Actually it makes perfect sense.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Regards,
Sandip.
|
|
|
|
|
As mentioned by others you should not access UI components from your thread.
However, it appears that you're really just using SetPos, which should be OK. One thing you can try is after every call to
ProgressBar.SetPos(); add a call to
ProgressBar.UpdateWindow();
UpdateWindow() sends a message directly to the window, bypassing the normal message queue.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Hi,
I am using mfc 9.0 for developing an application. I Created one SDI application with CScrollview as base class. i am having the Dialog box. once i clicked Add Dialog from the menu, then the Dialog box was loaded. i am having zooming options to zoom the Dialog as well as SDI Client area. The dialog box is zooming correctly if i am not scroll manually. Once i scroll manually, then the zooming for the Dialog box is not working correctly.
Please Help me..
|
|
|
|
|
This link may help.[^]
Regards,
Rane
|
|
|
|
|
How does the output vary for pre and post increment operators?
In this code, how and why does value of 'a' vary?
main()
{
int a=0;
printf("%d\n",a++);
printf("%d\n",++a);
}
OUTPUT:
0
2
main()
{
int a=0;
printf("%d %d\n",a++,++a);
}
OUTPUT:
1,1
|
|
|
|
|
main()
{
int a=0;
printf("%d\n",a++); // POST INCREMENT a is still 0
// HERE a is 1
printf("%d\n",++a); // PRE INCREMENT a is (1+1) = 2 now
}
main()
{
int a=0;
printf("%d %d\n",a++,++a); // Move from right to left
// ++a is pre increment so value for a is 1 for ++a. a++ is post increment so the value still remains 1 for a++
// Here a would be 2
}
Preincrement means the value is first operated upon and then used, while in post increment the value is first used then the change happens
Hope this helps
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
the developer shouldn't rely on the order of the parameters.
your inline printf() (the second example) is really bad.
On Visual C++, the parameters are unstacked from right to left, so when you do
printf("%d %d\n",a++,++a) ++a is evaluated before a++ .
this may be different on other compilers.
for how the value of a vary, you have to know how pre and post increment operators work.
Preincrement (++a) increments the variable and returns its new value (the value after the incrementation).
Postincrementation (a++) increments the variable ans returns its old value (the value before the incrementation).
|
|
|
|
|
i need to edpand the button to show following options
Import Traffic matrix
View and Export Traffic matrix
|
|
|
|
|
What do you mean ?
A button doesn't expand. it is clickable, and eventually can be shown as a checkbox/radio.
|
|
|
|
|
toxcct wrote: What do you mean ?
Probably he wants to show the popup menu on click of the button
toxcct wrote: A button doesn't expand. it is clickable, and eventually can be shown as a checkbox/radio.
But Why are you down voted for this??
Regards,
Sandip.
|
|
|
|
|
probably, and I thought of that too, but God, what if the OP doesn't specify it clearly ?
are we supposed to read in mind ?
So is my answer worth a 1 ?!
|
|
|
|
|
My guess would be that the OP wants to display the "Import Traffic matrix" text initially on the button. When the user clicks on the button he wants to display "View and Export Traffic matrix" on the same button, which obviously won't fit the initial size(something he sets depending on "Import Traffic matrix" at design time)
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
yes u are right
ok sorry i am new to MFC
|
|
|
|