CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    May 2006
    Posts
    41

    Question 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 :

    Code:
    CWaitCursor wait;
    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

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    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.

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: CWaitCursor issue

    Try BeginWaitCursor () and EndWaitCursor ().

  4. #4
    Join Date
    May 2006
    Posts
    41

    Re: CWaitCursor issue

    Quote 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.

  5. #5
    Join Date
    May 2006
    Posts
    41

    Re: CWaitCursor issue

    Quote 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).

  6. #6
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    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.

  7. #7
    Join Date
    Mar 2001
    Posts
    2,529

    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.

  8. #8
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: CWaitCursor issue

    You also can try the SetClassLong function with the GCL_HCURSOR flag.

    Code:
    SetClassLong (m_someWindowHandle, GCL_HCURSOR, m_someCursorHandle);

  9. #9
    Join Date
    May 2006
    Posts
    41

    Re: CWaitCursor issue

    Quote 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...

  10. #10
    Join Date
    Mar 2001
    Posts
    2,529

    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.

  11. #11
    Join Date
    May 2006
    Posts
    41

    Re: CWaitCursor issue

    Quote 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.

  12. #12
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    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.

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: CWaitCursor issue

    Quote 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

  14. #14
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    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?

  15. #15
    Join Date
    May 2006
    Posts
    41

    Re: CWaitCursor issue

    Quote 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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured