Application freeze
-
Hallo, i have the following function in SDI-application: void CMyClass::Myfunction() { CString strOutput; LPMSG *pmsg = NULL; for(int i = 0; i < 3000; i++) { ::PeekMessage(NULL,NULL,0,0,PM_NOYIELD | PM_REMOVE); strOutput.Format ("%d",i); m_ptrOutput->SetWindowTextA (strOutput); } } as you see the for-loop goes 3000 times and should print the value of i, what happens when this function starts is the appliction FREEZ. I do not have any idea why this happens and how to solve this problem.Please help.
-
Hallo, i have the following function in SDI-application: void CMyClass::Myfunction() { CString strOutput; LPMSG *pmsg = NULL; for(int i = 0; i < 3000; i++) { ::PeekMessage(NULL,NULL,0,0,PM_NOYIELD | PM_REMOVE); strOutput.Format ("%d",i); m_ptrOutput->SetWindowTextA (strOutput); } } as you see the for-loop goes 3000 times and should print the value of i, what happens when this function starts is the appliction FREEZ. I do not have any idea why this happens and how to solve this problem.Please help.
What is that magic number 3000? Why do you want to loop 3000 times?
«_Superman_» I love work. It gives me something to do between weekends.
-
What is that magic number 3000? Why do you want to loop 3000 times?
«_Superman_» I love work. It gives me something to do between weekends.
-
Hallo, i have the following function in SDI-application: void CMyClass::Myfunction() { CString strOutput; LPMSG *pmsg = NULL; for(int i = 0; i < 3000; i++) { ::PeekMessage(NULL,NULL,0,0,PM_NOYIELD | PM_REMOVE); strOutput.Format ("%d",i); m_ptrOutput->SetWindowTextA (strOutput); } } as you see the for-loop goes 3000 times and should print the value of i, what happens when this function starts is the appliction FREEZ. I do not have any idea why this happens and how to solve this problem.Please help.
susanne1 wrote:
LPMSG *pmsg = NULL;
What is the purpose of this pointer variable? You aren't using it anywhere in your code. Not to mention
LPMSG
is already a pointer to aMSG
structure. :|void Func()
{
CString szOutput;
MSG msg;for(int i=0; i<3000; i++)
{
PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); //You must use PM_NOREMOVE if you want the message to remain in the queue.
szOutput.Format(_T("%d"), i);
OutputDebugString(szOutput);
}Why would you do something like this? Are you trying to understand how
PeekMessage
works or ... ?It is a crappy thing, but it's life -^ Carlo Pallini
-
susanne1 wrote:
LPMSG *pmsg = NULL;
What is the purpose of this pointer variable? You aren't using it anywhere in your code. Not to mention
LPMSG
is already a pointer to aMSG
structure. :|void Func()
{
CString szOutput;
MSG msg;for(int i=0; i<3000; i++)
{
PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); //You must use PM_NOREMOVE if you want the message to remain in the queue.
szOutput.Format(_T("%d"), i);
OutputDebugString(szOutput);
}Why would you do something like this? Are you trying to understand how
PeekMessage
works or ... ?It is a crappy thing, but it's life -^ Carlo Pallini
i must do it because i have over 40000 rows in the database(wher can i find a tutorial that explain how peekmessgae works??) do not i need to intialize the msg before i use it? i used the PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);in the loop that retrives the rows but nothing changed positively??
-
i must do it because i have over 40000 rows in the database(wher can i find a tutorial that explain how peekmessgae works??) do not i need to intialize the msg before i use it? i used the PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);in the loop that retrives the rows but nothing changed positively??
-
-
You cannot solve this problem until you understand the basics. If I start to tell why you should not use PeekMessage there, I'll have to explain what a worker thread is, thread synchronization, applying everything together in your program, etc., Too much of stuff to be discussed in a thread like this. You are desperately in need of a book and go buy one or two. Your program can wait until you're good enough to solve it. And no pal, I do not feel like providing you a quick-fix. Sorry about that.
It is a crappy thing, but it's life -^ Carlo Pallini
-
Hallo, i have the following function in SDI-application: void CMyClass::Myfunction() { CString strOutput; LPMSG *pmsg = NULL; for(int i = 0; i < 3000; i++) { ::PeekMessage(NULL,NULL,0,0,PM_NOYIELD | PM_REMOVE); strOutput.Format ("%d",i); m_ptrOutput->SetWindowTextA (strOutput); } } as you see the for-loop goes 3000 times and should print the value of i, what happens when this function starts is the appliction FREEZ. I do not have any idea why this happens and how to solve this problem.Please help.
You should sometimes (e.g. after reading of 100 data) call a function like this. If you remove the message from the queue, you should dispatch the message. You can call PeekMessage with other filters too (e.g. for a special window or other messages). But the last call should not use any filters! void PeekMessages() { MSG msg; // check for paint-messages ... while ( PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) ) { // ... and dispatch these TranslateMessage(&msg); DispatchMessage(&msg); } // only to prevent ghost-window on vista! // we dont use the result and let the message // in the queue (PM_NOREMOVE) PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); }