Archive for the ‘Managed Code’ Category

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.


I am currently having some fancy ideas about various topics that I can dive in. The bad news is I have too little time for them right now, so although I intended to start very soon, but I’m not sure when I can really dig into these messes.

These ideas are very straightforward:

1. Security in Cloud computing, data mining/querying on encrypted databases and practical facts.

This idea came to me in the RIVF conference last month. The general consideration is how can we trust the Cloud service provider (i.e. Windows Azure, Amazon Web Service…) that they will not steal our data, how much our data is secured? When we performing queries, how can we know if the provider is faithful enough?

One of possible solutions is encrypting the data before sending it to the provider. The problem hence raise, since how could we do data mining, query “our” encrypted data which are stored on provider’s infrastructure?

This is really a hard (and interesting!) problem, and it draws many attentions from academic scholars. It is pretty useful to apply the academic idea on commercial service like Windows Azure or AWS…

2. The second idea comes from my experiences on GPU computing with CUDA.

DirectCompute has been announced in PDC 2009, and it seems promising in cross-platform GPU computing. Nonetheless, the documentation of DirectCompute seems to be lacking (even on MSDN DirectX). I want to dig into DirectCompute, perform some benchmarks to check it performance, and then comparing with CUDA or OpenCL. I believe this will point out some interesting conclusions.

So if one of the readers of this blog would like to investigate to these problems, please contact me. I’m not sure this will lead to anywhere, but at least it can help you improving some skills 😉


Các thông tin chi tiết về phần mềm XMDict phiên bản 0.225 sẽ được đặt ở đây….

0. File hướng dấn XMDict: download (new – updated 22/12/2008)

1.    Cài đặt .NET CF 3.5:

Tùy thuộc vào hệ điều hành đang sử dụng, bạn tiến hành chép các file sau đây vào PocketPC (hoặc thẻ nhớ) rồi tiến hành cài đặt như bình thường.

WM 2003/WM 2003 SE: .NET CF 3.5

WM 2005: .NET CF 3.5

WM 6: .NET CF 3.5

WM 6.1: không cần cài đặt .NET CF 3.5 nếu sử dụng hệ điều hành này.

2.    Cài đặt XMDict:

Download file này về máy tính rồi chép vào PocketPC hoặc thẻ nhớ, sau đó cài đặt như các ứng dụng khác.

3. Cài đặt font tiếng Việt:

WM 2003/WM 2003 SE: font Unicode
WM 2005: font Unicode

4. Các từ điển hỗ trợ:

1. Afr – Deu: Nam Phi – Đức

2. Afr – Eng: Nam Phi – Anh

3. Cze – Eng: CH Séc – Anh

4. Dan – Eng: Đan Mạch – Anh

5. Deu – Fra: Đức – Pháp

6. Deu – Ita: Đức – Ý

7. Deu – Nld: Đức – Hà Lan

8. Deu – Por: Đức – Ba Lan

9. Eng – Afr: Anh – Nam Phi

10. Eng – Ara: Anh – Ả rập

11.Eng – Fra: Anh – Pháp

12.Eng – Ita: Anh – Ý

13. Eng – Nld: Anh – Hà Lan

14. Eng – Rus: Anh – Nga

15. Eng – Spa: Anh – TBN

16. Fra – Deu: Anh – Đức

17. Fra – Eng: Pháp – Anh

18.Fra – Nld: Pháp – Hà Lan

19. Por – Eng: BĐN – Anh

20. Spa – Eng: TBN – Anh

21. Swe – Eng: Thụy điển – Anh

22. Tur – Eng: TNK – Anh

23. Viet – Anh: Việt – Anh

24. Viet – Duc: Việt – Đức

25. Viet – Phap: Việt – Pháp

26. Viet – Viet: Việt – Việt

Do thời gian có hạn nên đây là toàn bộ dữ liệu của 26 từ điển trên để dùng cho XMDict.

MSP Tech Passion

23/02/2009 5 comments

Today I had a presentation about Functional Programming in .NET with C# and F# at Microsoft Vietnam office, according to the MSP Tech Passion conference series. Everything is OK, and I think the audience gets somewhat exciting with my presentation.

I have uploaded the slide and demo source code here. Fell free to comment and discuss about this.

Sending SMS message in Windows CE

15/01/2009 31 comments

Download the source code

Today I will show the way to send SMS message in Windows CE and Windows Mobile, using C++ and P/Invoke in .NET CF. It’s pretty simple…

In Windows CE environment, SMS fuction is handled by “sms.dll”, but in Windows Mobile 2005 and later, it’s handled (in a much more simpler way) by “cemapi.dll”. The “cemapi.dll” is not documented very well, in the other hand, you can find lots of information about “sms.dll” on MSDN.

Read more…

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…

How to programmatically establish GPRS connection in .NET CF

This is a simple way to establish GPRS connection in .NET CF using RAPI. Remember to check “Allow unsafe Code Blocks” option in project properties page!
Read more…