My this article and its source code is here.
You can see my previous article on showing Pick Icon Dialog at codeproject. It is a very simple way to show this dialog. After that I started trying to customize it to make it more useful. The first change I made is I made a new class which wraps the API and conversions of string in unicode and then back. Now you only need to call just one method of class to show the dialog and other two methods to get path and index of the selected icon.
The second change I made is I customized it to show index of currently selected icon in the icon listbox. I dynamically created a static control on the dialog and updated that static control to show current selection of listbox.
How things works, I hooked the dialog box with SetWindowsHookEx and hook type is WH_CALLWNDPROC. In my hook procedure first thing I wanted to do was to make room for my static control.
ListBox has a Fixed Height , The first thing came to my mind was to shrink the listbox. So I tried, But in vain, It is a “FIXED height” listbox you can’t change its height, I tried to set the height with SetWindowPos() it did not work. Lest I set the height to zero, but the list box remained at its place. The same is not with width, it can be changed.
Make Dialog Bigger , So now only way I had was to make the dialog more taller. So I made it, But making the dialog taller was not the only story I also had to move the buttons down too. There you can see only two buttons, but actually there are three buttons ( Oh SPY++ I love you very much ). I moved the three buttons down, because I did not want to have any problem in the future, If I have to show that third button and moving at that time would not be a good thing, so I solved it here.
Creation of Static Control , then I created static control dynamically, and placed it below the listbox.
Messages Handled , In my hook procedure I handled WM_INITDIALOG , and WM_COMMAND messages. the WM_INITDIALOG message is sent every time when the dialog box is about to be shown, so I did all my control changing there. the second WM_COMMAND message is actually handled only for a notification, which is sent to the parent of a listbox when the listbox selection changes. I handled it to update my static control.
Mysteries, Another thing I noticed in this dialog’s list box is, It selects the first entry by default, But whenever inquired with GetCurSel() it returns -1, which means no selection. So I made my class to handle this problem also.
If Finds a Bug or Problem , if you find any problem or any malfunction, Please inform me.
To me it is necessary to find
Comment by benoSingtrore — February 24, 2008 @ 4:50 pm