|
-
November 12th, 2007, 07:33 AM
#1
CWaitCursor issue
Hi,
My application initialization takes some time and I'd like to display a wait cursor while it is being loaded. So I have tried to put the following line at the beginning of my overridden CWinApp::InitInstance() method :
This changes nothing, the cursor is still displayed as an arrow. It seems it has something to do with being in the InitInstance() because it works later in other parts of the program. Would you have an explanation and/or a workaround ?
Thanks
-
November 12th, 2007, 07:37 AM
#2
Re: CWaitCursor issue
Please Post the code for your CWaitCursor code. Not good at guessing games. Dont want to play 20 questions.
ahoodin
To keep the plot moving, that's why.

-
November 12th, 2007, 07:43 AM
#3
Re: CWaitCursor issue
Try BeginWaitCursor () and EndWaitCursor ().
-
November 12th, 2007, 07:50 AM
#4
Re: CWaitCursor issue
 Originally Posted by ahoodin
Please Post the code for your CWaitCursor code. Not good at guessing games. Dont want to play 20 questions.
OK here you go... with slight adaptations :
Code:
// overriding virtual BOOL CWinApp::InitInstance() called by AfxWinMain(...)
BOOL CMyWinApp::InitInstance()
{
CWaitCursor wait;
InitCommonControls();
CWinApp::InitInstance();
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
GdiplusStartup(&GdiPlusToken, &GdiPlusStartupInput, NULL);
// intialize application
if (!CUIServicesController::get_instance()->initializeApplication())
{
exit(EXIT_SUCCESS);
}
_appInit = TRUE;
SetRegistryKey(_T("MyApp"));
LoadStdProfileSettings(4);
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyWinAppDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CMyWinAppView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (!ProcessShellCommand(cmdInfo))
return FALSE;
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
return TRUE;
}
Last edited by tnarol; November 12th, 2007 at 07:55 AM.
-
November 12th, 2007, 07:52 AM
#5
Re: CWaitCursor issue
 Originally Posted by Skizmo
Try BeginWaitCursor () and EndWaitCursor ().
Already tried this and it doesn't work.
Also tried unsuccessfully SetCursor(LoadCursor(IDC_WAIT)) and AfxGetApp->DoWaitCursor(1).
-
November 12th, 2007, 08:53 AM
#6
Re: CWaitCursor issue
Keep in mind, in order to use the SetCursor function, you need to handle the WM_SETCURSOR message.
Also I think somethings wrong with your LoadCursor function but, this morning I don't have access to the IDE so I can't double check that.
-
November 12th, 2007, 09:04 AM
#7
Re: CWaitCursor issue
Sounds like you have a slow down in your code. The wait cursor only pops up when you want it.
I think that you should time sections of your code....time it.
eg:
Code:
int ntime=0;
LARGE_INTEGER ntime1,ntime2;
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);//initialize at app start
QueryPerformanceCounter(&ntime1);//at start of code to check
//...code to profile in here
dosomefunction();
QueryPerformanceCounter(&ntime2);//at end of code to check
//get ntime in microseconds
ntime = (ntime2.QuadPart-ntime1.QuadPart)/(freq.QuadPart/1000000);
HTH,
ahoodin
To keep the plot moving, that's why.

-
November 12th, 2007, 09:06 AM
#8
Re: CWaitCursor issue
You also can try the SetClassLong function with the GCL_HCURSOR flag.
Code:
SetClassLong (m_someWindowHandle, GCL_HCURSOR, m_someCursorHandle);
-
November 12th, 2007, 10:02 AM
#9
Re: CWaitCursor issue
 Originally Posted by ahoodin
I think that you should time sections of your code....time it.
No I don't have slow downs... It's juste that the following call actually does a lot of things :
Code:
if (!CUIServicesController::get_instance()->initializeApplication())
{
exit(EXIT_SUCCESS);
}
It's perfectly normal that it takes a few seconds...
-
November 12th, 2007, 10:37 AM
#10
Re: CWaitCursor issue
Well I found that when you move your cursor over certain UI elements it is an arrow and hourglass. Othertimes it is just an arrow or vertical flatline.
FWIW.
ahoodin
To keep the plot moving, that's why.

-
November 12th, 2007, 10:39 AM
#11
Re: CWaitCursor issue
 Originally Posted by Skizmo
You also can try the SetClassLong function with the GCL_HCURSOR flag.
Code:
SetClassLong (m_someWindowHandle, GCL_HCURSOR, m_someCursorHandle);
I think this method is meant to display a particular cursor when the mouse is on a particular window. In this case I don't have any window ready when calling the initialization method that requires a cursor change.
-
November 12th, 2007, 11:30 AM
#12
Re: CWaitCursor issue
CWaitCursor class used to be helpful in 16-bit application to indicate something was going on, for long loops when application appeared to be frozen. That was before multithreading when local message loop was not used.
See following threads for discussions regarding CWaitCursor:
http://www.codeguru.com/forum/showthread.php?t=193132
http://www.codeguru.com/forum/showthread.php?t=198925
http://www.codeguru.com/forum/showthread.php?t=334368
http://www.codeguru.com/forum/showthread.php?t=318350
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
November 12th, 2007, 11:44 AM
#13
Re: CWaitCursor issue
 Originally Posted by tnarol
OK here you go... with slight adaptations :
Code:
// intialize application
if (!CUIServicesController::get_instance()->initializeApplication())
{
exit(EXIT_SUCCESS);
}
Note, that you must not use exit in the MFC application.
If you want to exit from within InitInstance - just return false.
If you want to return the exit code - override the CApp::ExitInstance and return the code you want to.
Victor Nijegorodov
-
November 12th, 2007, 12:17 PM
#14
Re: CWaitCursor issue
If you still can't get any of those to work, why don't you launch a window, with a progress bar and a wait cursor?
-
November 13th, 2007, 05:11 AM
#15
Re: CWaitCursor issue
 Originally Posted by bderagon
If you still can't get any of those to work, why don't you launch a window, with a progress bar and a wait cursor?
I think that's what I'm gonna do eventually.
I also tried this unsuccessfully :
Code:
BOOL cursorChange = FALSE;
HCURSOR waitCursor = LoadCursor(32514);
HCURSOR waitCursorCopy = CopyCursor(waitCursor);
cursorChange = SetSystemCursor(waitCursorCopy, 32512);
//
// ... long processing
//
cursorChange = SetSystemCursor(CopyCursor(LoadCursor(IDC_ARROW)), 32512);
The problem seems to be that a cursor change has to be processed by the message loop of a window. In this case I don't have any window ready at the time I want to change the cursor... I could see the cursor change briefly, but only after leavine the InitInstance() method.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|