我的程序在开始时需要做一些耗时的初始化工作,所以加入了启动窗口,并在启动窗口里加了个进度条,使用定时器,每500毫秒执行一次StepIt,但程序运行时进度条却不工作,不触发定时器,后又分别尝试单独用一个线程执行StepIt或单独用一个线程进行初始化,都达不到效果,不知是怎么回事,请各位大侠帮忙看看.部分代码如下:
/* 启动窗口部分, 是VC自带的那个启动窗口,稍加了改动 */
void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
{
c_bShowSplashWnd = bEnable;
}void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
{
if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
return; // Allocate a new splash screen, and create the window.
c_pSplashWnd = new CSplashWnd;
if (!c_pSplashWnd->Create(pParentWnd))
delete c_pSplashWnd;
else
c_pSplashWnd->UpdateWindow();
}BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
{
if (c_pSplashWnd == NULL)
return FALSE; // If we get a keyboard or mouse message, hide the splash screen.
if (pMsg->message == WM_CLOSE )
{
c_pSplashWnd->HideSplashScreen();
return TRUE; // message handled here
} return FALSE; // message not handled
}
void CSplashWnd::HideSplashScreen()
{
// Destroy the window, and update the mainframe.
delete m_pctlProgress;
DestroyWindow();
}
/* 在启动窗口建立后,建立进度条控件 */
int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1; // Center the window.
CenterWindow(); m_pctlProgress = new CProgressCtrl;
// 建立进度条
m_pctlProgress->Create( WS_CHILD|WS_VISIBLE|PBS_SMOOTH,
CRect(5,165,305,170), this,
IDC_PROGRESS );
m_pctlProgress->SetRange( 0, 300 );
m_pctlProgress->SetStep( 300 );
//设置定时器
SetTimer( ID_TIMER, 500, NULL ); return 0;
}
/* 响应定时 */
void CSplashWnd::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default m_pctlProgress->StepIt();
}/* 主程序 */
BOOL CSmart114DlgApp::InitInstance()
{ /* 建立并显示启动窗口 */
CSplashWnd::EnableSplashScreen();
CSplashWnd::ShowSplashScreen(); /* 建立主对话框 */
CSmart114DlgDlg dlg;
m_pMainWnd = &dlg; /* 一些耗时的初始化工作 */
InitSysterm(); /* 关闭启动窗口 */
MSG msg;
msg.message = WM_CLOSE;
CSplashWnd::PreTranslateAppMessage( &msg ); /* 显示主对话框 */
int nResponse = dlg.DoModal();
return FALSE;
}
/* 启动窗口部分, 是VC自带的那个启动窗口,稍加了改动 */
void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
{
c_bShowSplashWnd = bEnable;
}void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
{
if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
return; // Allocate a new splash screen, and create the window.
c_pSplashWnd = new CSplashWnd;
if (!c_pSplashWnd->Create(pParentWnd))
delete c_pSplashWnd;
else
c_pSplashWnd->UpdateWindow();
}BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
{
if (c_pSplashWnd == NULL)
return FALSE; // If we get a keyboard or mouse message, hide the splash screen.
if (pMsg->message == WM_CLOSE )
{
c_pSplashWnd->HideSplashScreen();
return TRUE; // message handled here
} return FALSE; // message not handled
}
void CSplashWnd::HideSplashScreen()
{
// Destroy the window, and update the mainframe.
delete m_pctlProgress;
DestroyWindow();
}
/* 在启动窗口建立后,建立进度条控件 */
int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1; // Center the window.
CenterWindow(); m_pctlProgress = new CProgressCtrl;
// 建立进度条
m_pctlProgress->Create( WS_CHILD|WS_VISIBLE|PBS_SMOOTH,
CRect(5,165,305,170), this,
IDC_PROGRESS );
m_pctlProgress->SetRange( 0, 300 );
m_pctlProgress->SetStep( 300 );
//设置定时器
SetTimer( ID_TIMER, 500, NULL ); return 0;
}
/* 响应定时 */
void CSplashWnd::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default m_pctlProgress->StepIt();
}/* 主程序 */
BOOL CSmart114DlgApp::InitInstance()
{ /* 建立并显示启动窗口 */
CSplashWnd::EnableSplashScreen();
CSplashWnd::ShowSplashScreen(); /* 建立主对话框 */
CSmart114DlgDlg dlg;
m_pMainWnd = &dlg; /* 一些耗时的初始化工作 */
InitSysterm(); /* 关闭启动窗口 */
MSG msg;
msg.message = WM_CLOSE;
CSplashWnd::PreTranslateAppMessage( &msg ); /* 显示主对话框 */
int nResponse = dlg.DoModal();
return FALSE;
}
解决方案 »
- 求教:标签控件的子对话框显示位置不正确??
- 关于VS2005中的dll问题
- 在listbox中添加checkbox怎么加呀.有人说把style设为check,我怎么没有找到这个属性呀.
- 关于DCOM线程的问题,请大家参与讨论!参与讨论者有分!
- 求救
- 谁能帮我写一个批处理程序
- help, 如何在线程中处理消息?
- 面对现在的编程语言vc天地有多宽,请诸位大师给我一点灯光!哪怕是依稀的!
- 很爽的XP风格Menu\ToolBar\Combo\Button程序(可惜不是我写的 :) ),有要的吗?
- 熟悉窗口超类化的请进
- mfc 如何实现类似IE6的界面,而且支持XP styler
- 请问一下clocx这个软件的"点击无响应"这个功能是怎么实现的?谢谢~~
在CSplashWnd的消息映射处加一行ON_WM_TIMER()
ON_WM_TIMER()
...
END_MESSAGE_MAP( )
/* 一些耗时的初始化工作 */
InitSysterm();里
主线程来不及响应WM_TIMER消息请看该帖:
http://community.csdn.net/Expert/topic/4955/4955940.xml?temp=.5684168