Unresposive mouse to a win32 application
-
Friday, April 20, 2012 4:03 AM
Hi,
I developed a simple window application on win32. The application includes buttons for executing certain commands. The problem with this application is the great delay to mouse actions. Specifically, when the application starts, the mouse cursor takes the hourglass shape for almost 25 seconds to become a pointer shape. Only after it becomes a pointer shape I can press on the command buttons. Also if I try drag the window (by pressing on the title bar) by the mouse it responds only after few seconds.
I have tried all these 3 cases:
WndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
WndCls.hCursor = LoadCursor(hInstance, IDC_ARROW);
WndCls.hCursor = NULL;
all the same response. Is there any clue to the cause of this behaviour and how to fix it?. Thanks.
Esmat
All Replies
-
Friday, April 20, 2012 4:11 AM
EsmatB wrote:
I developed a simple window application on win32. The application includes buttons for executing certain commands. The problem
with this application is the great delay to mouse actions. Specifically, when the application starts, the mouse cursor takes the
hourglass shape for almost 25 seconds to become a pointer shape.Your application performs some kind of long-running initialization on start-up. The hourglass cursor is set by the operating system, until the application gets to its message pump and starts processing window messages.
So, figure out what your app is doing during these 25 seconds, and find a way to avoid this delay. For example, you could perform this initialization in background, on a worker thread.
Igor Tandetnik
- Marked As Answer by Helen ZhaoModerator Friday, April 27, 2012 6:05 AM
- Unmarked As Answer by EsmatB Friday, April 27, 2012 1:09 PM
-
Tuesday, May 01, 2012 7:06 PM
After populating my code with break points and eleminating segments of code one at a time I found that eliminating this single statement
ReadFile( hComm , tmpMsg , 400 , &BytesRead , NULL );
causes the pointer (arrow) cursor to appear instantly and no showing of the hour glass. The ReadFile statement is the first statement of an inifinite loop in my application. Probably this is something I have to look into to understand the effect of the statement on the delay. However, even though, the window can be moved smoothly I find that pressing any of the buttons causes them to remain sunken. Any hint!!!Esmat
- Marked As Answer by EsmatB Tuesday, May 01, 2012 7:07 PM
-
Wednesday, May 02, 2012 1:26 PM
Is that statement reading from a serial port? It won't return until 400 bytes have been received, so that might be the reason for the delay. It can also be made to return after a timeout that you can set with SetCommTimeouts.
Serial port code is best moved into separate threads for reading and writing so such delays will not affect the GUI responsiveness.
-
Wednesday, May 02, 2012 7:23 PM
Scott, Thank you for your reply. Yes, the ReadFile statement is from a serial port and for which I set the Timeout parameters to:
TimeOut.ReadIntervalTimeout = 50;
TimeOut.ReadTotalTimeoutConstant = 50;
TimeOut.ReadTotalTimeoutMultiplier = 10;
TimeOut.WriteTotalTimeoutConstant = 50;
TimeOut.WriteTotalTimeoutMultiplier = 10;
As yet I am not familiar with moving the Serial port code into separate threads. However, when I preceded the ReadFile with:
if(counter<300000){// counter is initialized to 0
newFrame=0;
counter++;
}
else ReadFile(..);
it eliminated the delay.
Esmat

