Tag: wxwidgets

Entries for tag "wxwidgets", ordered from most recent. Entry count: 3.

Warning! Some information on this page is older than 3 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

Pages: 1

19:31
Mon
23
Jan 2012

The Concept of Wait Cursor

When coding a GUI application, sometimes we have to conduct lengthy operation like loading or saving a file. It would be perfect if every such operation was done on separate, background thread while main thread - the one responsible for windowed interface - would show progress and allow to cancel the operation at any time. But multithreaded programming is hard, so some (not so critical and not so long) operations, like loading a configuration file, are usually done on the main thread, freezing the whole GUI. It's OK as long as the operation takes no longer than a fraction of second or several seconds - just like loading and parsing small configuration file, unless the file is located on a floppy disk :)

But it's good to show to the user that some operation is being performed so he doesn't get angry and terminate your application so quickly. Changing mouse cursor from "Normal" to "Wait" is useful here, so GUI libraries provide functionality for this.

In C#, we do it by setting Cursor property of a Form. Assuming we are inside a method of a Form:

Cursor = Cursors.WaitCursor;
// Lengthy process...
Cursor = Cursors.Default;

Just don't forget to restore default cursor no matter what's the result of the operation. try-finally section can be useful here to make the wait cursor "exception-safe". Good news is that if you wish to show a MessageBox informing user about an error that happened between setting the cursor to WaitCursor and restoring it, the cursor will change to Default automatically for the time the message window is shown.

It may be tempting to use Application.UseWaitCursor instead, but this method is worse. It requires to go back to main message loop before the cursor change takes effect, so if you set Application.UseWaitCursor = true; then do some time-consuming process inside same function and set Application.UseWaitCursor = false; at the end, user won't see changed cursor at all, whereas setting Cursor property of a form takes effect immediately.

wxWidgets library makes it easy to change cursor to "busy" - as they call it - and restore it at the end of C++ scope by creating an object of class wxBusyCursor on the stack. It will change cursor in its constructor and automatically restore it in destructor of the object.

{
    wxBusyCursor busyCursor;
    // Lengthy process...
}

MFC library also has such class. It is called CWaitCursor.

If you know the way to show wait cursor in other GUI libraries, post it in a comment.

Comments (1) | Tags: wxwidgets .net mfc gui | Author: Adam Sawicki | Share

00:16
Thu
06
May 2010

Compiling wxWidgets 2.9.0 in Visual C++ 2010 Express

NEW! (2011-02-18) I posted this entry months ago, wxWidgets keeps evolving and so it may no longer work. For building wxWidgets 2.9.1 in Visual C++ 2010, I now recommend you follow steps described here: Visual Studio C++ 2010 - Microsoft Visual C++ Guide - wiki.wxwidgets.org and here: Fixed wxWidgets 2.9.1 project files Visual Studio 2010 - forums.wxwidgets.org.

My old blog entry:

Today I wanted to compile wxWidgets library (version 2.9.0, which contains lots of interesting new features, including wxPropertyGrid control) under Visual C++ 2010 Express. A strange error appeared that stopped the build and explained nothing specific about the cause:

Microsoft.CppCommon.targets(151,5): error MSB6001: Invalid command line switch for "cmd.exe". The path is not of a legal form.

It took me some time to find a correct solution on Google, as many of them didn't work. (Copy setup.h file to some another directory? Made no difference in my case. Use the wx.dsw - project file for oldest IDE version? Didn't work either, my Visual says it cannot import such projects.)

Finally I've found this forum topic: http://forums.wxwidgets.org/viewtopic.php?t=27630. Sami Hamlaoui on 25th April 2010 posted a ZIP archive there containing converted and fixed project for Visual C++ 2010 that you can download and use to successfully build wxWidgets 2.9.0. Thanks for that!

After you build all projects in Debug and Release configuration, you just need to setup include and library paths in the IDE:

...\wxWidgets-2.9.0\include
...\wxWidgets-2.9.0\include\msvc

...\wxWidgets-2.9.0\lib\vc_lib

And finally you can use wxWidgets in your projects. To do that, you need to #include files such as and link with these libraries:

comctl32.lib, rpcrt4.lib, winmm.lib, advapi32.lib, wsock32.lib

and desired wx libraries like wxbase29ud.lib and wxmsw29ud_core.lib ("d" is for debug, use versions without "d" in Release configuration). Also remember that the new wxWidgets has no ASCII support, so you have to use Unicode character set.

Comments (2) | Tags: wxwidgets visual studio | Author: Adam Sawicki | Share

18:43
Thu
18
Mar 2010

How to Disable Redrawing of a Control

When coding Windows application with GUI, there is an issue about how long does it take to add lots of items (like hundreds or thousands) into a list view or tree view control. It is caused by redrawing the control after each operation. I've seen this annoying effect in may programs, including some serious, commercial ones. Apparently many programmers don't know there is a simple solution. But first a bit of background...

When coding games, we constantly spin inside a big loop and redraw whole screen every frame. Calculations are separated from rendering so we can, for example, build a list with thousands of items in the computation function and the visible part of the list will start being rendered since the first rendering function call after that. When coding windowed applications, nothing new is drawn onto the screen unless needed. We have to manually do it and we can call redrawing function any time. So how should a list control be refreshed when we add an item into it? It is done automatically after each insert, which is a good solution... unless we want to add hundreds of them.

So GUI library developers provide a functionality to temporarily disable redrawing of a control.

Comments (2) | Tags: .net mfc wxwidgets winapi gui | Author: Adam Sawicki | Share

Pages: 1

STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2017 Adam Sawicki
Copyright © 2004-2017 Adam Sawicki