Celebrated too early (ComboBox color problem again)

Started by Philipp Emanuel Weidmann, November 16, 2005, 11:53:27 AM

Previous topic - Next topic

Philipp Emanuel Weidmann

Hello!

It turned out that the code I recieved as a reply to my earlier post doesn't work after all, it was merely me forgetting to change the color back to normal in the FF property list...  :oops:

So the request still stands: How do you change a ComboBox's background color at runtime without the result being screwed up?

I would really appreciate any help (for more information see post below).

Thank you

Philipp

TechSupport

Hi Philipp,

The code I posted works for me. However, if you are trying to change colors using FireFly's build in SetColor function then it will not work. The code I posted will display a gray background in the combo's edit box whenever the control is disabled. It will turn white whenever the control is enabled. If you want to use a different color than gray then simply change the color of the brush that is being returned.

Are you using Windows XP ???? I tested using Windows 2000. It is possible that WinXP could be causing problems because Windows Themes always seems to play some havoc on color changes (for whatever reason).

Philipp Emanuel Weidmann

Hmmm.... I tried the code again in a separate project and it still doesn't work. It is true that I use Windows XP but I use Windows Classic Theme and the libraries used to draw this are supposedly almost the same as in Win2k.

Can you post a project that works for you or a compiled EXE so that I can see whether it is the OS or not? That would be great.

Thank you

Philipp

TechSupport

No problem.

- Create a new project.
- Add a combo box (Combo1)
- Add a command button (cmdEnable)
- Add a command button (cmdDisable)

Add the following code to the Form.


'------------------------------------------------------------------------------------------------------------------------
Function FORM1_CMDENABLE_BN_CLICKED ( _
                                  ControlIndex     As Long,  _  ' index in Control Array
                                  hWndForm         As Dword, _  ' handle of Form
                                  hWndControl      As Dword, _  ' handle of Control
                                  idButtonControl  As Long   _  ' identifier of button
                                  ) As Long

   EnableWindow HWND_FORM1_COMBO1, %TRUE
   
End Function


Function FORM1_CMDDISABLE_BN_CLICKED ( _
                                  ControlIndex     As Long,  _  ' index in Control Array
                                  hWndForm         As Dword, _  ' handle of Form
                                  hWndControl      As Dword, _  ' handle of Control
                                  idButtonControl  As Long   _  ' identifier of button
                                  ) As Long

   EnableWindow HWND_FORM1_COMBO1, %FALSE
   
End Function



'------------------------------------------------------------------------------------------------------------------------
Function FORM1_COMBO1_CUSTOM ( _
                            ControlIndex  As Long,  _  ' index in Control Array
                            hWndForm      As Dword, _  ' handle of Form
                            hWndControl   As Dword, _  ' handle of Control
                            wMsg          As Long,  _  ' type of message
                            wParam        As Dword, _  ' first message parameter
                            lParam        As Long   _  ' second message parameter
                            ) As Long

 Select Case wMsg
    Case %WM_CTLCOLORLISTBOX, %WM_CTLCOLOREDIT, %WM_CTLCOLORSTATIC, %WM_CTLCOLORBTN
       If IsWindowEnabled( hWndControl ) = 0 Then
          SetBkMode wParam, %TRANSPARENT  
          Function = GetSysColorBrush(%COLOR_BTNFACE)
          Exit Function
       End If  
 End Select

End Function

TechSupport

hmmm.... it looks like it works for ComboBox's with the styles %CBS_DROPDOWN or %CBS_SIMPLE. I don't think that it is working for %CBS_DROPDOWNLIST. Strange. I will check further.

Roger Garstang

Which code has priority...FF's or the Custom?  I didn't check myself yet, but I know we had to change the combo control paint code to ignore and pass to def proc if not an FF generated control with a prop entry.  Perhaps it is ignoring your code then since it is a child control of the parent combo which is what we had problems painting before since we were trying to pass a non-existant prop value the child controls didn't have.  Or perhaps the child controls aren't disabled...just the parent combo?  Might have to test for a parent in the code.

As suggested too, this would be a cool addition to FF since the controls don't paint disabled and from what I can tell only slightly alter their border.  Perhaps adding a background color property with colors and a couple values called something like Default and AutoPaint or ShowState or something.

Philipp Emanuel Weidmann

Quotehmmm.... it looks like it works for ComboBox's with the styles %CBS_DROPDOWN or %CBS_SIMPLE. I don't think that it is working for %CBS_DROPDOWNLIST. Strange. I will check further.

Yeah... that's exactly what I found out as well! Too bad I need it with the dropdown list style. I still appreciate any help!

Thank you

Philipp

TechSupport

Interesting. I find that if you are only dealing with the %CBS_DROPDOWNLIST style then you can simply use the FF_Control_SetColor functions.

The following code worked for me:

'------------------------------------------------------------------------------------------------------------------------
Function FORM1_CMDENABLE_BN_CLICKED ( _
                                  ControlIndex     As Long,  _  ' index in Control Array
                                  hWndForm         As Dword, _  ' handle of Form
                                  hWndControl      As Dword, _  ' handle of Control
                                  idButtonControl  As Long   _  ' identifier of button
                                  ) As Long

   FF_Control_SetColor HWND_FORM1_COMBO1, -1, GetSysColor(%COLOR_WINDOW)
   EnableWindow HWND_FORM1_COMBO1, %TRUE
   
End Function


Function FORM1_CMDDISABLE_BN_CLICKED ( _
                                  ControlIndex     As Long,  _  ' index in Control Array
                                  hWndForm         As Dword, _  ' handle of Form
                                  hWndControl      As Dword, _  ' handle of Control
                                  idButtonControl  As Long   _  ' identifier of button
                                  ) As Long

   FF_Control_SetColor HWND_FORM1_COMBO1, -1, GetSysColor(%COLOR_BTNFACE)
   EnableWindow HWND_FORM1_COMBO1, %FALSE
   
End Function


It should work for you unless my copy of the FF_Functions is newer....

(You will need to remove the previously posted code that deals with the %WM_CTLCOLORXXXX messages).

Philipp Emanuel Weidmann

Simply put... it doesn't work for me. That's exactly the code I started out with and with my system (Win XP Personal SP2 with Windows Classic Style) this code makes the border of the ComboBox turn gray and that's it.

Sorry to cause you that much trouble, but I still think this is worth researching into :) I was even thinking about low-level debugging a Visual Basic Program (VB doesn't exhibit this problem) and look how the VB runtime library does it but got frustrated pretty soon.

TechSupport

Try downloading the latest FireFly Functions file (FF_Functions.zip) and extracting the FF_Functions.src file from that zip file. Install it into your FireFly installation directory to overwrite the existing file.

You can get the file from: http://www.planetsquires.com/files/FF_Functions.zip

Please let me know if it makes any difference at all.

Philipp Emanuel Weidmann

Believe it or not, that did the trick! Thank you so much, you solved my problem.

I am really looking forward to being able to edit the FF functions myself (that was on the 3.0 feature list, or not?).

Thank you again, and have a nice day

Philipp