?
Solved

Problem displaying the wait cursor in a dialog box

Posted on 1998-07-14
5
Medium Priority
?
708 Views
Last Modified: 2013-11-20
I have written a sample appliction dialog box which
has 2 buttons (Start and Stop wait cursor). The first
button display the wait cursor and the second stop it.
I have tested it with 'DoWaitCursor' and with 'CCmdTarget'.
It doesn't work when application is a dialog box ! Why ?
But it works when the sample is an SDI or MDI application.

Here's the sample application I have written to test this :

// *************************************************************
// *************************************************************
// WaitCursorTester.h : main header file for the WAITCURSORTESTER application
//

#if !defined(AFX_WAITCURSORTESTER_H__B93D9CC4_1A59_11D2_92DA_99548D96D21C__INCLUDED_)
#define AFX_WAITCURSORTESTER_H__B93D9CC4_1A59_11D2_92DA_99548D96D21C__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // main symbols

/////////////////////////////////////////////////////////////////////////////
// CWaitCursorTesterApp:
// See WaitCursorTester.cpp for the implementation of this class
//

class CWaitCursorTesterApp : public CWinApp
 {
  public :
           CWaitCursorTesterApp();

  public :
//{{AFX_VIRTUAL(CWaitCursorTesterApp)
virtual BOOL InitInstance();
//}}AFX_VIRTUAL

//{{AFX_MSG(CWaitCursorTesterApp)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
    afx_msg void OnUserMessage(UINT, LONG);
 };

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_WAITCURSORTESTER_H__B93D9CC4_1A59_11D2_92DA_99548D96D21C__INCLUDED_)

// *************************************************************
// *************************************************************

// WaitCursorTester.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "WaitCursorTester.h"
#include "WaitCursorTesterDlg.h"
#include "Defines.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWaitCursorTesterApp

BEGIN_MESSAGE_MAP(CWaitCursorTesterApp, CWinApp)
//{{AFX_MSG_MAP(CWaitCursorTesterApp)
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
    ON_THREAD_MESSAGE(WM_USER + 100, OnWaitCursor)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWaitCursorTesterApp construction

CWaitCursorTesterApp::CWaitCursorTesterApp()
 {
 }

/////////////////////////////////////////////////////////////////////////////
// The one and only CWaitCursorTesterApp object

CWaitCursorTesterApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CWaitCursorTesterApp initialization

BOOL CWaitCursorTesterApp::InitInstance()
 {
  #ifdef _AFXDLL
  Enable3dControls(); // Call this when using MFC in a shared DLL
  #else
  Enable3dControlsStatic(); // Call this when linking to MFC statically
  #endif

  CWaitCursorTesterDlg dlg;
  m_pMainWnd = &dlg;
  dlg.DoModal();

  return FALSE;
 }

// ---------------------------------------------------------------------------

void CWaitCursorTesterApp::OnUserMessage(UINT State, LONG)
 {
  if (State) BeginWaitCursor();
  else EndWaitCursor();
 }

// *************************************************************
// *************************************************************

// WaitCursorTesterDlg.h : header file
//

#if !defined(AFX_WAITCURSORTESTERDLG_H__B93D9CC6_1A59_11D2_92DA_99548D96D21C__INCLUDED_)
#define AFX_WAITCURSORTESTERDLG_H__B93D9CC6_1A59_11D2_92DA_99548D96D21C__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

/////////////////////////////////////////////////////////////////////////////
// CWaitCursorTesterDlg dialog

class CWaitCursorTesterDlg : public CDialog
 {
  public :
           CWaitCursorTesterDlg(CWnd* pParent = NULL);

  protected :
              HICON m_hIcon;

  public :
//{{AFX_DATA(CWaitCursorTesterDlg)
enum { IDD = IDD_WAITCURSORTESTER_DIALOG };
//}}AFX_DATA

  protected :
//{{AFX_VIRTUAL(CWaitCursorTesterDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

//{{AFX_MSG(CWaitCursorTesterDlg)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnPB_Start();
afx_msg void OnPB_Stop();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
 };

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_WAITCURSORTESTERDLG_H__B93D9CC6_1A59_11D2_92DA_99548D96D21C__INCLUDED_)

