- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Other than using the Xeffort download, is there any simple way of setting the background colour in a listbox control ?
I've tried a number of combinations of:
jret = SendMessage (GetDlgItem (dlg%hwnd, IDC_list1),
& LB_******,0,Rgb (INT1(50),INT1(0),INT1(0)))
with LB set to a number of message flags.
So far, no joy
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you will have to write a default dialog procedure to handle the WM_CTLCOLORLISTBOX message sent just before a control is drawn (see below from the Help). Call the procedure MyDlgProc, for instance.
This new procedure can then be used to replace the default dialog procedure using IOldDlgProc=SetWindowLong(dlg%hwnd, DWL_DLGPROC, LOC(MyDlgProc) )
This is done in a callback routine activated when your dialog is created. Your replacement procedure MyDlgProc can then process the WM_CTLCOLORLISTBOX message for the controls you are interested in and it must then pass on all other messages that it does not process to the default dialog procedure, either using CallWindowProc using the pointer IOldDlgProc to the original dialog procedure,
iret=CallWindowProc(IOldDlgProc, dlg%hWnd, message, wparam, lparam)
or by calling
iret=DefDlgProc(dlg%hwnd, message, wparam, lparam)
one of which should work.
WM_CTLCOLORLISTBOX
The WM_CTLCOLORLISTBOX message is sent to the parent window of a list box before the system draws the list box. By responding to this message, the parent window can set the text and background colors of the list box by using the given display device context handle.
WM_CTLCOLORLISTBOX
hdcLB = (HDC) wParam; // handle to list box display context
hwndLB = (HWND) lParam; // handle to list box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is a zipped workspace that creates a simple dialog with two edit boxes and one listbox. It shows you how to identify the control and colour it accordingly. Just run the EXE and the messages tell you what to expect. It uses subclassing and a special dialog procedure, as I mentioned in my earlier post. It is fairly straightforward, the only wrinkles I found were that the new dialog procedure had to return the brush handle and return immediately (note the 'return' statement) or it did not work.
(P.S. I use Compaq Visual Fortran, but the Fortran code is there for you to create a new project if you are using the Intel compiler)

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page