简体   繁体   English

使用C ++ Win32 GUI在窗口中显示文本

[英]displaying a text in a window with C++ Win32 GUI

at first sorry for my english :) 起初对我的英语很抱歉:)

I have a little problem. 我有一点问题。

I have a program written in C++ which parse JavaScript files in order to find some keywords. 我有一个用C ++编写的程序,该程序可以解析JavaScript文件以便找到一些关键字。

I have a main window and a main menu, and when you click to menu->open folder, you need to select your folder. 我有一个主窗口和一个主菜单,当您单击菜单->打开文件夹时,您需要选择文件夹。 After this, i recover all the files in this folder to open it, read it in order to find my keyword. 在此之后,我恢复了该文件夹中的所有文件以打开它,请阅读它以找到我的关键字。 When everything is sone, i display the result in a childwindow. 一切正常后,我在子窗口中显示结果。 I wanted to add a popup displaying a text like "loading, please wait" but i have a little problem. 我想添加一个显示诸如“正在加载,请稍候”之类的文本的弹出窗口,但是我有一个小问题。

Here is my code : 这是我的代码:

// 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()));

when i run the application, when i open the new folder, my "popup window" is displaying, but without the loading text. 当我运行该应用程序时,当我打开新文件夹时,显示“弹出窗口”,但没有加载文本。 when the parsing is done, everythin works well, the popup window is closed and the child window is filled with the result. 解析完成后,一切都很好,关闭了弹出窗口,并在子窗口中填充了结果。

I saw that, if i comment this line : 我看到了,如果我对此行发表评论:

CloseWindow(MainWindow::m_hwndResLoading);

the loading text is displayed in the same moment than the result. 加载文本与结果显示在同一时刻。

Does anyone have a little idea to help me? 有人有帮助我的想法吗?

Thanks a lot 非常感谢

I believe the problem is missing (win32) message processing. 我相信问题是缺少(win32)消息处理。 I assume you ave a message processing loop (like TranslateMessage , DispatchMessage and the like) somewhere in your code? 我假设您在代码中的某处有一个消息处理循环(例如TranslateMessageDispatchMessage之类)?

I think your problem is that you don't process messages (in this cases probably a REPAINT message) between the popup creation and your long loading routine. 我认为您的问题是,您在弹出窗口创建和长时间加载例程之间不处理消息(在这种情况下,可能是REPAINT消息)。 That's why your popup doesn't paint and the application freezes. 这就是为什么您的弹出窗口不绘制并且应用程序冻结的原因。 Try to insert message processing calls between CreateWindow and FileParser::init . 尝试在CreateWindowFileParser::init之间插入消息处理调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM