|
a_du wrote:
dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles,
FALSE, INFINITE);
Actaully this is BLOCKING CALL,this will block all Message Coming to your Dialog Box.
Only Solution to above problem is to create multithread Program!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Thanx alot. I have solved that problem by using multithread.
BTW, can some one tell me the differences between these two functions and whether it is possible to retrieve file name informations from the FindFirstChangeNotification approach.
|
|
|
|
|
a_du wrote:
it is possible to retrieve file name informations from the FindFirstChangeNotification approach.
Nope, It not Possible to Retrieve File Information using FindFirstChangeNotification approach!, only ReadDirectoryChangeW will help in this regard!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
As Alok said, you're blocking the UI thread and waiting for directory changes. You need to move that code to a separate worker thread and inform the UI when you get modifications.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote:
and inform the UI when you get modifications.
Oops, I forget to mention that, Thanks for correcting me!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hello!
Here's my situation. I have a dialog with a CEdit-derived object and CListCtrl-derived object. When someone is typing in the edit control and they hit Enter, I want the text to be copied to the CListCtrl.
The CDialog class that contains these controls has a method that gets the text from the edit control and inserts it into the CListCtrl.
My problem is trapping the Enter key in the edit box and getting the dialog to call it's method that copies from the edit box to the list control.
I think I'm going about this all wrong. What I'm currently trying to do in the CEdit-derived class is this:
void CMyEdit::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// If Enter has been pressed, we need to post this message to the dialog.
if(nChar == 13)
{
// Get a handle to our dialog window
CWnd* pDialogWnd = GetParent();
// Post the message to our dialog window
pDialogWnd->PostMessage(WM_KEYUP, VK_RETURN, 0);
}
CEdit::OnKeyUp(nChar, nRepCnt, nFlags);
}
I implement the WM_KEYUP message in the parent dialog class as follows:
void CMyDlg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// If Enter has been pressed, we need to update the rules list
if(nChar == 13)
{
UpdateRulesList();
}
CDialog::OnKeyUp(nChar, nRepCnt, nFlags);
}
But I end up hanging somewhere after my UpdateRulesList method executes (the problem is not in UpdateRulesList (at least I can call it from the dialog object and it works just fine)). I must be generating some kind of endless message loop or something...
Any help would be greatly appreciated!
Thanks!
-Ian
|
|
|
|
|
Ian Bowler wrote:
I must be generating some kind of endless message loop or something...
Does this mean you've put a breakpoint in to see if this is the case ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I put a break point where my dialog class calls the UpdateRegRules method. I step through that method and everything seems copacetic. If I hit f5, I seem to hang.
I'm totally guessing on the endless looping. I'm actually stumped. I've never used PostMessage before and I'd be willing to bet that that's the root of the problem...
|
|
|
|
|
If you hit F5 and you're creating an endless message loop, you should find yourself hitting the same spot over and over. You can also override PreTranslateMessage to see if this is in fact occuring.
The difference between SendMessage and PostMessage is just that PostMessage sends the message when the current function ends, SendMessage does it right away.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Not really, PostMessage posts the message to the message queue and returns immediately, SendMessage sends the message to the message pump and waits till it gets processed.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Try out with SendMessage instead of PostMessage
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
You guys ROCK! Thanks so much! SendMessage fixed the problem. I don't think I understand why sending the message right away fixed the problem though. Some crazy timing thing?
I actually thought the difference was that PostMessage added the message to the message queue and SendMessage bypassed the queue (at least that's how someone else explained it to me).
Thanks again, to both of you for your excellent help!
-Ian
|
|
|
|
|
Well you are right about the difference between SendMessage and PostMessage but there is one more thing to be noted that PostMessage as it goes in queue is a blocking call, but it is not the case with SendMessage
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
You've been so helpful I hesitate to ask another question...
What is a blocking call?
|
|
|
|
|
<code>
void function1()
{
PostMessage();
//this message box would get displayed only when the lengthy operation of
//ReceiverOfPostMessage function gets over, This is called a blocking call
AfxMessageBox("");
SendMessage();
//this message box would immediately get displayed and would not wait for the
//operation of ReceiverOfPostMessage to get over
AfxMessageBox("");
}
void ReceiverOfPostMessage()
{
//execute a lengthy operation
}
</code>
Hope that's clear
<br></br>
<bold>- Nilesh</bold>
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
</italics>
|
|
|
|
|
Ahhh. I didn't realize you were talking about synchronous VS asynchronous. You explained it perfectly.
Thanks again for all your help! I hope I get the chance to return the favor someday...
-Ian
|
|
|
|
|
Thanks
Glad to be of help
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Nilesh K. wrote:
PostMessage();
//this message box would get displayed only when the lengthy operation of
//ReceiverOfPostMessage function gets over, This is called a blocking call
AfxMessageBox("");
SendMessage();
//this message box would immediately get displayed and would not wait for the
//operation of ReceiverOfPostMessage to get over
AfxMessageBox("");
Are you jokin!, have you consulted MSDN before writing difference between PostMessage and SendMessage Here! or try to run above code in your compiler!
The Defination is actually reverse!, SendMesssage Block the call and PostMessage Return immedietly.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Your are right, thanks for correcting!!
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Nilesh K. wrote:
Your are right, thanks for correcting!!
Sorry for my RUDE Comments!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
It's SendMessage that's blocking, PostMessage returns immediately after posting a message to the message queue. There's more to it, though, take a look at this article (www.codeproject.com/csharp/begininvoke.asp[^]), in particular the "message queues and message pumping" section.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
My guess is that posting the messages is causing the message pump to process it again. That causes CMyEdit::onkeyup to execute again which again posts a message to the message pump and so on.
SendMessage from within the UI thread directly calls the WndProc of the dialog and so it executes correctly.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I have a program that has many windows that need to be displayed. I am using MFC for the windows. I need to be able to dynamically update the windows from within the program. But I would like them to be displayed in a tab/dockable window fashion. However I can't figure out when you create the window as a property sheet of CFormView how to get access to the object that is created because they have to be created as CRuntimeClass.
Currently for example I just have a bunch of modeless dialog boxes that I instantiate directly and have objects for that I can just call set routines to manipulate the display. I would like to to the same thing just without using modeless dialogs, but CFormview or something similar.
|
|
|
|
|
When I click on the application window's Close X button, it calls my OnClose method. In OnClose, I prompt the user to save the data before closing the application. If the user cancels, I would like the application to remain open as in Microsoft Word, Excel, etc. How do I go about doing this? Thanks.
|
|
|
|
|
don't call the base method, and if the function returns a boolean, return true ( which tells the system you've handled the message, no further processing required ).
Christian Graus - Microsoft MVP - C++
|
|
|
|