首先抱歉我的英语:)
我有点问题。
我有一个用C ++编写的程序,它解析JavaScript文件以找到一些关键字。
我有一个主窗口和一个主菜单,当你点击菜单 - >打开文件夹时,你需要选择你的文件夹。 在此之后,我恢复此文件夹中的所有文件以打开它,阅读它以便找到我的关键字。 当一切都响了,我将结果显示在子窗口中。 我想添加一个显示文本的弹出窗口,如“正在加载,请稍候”,但我有一点问题。
这是我的代码:
// creating a "popup" display a text while loading
MainWindow::m_hwndResLoading = CreateWindow( "edit",
"",
WS_VISIBLE|ES_MULTILINE|ES_READONLY|WS_OVERLAPPED,
0,
0,
400,
200,
hwnd,
NULL,
NULL,
NULL);
// creating my str, and asking my m_hwndLoading to display my text
string loading = "Chargement";
SetWindowText(MainWindow::m_hwndResLoading,TEXT(loading.c_str()));
MainWindow::projectPath = path;
// this function find every files in a specified directory which is source code file
getAllFile(path);
// creating my childwindow which will contain the result of the files parsing
MainWindow::m_hwndRes = CreateWindow( "edit",
"",
WS_VISIBLE|WS_CHILD|WS_BORDER|
WS_VSCROLL|WS_HSCROLL|ES_MULTILINE|
ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_READONLY,
0,
0,
1000,
600,
hwnd,
NULL,
NULL,
NULL);
// create and instanciate my object
FileParser *fp;
fp = new FileParser();
string res = fp->init(files);
// close my loading "popup"
CloseWindow(MainWindow::m_hwndResLoading);
// display the result in my child window
SetWindowText(MainWindow::m_hwndRes,TEXT(res.c_str()));
当我运行应用程序时,当我打开新文件夹时,我的“弹出窗口”正在显示,但没有加载文本。 解析完成后,每个都运行良好,弹出窗口关闭,子窗口填充结果。
我看到了,如果我评论这一行:
CloseWindow(MainWindow::m_hwndResLoading);
加载文本显示的时间与结果相同。
有没有人有点想法帮助我?
非常感谢
答案 0 :(得分:1)
我相信问题是缺少(win32)消息处理。我假设您在代码中的某处有一个消息处理循环(如TranslateMessage
,DispatchMessage
等)?
我认为您的问题是您不会在弹出窗口创建和长时间加载例程之间处理消息(在这种情况下可能是REPAINT
消息)。这就是为什么你的弹出窗口不绘画和应用程序冻结的原因。尝试在CreateWindow
和FileParser::init
之间插入邮件处理调用。