Archive for the ‘UI’ Category

Về Memory leak trong MFC/C++ trên Windows

<Bài này viết lâu rồi, trên Live Spaces, nay move qua đây>

Những ai lập trình C có kinh nghiệm chắc hẳn đều thừa nhận rằng việc C/C++ giao hẳn trách nhiệm quản lí bộ nhớ cho người lập trình thực sự là một ưu điểm mạnh mẽ, và cũng chính là khuyết điểm lớn của ngôn ngữ này. Với tư tưởng đó, lập trình viên C++ luôn phải làm một công việc khó chịu và mất nhiều thời gian là phát hiện và loại trừ memory leak trong chương trình. Entry này không trình bày cặn kẽ và chi tiết về memory leak, mà chỉ là ghi lại một số kinh nghiệm của người viết. Hi vọng bài viết sẽ có ích với những người (và chỉ những người) đã có kinh nghiệm làm việc với C++, đã có những hiểu biết cơ bản về memory leak như: tại sao lại có memory leak, tại sao phải tránh memory leak v.v…
Read more…


Differences between Control.Invalidate(), Control.Refresh and Control.Update


Before discussing each one of the above functions, let’s look at how winforms controls paint.

Windows controls paint is response to WM_PAINT messages. This message is sent when UpdateWindow or RedrawWindow is called, or by the DispatchMessage function when the application gets a WM_PAINT through the message queue. On getting the WM_PAINT message, the control paints its background and then the foreground if necessary. Double-buffering and transparency is honored while painting and then the OnPaint event is fired to give the user a chance to perform his custom painting.

With this background, let’s look at the above mentioned three functions in more detail,

Control.Invalidate( ) / Control.Invalidate(bool) / Control.Invalidate(Rectangle) / Control.Invalidate(Rectangle, bool) / Control.Invalidate(Region) / Control.Invalidate(Region, bool)

The bool parameter denotes whether the user wants to invalidate the child controls of the control on which he is calling Invalidate. The Rectangle parameter are the bounds to invalidate and the region parameter is the region to invalidate. All the overloads essentially end up calling one of the RedrawWindow, InvaliateRect or InvalidateRgn functions. If RedrawWindow is called then this may result in a WM_PAINT message being posted to the application message queue (to invalidate the child controls).

The important thing to note here is that these functions only “invalidate” or “dirty” the client area by adding it to the current update region of the window of the control. This invalidated region, along with all other areas in the update region, is marked for painting when the next WM_PAINT message is received. As a result you may not see your control refreshing (and showing the invalidation) immediately (or synchronously).


Update function calls the UpdateWindow function which updates the client area of the control by sending WM_PAINT message to the window (of the control) if the window’s update region is not empty. This function sends a WM_PAINT directly to WNDPROC() bypassing the application message queue.

Thus, if the window update region is previously “invalidated” then calling “update” would immediately “update” (and cause repaint) the invalidation.


By now, you might have guessed what Refresh( ) would be doing. Yes, it calls Invalidate(true) to invalidate the control and its children and then calls Update( ) to force paint the control so that the invalidation is synchronous.

Windows Touch in C++ fashion

A great article and presentation on how to multitouch in C++. It’s really worth watching and trying…

What can you do with MS SmallBasic

I spent my rarely free time before the Lunar New Year holiday by playing with SmallBasic – one of more interesting tools introduced by Microsoft. Just another easy tool for newbies, and at the first sight, I was really skeptical. SmallBasic just has less than 15 keywords, and I can’t imagine anything I can do with it…

Read more…

10 Useful Techniques To Improve Your User Interface Designs

Lại thêm 1 bài báo nữa về UI design, nhưng h thì lười wá, không copy nữa (mà cũng chưa đọc hết dc nó), nên đặt tạm cái link đây vậy:

Colors and the UI: another good article for UI designers

As the name suggests, GUIs (Graphical User Interfaces) present their features and functions visually. The human-computer interaction is heavily based on seeing things, looking for things and interacting with graphical UI elements. Color is a main characteristic of any visual scene, not only on computer screens, but in any situation where we see something. Because most of what we see and interact with in our everyday life is colored (as opposed to shades of white-gray-black), we are very familiar with colors – maybe so much that we don’t think about them a lot. On the other hand, it does bother us when we need to read a dark-gray label on a black button. So colors have the potential to boost or wreck the user experience. This article will introduce the concept of user experience and highlight some aspects of colors and color perception together with recommendations for UI design.

Read more…

Scrolling PropertyPage in MFC

26/11/2008 Comments off

This piece of code can make a propertyPage scroll smoothly in MFC. It’s really easy to use…

Read more…