mike_marquet
asked on
Wait cursor problem !
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'.
// First method
void CMyDialogBox::OnStart()
{
((CMyApp *)AfxGetApp())->DoWaitCurs or(1);
}
void CMyDialogBox::OnStop()
{
((CMyApp *)AfxGetApp())->DoWaitCurs or(-1);
}
// Second method
CCmdTarget g_CmdTarget;
void CMyDialogBox::OnStart()
{
g_CmdTarget.BeginWaitCurso r();
}
void CMyDialogBox::OnStop()
{
g_CmdTarget.EndWaitCursor( );
}
It doesn't work when application is a dialog box ! Why ?
But it works when the sample is an SDI or MDI application.
Can someone help me !
Thanks,
Mike.
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'.
// First method
void CMyDialogBox::OnStart()
{
((CMyApp *)AfxGetApp())->DoWaitCurs
}
void CMyDialogBox::OnStop()
{
((CMyApp *)AfxGetApp())->DoWaitCurs
}
// Second method
CCmdTarget g_CmdTarget;
void CMyDialogBox::OnStart()
{
g_CmdTarget.BeginWaitCurso
}
void CMyDialogBox::OnStop()
{
g_CmdTarget.EndWaitCursor(
}
It doesn't work when application is a dialog box ! Why ?
But it works when the sample is an SDI or MDI application.
Can someone help me !
Thanks,
Mike.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
One thing I can See:
you are using WM_USER! The MFC uses some WM_USER Messages therfore never use WM_USER it is better to use
WM_USER+10
BTW You have Accepted the answer normaly it is better to reject an Answer if it does not fullfill your requirements so other experts can answer also now this question is inside the answered question section an most experts will not look there to answer someting
you are using WM_USER! The MFC uses some WM_USER Messages therfore never use WM_USER it is better to use
WM_USER+10
BTW You have Accepted the answer normaly it is better to reject an Answer if it does not fullfill your requirements so other experts can answer also now this question is inside the answered question section an most experts will not look there to answer someting
ASKER
Thanks
does it work now ?
ASKER
the mistake !
// **************************
// **************************
// WaitCursorTester.h : main header file for the WAITCURSORTESTER application
//
#if !defined(AFX_WAITCURSORTES
#define AFX_WAITCURSORTESTER_H__B9
#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(CWaitCurso
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
//{{AFX_MSG(CWaitCursorTes
//}}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_WAITCURSORTES
// **************************
// **************************
// 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(CWaitCur
//{{AFX_MSG_MAP(CWaitCurso
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
ON_THREAD_MESSAGE(WM_USER,
END_MESSAGE_MAP()
//////////////////////////
// CWaitCursorTesterApp construction
CWaitCursorTesterApp::CWai
{
}
//////////////////////////
// The one and only CWaitCursorTesterApp object
CWaitCursorTesterApp theApp;
//////////////////////////
// CWaitCursorTesterApp initialization
BOOL CWaitCursorTesterApp::Init
{
#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::OnUs
{
if (State) BeginWaitCursor();
else EndWaitCursor();
}
// **************************
// **************************
// WaitCursorTesterDlg.h : header file
//
#if !defined(AFX_WAITCURSORTES
#define AFX_WAITCURSORTESTERDLG_H_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
//////////////////////////
// CWaitCursorTesterDlg dialog
class CWaitCursorTesterDlg : public CDialog
{
public :
CWaitCursorTesterDlg(CWnd*
protected :
HICON m_hIcon;
public :
//{{AFX_DATA(CWaitCursorTe
enum { IDD = IDD_WAITCURSORTESTER_DIALO
//}}AFX_DATA
protected :
//{{AFX_VIRTUAL(CWaitCurso
protected:
virtual void DoDataExchange(CDataExchan
//}}AFX_VIRTUAL
//{{AFX_MSG(CWaitCursorTes
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_WAITCURSORTES
// **************************
// **************************
// 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::CWai
{
//{{AFX_DATA_INIT(CWaitCur
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_
}
// --------------------------
void CWaitCursorTesterDlg::DoDa
{
CDialog::DoDataExchange(pD
//{{AFX_DATA_MAP(CWaitCurs
//}}AFX_DATA_MAP
}
// --------------------------
BEGIN_MESSAGE_MAP(CWaitCur
//{{AFX_MSG_MAP(CWaitCurso
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::OnIn
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
return TRUE;
}
// --------------------------
void CWaitCursorTesterDlg::OnPa
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBK
// 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::OnQu
{
return (HCURSOR) m_hIcon;
}
// --------------------------
void CWaitCursorTesterDlg::OnPB
{
//((CWaitCursorTesterApp *)AfxGetApp())->PostThread
BeginWaitCursor();
}
// --------------------------
void CWaitCursorTesterDlg::OnPB
{
//((CWaitCursorTesterApp *)AfxGetApp())->PostThread
EndWaitCursor();
}
// **************************
// **************************