// *************************************************************
// *************************************************************

// WaitCursorTesterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "WaitCursorTester.h"
#include "WaitCursorTesterDlg.h"
#include "Defines.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWaitCursorTesterDlg dialog

CWaitCursorTesterDlg::CWaitCursorTesterDlg(CWnd* pParent) : CDialog(CWaitCursorTesterDlg::IDD, pParent)
 {
//{{AFX_DATA_INIT(CWaitCursorTesterDlg)
//}}AFX_DATA_INIT
  m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
 }

// ---------------------------------------------------------------------------

void CWaitCursorTesterDlg::DoDataExchange(CDataExchange* pDX)
 {
  CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWaitCursorTesterDlg)
//}}AFX_DATA_MAP
 }

// ---------------------------------------------------------------------------

BEGIN_MESSAGE_MAP(CWaitCursorTesterDlg, CDialog)
//{{AFX_MSG_MAP(CWaitCursorTesterDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDPB_START, OnPB_Start)
ON_BN_CLICKED(IDPB_STOP, OnPB_Stop)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWaitCursorTesterDlg message handlers

BOOL CWaitCursorTesterDlg::OnInitDialog()
 {
  CDialog::OnInitDialog();

  SetIcon(m_hIcon, TRUE); // Set big icon
  SetIcon(m_hIcon, FALSE); // Set small icon

  return TRUE;
 }

// ---------------------------------------------------------------------------

void CWaitCursorTesterDlg::OnPaint()
 {
  if (IsIconic())
   {
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
   }
  else CDialog::OnPaint();
 }

// ---------------------------------------------------------------------------

HCURSOR CWaitCursorTesterDlg::OnQueryDragIcon()
 {
  return (HCURSOR) m_hIcon;
 }

// ---------------------------------------------------------------------------

void CWaitCursorTesterDlg::OnPB_Start()
 {
  //((CWaitCursorTesterApp *)AfxGetApp())->PostThreadMessage(WM_USER + 100,1L,0L);
  BeginWaitCursor();
 }

// ---------------------------------------------------------------------------

void CWaitCursorTesterDlg::OnPB_Stop()
 {
  //((CWaitCursorTesterApp *)AfxGetApp())->PostThreadMessage(WM_USER + 100,0L,0L);
  EndWaitCursor();
 }

// *************************************************************
// *************************************************************

Can someone help me !
Thanks,
Mike.

0
Comment
Question by:mike_marquet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 3

Expert Comment

by:Norbert
ID: 1319106
Hi again,
I have build a program from the scratch to have a look to your problem
To see the cursor you can add a wait loop like
void CWaitCursorTesterDlg::OnStart()
{
//((CWaitCursorTesterApp *)AfxGetApp())->PostThreadMessage(WM_USER + 100,1L,0L);
      BeginWaitCursor();       
      unsigned long i;
      for (i=0;i<0x1000000;i++);//wait a little bit
      //on 100 Mhz Pentium PC this is enough to see the waitcursor
      MessageBeep(0xffffffff);  //to hear when loop has finished
}
but when the loop has finished the cursor disapeares
I am still Working....
0
 
LVL 3

Accepted Solution

by:
Norbert earned 40 total points
ID: 1319107
Now a real working solution:
It seems tha DoWaitCursor and BeginWaitCursor automatically are Ended if the program goes into IDLE mode
 but this works always:
void CWaitCursorTesterDlg::OnStart()
{
      m_ShowWaitCursor=TRUE;
}

void CWaitCursorTesterDlg::OnStop()
{
      m_ShowWaitCursor=FALSE;
}

BOOL CWaitCursorTesterDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
      if(m_ShowWaitCursor)
      {
            SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
            return TRUE;
      }
      return CDialog::OnSetCursor(pWnd, nHitTest, message);
}

0
 

Author Comment

by:mike_marquet
ID: 1319108
Thanks for your answer
It works very fine !
0
 
LVL 3

Expert Comment

by:Norbert
ID: 1319109
Glad to hear that the second try works.
What about Graduation? ;-)
0
 
LVL 3

Expert Comment

by:Norbert
ID: 1319110
Mike, nothing heared from you
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question