|
IT_DOER wrote: CString* pt_str=(CString*)lpDrawItemStruct->itemData;
The code above is wrong, you cannot cast lpDrawItemStruct->itemData to a CString * .
Please use the original code:
LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
and then
dc.TextOut(lpDrawItemStruct->rcItem.left+4,lpDrawItemStruct->rcItem.top+2,
lpszText);
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.
|
|
|
|
|
I have a class which sets a timer to fire every five minutes:
m_hTimer = ::SetTimer(NULL, NULL, 5*60*1000, MyTimerProc);
Dependent on circumstances, MyTimerProc() may need to ask for user intervention (for simplicity I'll use an AfxMessageBox()). Obviously I don't want the AfxMessageBox to pop up multiple times should the program be unattended for a period of time. I have come up with the following:
void CALLBACK MyTimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)<br />
{<br />
static bool locked = false;<br />
<br />
if (!locked)<br />
{<br />
locked = true;<br />
AfxMessageBox("HELLO");<br />
locked = false;<br />
}<br />
}
Of course, I'd rather be using something safer than the frankly dodgy static variable. But EnterCriticalSection() et al don't work (they merely increment the LockCount and RecursionCount without blocking), and the CreateMutex()/WaitForSingleObject() method seems to suffer from the same problem.
I think the problem is down to each successive SetTimer() event being seen as being in the same thread.
Anybody been here before? Any suggestions gratefully received!
|
|
|
|
|
EnterCriticalSection(...) is working correctly in this case - if the same thread tries to enter the same CS, it just increments the counters.
I think that using the static variable may be the easiest way to make this kind of issue work, short of not throwing up a blocking interface. There is no need to take something simple that works and make it unnecessarily complex.
If the number of times the message would have been shown is significant, I would suggest having a custom dialog where you can update a message or counter indicating multiple messages (like: "this message has occurred xxx times").
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Just a thought:
1.
Stop the timer in the callback function.
2.
Display the message.
3.
(Re)start the timer.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Considering that the OP wrote:
Dependent on circumstances, MyTimerProc() may need to ask for user intervention [...] - It sounds like the timer function is doing something other than showing a message box. Because of that, stopping the time may not be such a good idea...
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Then, just stop the timer when the messagebox has to be shown. The timer proc (I assume) will have to wait for a response anyway.
Else, another way could be to let the timer proc start a thread that shows the messagebox. That way, the thread can keep on working, and the thread is responsible for getting input from the message box.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Killing, then re-enabling the timer looks to be the way forward. A little annoyed I didn't think of it myself!
Thanks for the input everyone!
|
|
|
|
|
I'm glad to be able to help you out.
And sometimes, the simplest answers are the hardest to find.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Show a Dialog instead of message box and kill the timer.
Then notify the parent class to start the timer, when the dialog is about to destroy.
Do your Duty and Don't expect the Result
|
|
|
|
|
Not sure why your post had a score of 3, you gave the same advice that I'd give. Kill the timer in MyTimerProc() and then re-set it after the UI is dismissed.
|
|
|
|
|
Michael Dunn wrote: Not sure why your post had a score
Michael Dunn wrote: you gave the same advice that I'd give
Sorry, is it You or Kakan? Only 2 Min difference, seems i didn't refresh my page before i hit the reply link...
Do your Duty and Don't expect the Result
Rate this Post, if I helped You
|
|
|
|
|
There's nothing wrong with your code. Using a critical section is pointless since you've only got one thread. Same goes for the other synchronisation primitives.
Steve
|
|
|
|
|
Hello Comunity,
is there any function to determine is it a folder or file, e.g.
C:\folder\file.txt <-- path to file
C:\folder\files\ <-- path to folder
C:\folder\files <-- path to folder
thanks in advance
regards
break
|
|
|
|
|
|
Hello Prasad,
thanks for answer!
regards
break;
-- modified at 7:30 Thursday 22nd March, 2007
|
|
|
|
|
break; wrote: thanks for quick answer!
So why do you delay in polling a quick vote for him?
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
When all of the dust settles, does it even matter when, or even if, he votes?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Not really that it matters, but IMO they should be thankful when they get help, but they don't do..
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
Last time I checked, "thanks for answer" was being thankful. That in itself is all that's necessary to express thanks. Voting is nothing but extra.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Here's a Win95 compatible way of doing it:
DWORD dwAttrib = GetFileAttributes(psPath);
if(0xFFFFFFFF == dwAttrib)
dwAttrib = 0;
if(0 != (dwAttrib&FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
|
Hello,
thank you for help
regards
termal
|
|
|
|
|
Hi all,
I am writing one win32 Application using VC++.NET 2003. I am getting one wired error in my thread proc. I am creating one thread using CreateThread() function.
this->m_threadHwnd = CreateThread(NULL, 0, ThreadFunc, this, 0, NULL);
But when I am using Sleep() function in this ThreadFunc() it gives me error like “There is no source code available for the current location” . Sleep() function is working fine with other methods but not with ThreadFunc(). Can I know hoe can I solve this problem?
Thanks in advance,
Priyank
|
|
|
|
|
priyank_ldce wrote: “There is no source code available for the current location”.
Possibly, you are trying to step in to Sleep API while debugging, isn't it ?
|
|
|
|
|
Perhaps a little bit off topic, but it may solve your problem anyway...
The call to ::Sleep() should probably be removed.
When mentioning a sleep operation together with multithreading, chances are that the multithreading concept is not quite understood. Even the use of ::Sleep() is a warning sign itself.
Read about why ::Sleep() should be avoided here[^].
Read about how multithreading should be done here[^].
I humbly advise you to read the articles since they will prevent you from doing common mistakes that you will have a hard time tracking down later.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Excellent source material – I’ll try to remember it.
(You are forgive! for the VB phase)
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|