Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

set colour of background in listbox

chunky_lover_23
Beginner
396 Views

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

0 Kudos
2 Replies
anthonyrichards
New Contributor III
396 Views

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 
 
0 Kudos
anthonyrichards
New Contributor III
396 Views

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)

0 Kudos
Reply