How to change the color of CComboBoxEx

I have derived my class from CComboBoxEx and I change the colors
(SetBkColor and SetTextColor) in OnCtlColor() in response to
CTLCOLOR_EDIT and CTLCOLOR_LISTBOX; I also return my brush;
As a result the colors of the edit part of the combo do change but in
the listbox only the space around the text is painted. The text itself
and its backgound remain as the Windows defaults.
0
svilst (2)
8/31/2003 4:46:17 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
1418 Views

Similar Articles

[PageSpeed] 28

"David A. Mair" <mairda@hotrmail.com> wrote in message news:<ObKF5Q#bDHA.2632@TK2MSFTNGP12.phx.gbl>...
> I have it working OK, here's my CColorComboBox::OnCtlColor():
> 
> HBRUSH CColorComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
> {
>     LOGBRUSH brush;
>     HBRUSH hbr;
> 
>     if ((nCtlColor == CTLCOLOR_LISTBOX) || (nCtlColor == CTLCOLOR_EDIT))
>     {
>         // Show white text on a pastel blue background
>         brush.lbStyle = BS_SOLID;
>         brush.lbColor = RGB(128, 192, 255);
>         hbr = CreateBrushIndirect(&brush);
>         pDC->SetBkColor(RGB(128, 192, 255));
>         pDC->SetTextColor(RGB(255, 255, 255));
>     }
>     else
>     {
>         hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
>     }
> 
>     return hbr;
> }
> 
> The project was created with Visual Studio .NET 2003 on Windows 2000
> Advanced Server.  The project uses a CColorComboBox member in the CDialog
> with the member linked to the ID of the combobox control in the dialog.
> When I ran the debug target the result was a combobox with a pastel blue
> background and when I type in it the text is white.  When I drop down the
> list (I populated it with a few entries in OnInitDialog()) the result is a
> fully filled pastel blue background to the drop down list with the text in
> white on a pastel blue background.  IOW, the drop down list is completely
> coloured with the pastel blue all the way to the black border.
> 
> I had the same results as you while testing iterative stages of
> developement, it worked as you are seeing until I completed the code to
> create my brush.
> 
> "svilen" <svilst@hotmail.com> wrote in message
> news:f6b84cfe.0308310846.2b8a5ac3@posting.google.com...
> > I have derived my class from CComboBoxEx and I change the colors
> > (SetBkColor and SetTextColor) in OnCtlColor() in response to
> > CTLCOLOR_EDIT and CTLCOLOR_LISTBOX; I also return my brush;
> > As a result the colors of the edit part of the combo do change but in
> > the listbox only the space around the text is painted. The text itself
> > and its backgound remain as the Windows defaults.

As I understand your class is derived from CComboBox not from
CComboBoxEx
regarding CComboBox - I have working code and it is generally the same
as yours.
But try deriving your class from CComboBoxEx and then test how the
text background is coloured.
I suspect that the problem lies in the fact that CComboBoxEx
encapsulates an ordinary ComboBox as its child. The WM_CTLCOLOR
message is sent BOTH to the child  - the combobox (and this we do not
handle at all) and then to its parent CComboBoxEx (which message we
handle). But notice that CComboBoxEx handler receives the message
second (after the ordinary combobox) but it handles it first, i.e it
is nested in the handler of the combobox. Which means that the
ordinary combobox has the last word and it probably does something
after we change the colors in OnCtlColor

I do not know if my make myself clear but if you can please try
changing your class to be a descendant of CComboBoxEx . not CComboBox
and see the result.
0
svilst (2)
9/1/2003 6:41:50 PM
"svilen" <svilst@hotmail.com> wrote in message
news:f6b84cfe.0309011041.34ce96c3@posting.google.com...
> "David A. Mair" <mairda@hotrmail.com> wrote in message
news:<ObKF5Q#bDHA.2632@TK2MSFTNGP12.phx.gbl>...
> > I have it working OK, here's my CColorComboBox::OnCtlColor():
> >
> > HBRUSH CColorComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
> > {
> >     LOGBRUSH brush;
> >     HBRUSH hbr;
> >
> >     if ((nCtlColor == CTLCOLOR_LISTBOX) || (nCtlColor == CTLCOLOR_EDIT))
> >     {
> >         // Show white text on a pastel blue background
> >         brush.lbStyle = BS_SOLID;
> >         brush.lbColor = RGB(128, 192, 255);
> >         hbr = CreateBrushIndirect(&brush);
> >         pDC->SetBkColor(RGB(128, 192, 255));
> >         pDC->SetTextColor(RGB(255, 255, 255));
> >     }
> >     else
> >     {
> >         hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
> >     }
> >
> >     return hbr;
> > }
> >
> > The project was created with Visual Studio .NET 2003 on Windows 2000
> > Advanced Server.  The project uses a CColorComboBox member in the
CDialog
> > with the member linked to the ID of the combobox control in the dialog.
> > When I ran the debug target the result was a combobox with a pastel blue
> > background and when I type in it the text is white.  When I drop down
the
> > list (I populated it with a few entries in OnInitDialog()) the result is
a
> > fully filled pastel blue background to the drop down list with the text
in
> > white on a pastel blue background.  IOW, the drop down list is
completely
> > coloured with the pastel blue all the way to the black border.
> >
> > I had the same results as you while testing iterative stages of
> > developement, it worked as you are seeing until I completed the code to
> > create my brush.
> >
> > "svilen" <svilst@hotmail.com> wrote in message
> > news:f6b84cfe.0308310846.2b8a5ac3@posting.google.com...
> > > I have derived my class from CComboBoxEx and I change the colors
> > > (SetBkColor and SetTextColor) in OnCtlColor() in response to
> > > CTLCOLOR_EDIT and CTLCOLOR_LISTBOX; I also return my brush;
> > > As a result the colors of the edit part of the combo do change but in
> > > the listbox only the space around the text is painted. The text itself
> > > and its backgound remain as the Windows defaults.
>
> As I understand your class is derived from CComboBox not from
> CComboBoxEx
> regarding CComboBox - I have working code and it is generally the same
> as yours.
> But try deriving your class from CComboBoxEx and then test how the
> text background is coloured.
> I suspect that the problem lies in the fact that CComboBoxEx
> encapsulates an ordinary ComboBox as its child. The WM_CTLCOLOR
> message is sent BOTH to the child  - the combobox (and this we do not
> handle at all) and then to its parent CComboBoxEx (which message we
> handle). But notice that CComboBoxEx handler receives the message
> second (after the ordinary combobox) but it handles it first, i.e it
> is nested in the handler of the combobox. Which means that the
> ordinary combobox has the last word and it probably does something
> after we change the colors in OnCtlColor
>
> I do not know if my make myself clear but if you can please try
> changing your class to be a descendant of CComboBoxEx . not CComboBox
> and see the result.

Yes, now I can reproduce what you see.  However, I did a little research
and, as far as I can see there is no encapsulated CComboBox in CComboBoxEx.
In fact, CComboBoxEx is derived from CComboBox (so a CComboBoxEx is a
CComboBox so doesn't need to contain one and there isn't one in the member
list).  For example, here's the guts of the implementation of
CComboBoxEx::GetComboBoxCtrl():

return (CComboBox*) CComboBox::FromHandle((HWND)::SendMessage(m_hWnd,
CBEM_GETCOMBOCONTROL, 0, 0));

IOW, there's a ComboBox inside ComboBoxEx but there isn't a CComboBox inside
CComboBoxEx.  I only offer that part for clarity.

This all suggests to me that the problem lies not in the framework but in
the Windows common control implementation for a ComboBoxEx.  The only way I
can imagine it being possible to do what you need is to either do an owner
drawn combobox of your own or maybe you can subclass the control.  I tried
the latter a few different ways and couldn't get close to resolving the
problem.  On searching at Google I find several other reports of the same
problem with others offering their own solutions with comments like: "Extra
formatting properties beyond icon and indentation such as text alignment and
colour are not provided for".


0
mairda (55)
9/1/2003 9:30:55 PM
Reply:

Similar Artilces:

Change of recipient/sender display name
Hi All, Environment :- Windows 2003 x64 with exchange 2007 (All in one role) Outlook client :- 2003, 2007 We have created a list of mail contacts (which under GAL) in exchange 2007, these mail contacts are associates with external email address, each of contact has a naming standard for display name, for example, display name is HD Finance Manager, external email address is fin_manager@hdemea.com I want to configure outlook client to show the display name according to mail contacts whenever the email address is match to mail contacts list (GAL), for example, an email sent from the email a...

Change default font format in Excel
I have an existing workbook with cell text entries in regular black font. I want to make a number of additional entries in various cells in this workbook, and I want all my text entries to be a different font format (bold, red). Is there a way to do this automatically without highlighting each entry I make and manually changing the cell format? Thanks. Michael, Copy the code below, right-click on your sheet tab, select "View Code" and paste the code in the window that appears. HTH, Bernie MS Excel MVP Private Sub Worksheet_Change(ByVal Target As Range) If Target.Cells.Cou...

Change links to hyperlinks in a workbook?
I have 5 Income Statement sheets in a workbook. The first sheet is an Income Statement summing four departments (listed by columns). Column B has Dept 1 data, column C has Dept 2 data, etc. ALL data on this sheet is linked (referenced) to the other four sheets which are the individual departments. I know I can set hyperlinks one at a time, but is there a way for me to have each of those links (every cell containing the data from the other four sheets) become hyperlinks? If I have to add another sheet that mirrors the summary sheet but has hyperlinks, that would be fine. I am just ...

changing the cell information #2
Hi I have files I tried to change the cell information to another cel that have to be the blank for a row that contains director name in cel A and for the movie titles I have to have director names instead of th title names.Please help me, the data in cell B sholuld have to be, A 1 D:B.Jane 2 T:Back to the future 3 T:Aliens 4 T:X-files 5 D:Adam Mathew 6 T:Core 7 T:Titanic B 1 (empty) 2 D:B.Jane 3 D:B.Jane 4 D:B.Jane 5 (empty) 6 D:Adam Mathew 7 D:Adam Mathew thanks -- Message posted from http://www.ExcelForum.com ...

Change <value> in outlook
We Have Exchange 2003 sp2 and outlook 2003 sp2. I have renamed 2 AD accounts. Changed all display names, accounts name etc with the 2 accounts. When users open outlook and send to renamed account they see account name <oldaccountname> in the autocomplete list. I have cleared nk2 files in profile , but it still shows newaccount <oldaccountname> in drop down box. Is there a way to edit the <oldaccountnam> value of the renamed account? I tried the same thing with a freshly loaded PC. with the same result. Thanks You can delete the nickname files. -- Ed Crowley MVP - E...

Changing Interface OWA (exchange 2003)
Not sure if you all remember but back in the Exchange 5.5 days we use to be able to go onto a site and put in the username of the person mailbox you want to access, then a windows pop up would come up asking you for your credentials. I was wondering if that is still possible to do that in Exchange 2003? If so how can that be done? Configure Forms-Based Authentication (FBA). -- Ed Crowley MVP - Exchange "Protecting the world from PSTs and brick backups!" "John" <nospam@comcast.net> wrote in message news:evIllMndHHA.596@TK2MSFTNGP06.phx.gbl... > Not sure...

Color Tabs
Is there away to change the color of the tab only when the sheet is active? Only from XL2002 on. -- HTH Bob Phillips "zero" <zero.tag21@excelforum.com> wrote in message news:zero.tag21@excelforum.com... > Is there away to change the color of the tab only when the sheet is > active? Only in 2002/2003 Zero -- Regards Ron de Bruin (Win XP Pro SP-1 XL2002 SP-2) www.rondebruin.nl "zero" <zero.tag21@excelforum.com> wrote in message news:zero.tag21@excelforum.com... > Is there away to change the color of the tab only when the sheet is > active...

Change License / Company name
Hi, we tried CRM 1.2 with the MSDN license key. Now my company bought a 25 user Proffesional Suite license and I want to change the key on the production server. Is there an easy way to do this?? The only solution I see, is via the Data Migration Framework. Erik. How about the re-deploy tool? "Erik" <none> wrote in message news:u0SXdbXlEHA.3452@TK2MSFTNGP15.phx.gbl... > Hi, > we tried CRM 1.2 with the MSDN license key. Now my company bought a 25 > user > Proffesional Suite license and I want to change the key on the production > server. Is there an easy wa...

Locking cell color while allowing data changes in cell
In excel 2000, I created an attendance worksheet for my classes.(Alphabetized names down left vertical column. Dates across top of horizontal row.) I added a different color to all cells in every other row to make for easier reading of each student's name and absences. Every other row stays with a white background. My question: I wondered if it was possible to lock row colors while allowing data to change on top of them. If a new student is added to my class in alphabetical order, the alternating color pattern is often lost. It is a pain to rechange row and cell colors. Any shortcut ...

Changing the Selection Fields in a Combo Box
Hi, I've created a Combo Box using the Controls Wizard. In creating the control, I specified that my unique value to be stored in the table is an ID. When the user views the selection options in the Combo Box, I'd like to have the ID field hidden and only see the text values, while still storing the ID in the appropriate column. This is probably a second question. Also, when the user views a form that has been populated, I'd like them to see the actual textual values on the form, as just the stored ID value. Is that possible to do with the one Combo Box or is that...

APAY Frequency changes mysteriously
Has anyone noticed that if, for example, you set up an APAY bill monthly, that all of a sudden the next pay date is many months later? It will be cruising along fine, sending bills monthly via MSN Billpay automatically and then one day I go to look at BILLS AND DEPOSITS and some of the autopay's that should be due next month say something crazy like it wont be paid until three months from now or even Jan of next year. I have to cancel the autopay and resubmit it with the proper information. This has happened to me several times in Money2003 on XP... p.s. I tried out the archive feature t...

Background changes conditionally
Hi all, I have a spreadsheet that shows the floor plan layout of my call centre. On each desk, the desk number and identity are displayed. I would like to colour the background for those pcs that are on the same subnet. I have a sheet called data - it contains Table Number, Desk Number, PC ID, IP Address. How could I get it to change the background colour if the pc is on subnet 162, and set a different colour for those on subnet 167 any ideas? -- PeterG ------------------------------------------------------------------------ PeterG's Profile: http://www.excelforum.com/member.p...

gp10 change clients pointing to different server
In version GP 10 I have clients pointed to a test server. When production server is ready what do i do to point the clients to the production server e.g. GPServer. Would I change the odbc connection? Or Rerun the client installs? Any help is appriciated. Thank YOu As long as your production server has THE SAME level service pack as your clients and THE SAME third party products all you need to do is repoint your ODBC to the production server. Best regards, -- MG.- Mariano Gomez, MIS, MCP, PMP Maximum Global Business, LLC http://www.maximumglobalbusiness.com "2020" wro...

OWA & "User must change password at next logon"
Current Environment: Running EX2K3(SP2), and using OWA as the ONLY option to get e-mail; using certificates (https:\\owa.domain.com\exchange) & forms based Authentication. Problem: I create a NEW user in AD; e-mail enable it, and select "User must change password at next logon". Now when the user tries to log in (VIA OWA) s/he is not prompted to change the password / it won't even log them in. It use to work with our old exchange 2000 environment, where it gave them the opportunity to change the password at sign on. Answer: ? There is one property in MetaBase: ...

Changing default Print copies
Hi, I have a workbook that has a worksheet with default printing copies of 3. Even when I go to page setup and change the number of copies to print to 1 it will automatically revert to 3 the next time I bring up the print dialog. I have also looked through the VBA editor at the worksheet for any oddities and have found none. Does anyone know how to change this permanently? Thanks in advance. Pach >Even when I go to page setup and change the number of copies to > print to 1 it will automatically revert to 3 the next time I bring up > the print dialog. Look at the defaults for you...

HOW DO I COPY FORMULA WITHOUT CHANGING CELL REFERENCE
My cell c1 contains the formula b1-a1.when i copy this formula to cells d1 and e1 the cells d1 and e1 have the following formula : d1=c1-b1 e1=d1-c1 but i want the following d1 should be b2-a2 and e2 should be b3-a3 how do i do this? One way... In C1 enter & copy across: =INDEX($A:$A,COLUMN()-COLUMN($C$1)+1)-INDEX($B:$B,COLUMN()-COLUMN($C$1)+1) anantth wrote: > My cell c1 contains the formula b1-a1.when i copy this formula to cells d1 > and e1 the cells d1 and e1 have the following formula : > d1=c1-b1 > e1=d1-c1 > > but i want the following > d1 should be b2-...

stop automatically changing formula!
i have a countif function COUNTIF(Locking!I16:I40,"f") when i copy this and paste it to the next cell, the formula automatically change to COUNTIF(Locking!J16:J40,"f") How do I stop it from changing column I to J?!?!?! thanks. Caryn, =COUNTIF(Locking!$I$16:$I$40,"f") or =COUNTIF(Locking!$I16:$I40,"f") HTH, Bernie MS Excel MVP "caryn" <caryn.tan@gmail.com> wrote in message news:d7n4u3$hgi$1@avnika.corp.mot.com... > i have a countif function > COUNTIF(Locking!I16:I40,"f") > when i copy this and paste it to the nex...

unable to change password via OWA
Hi, I am having a problem with users changing passwords via OWA. When they click on the change password button, it comes up with change password screen and asked for domain name, user name , old password ,etc. The problem that I have is that when I submit it, it comes up with message saying "Either the password is too short or password uniqueness restrictions have not been met." But I didn't define any password policy on DC. What can I do ? Kindly please give me some idea. Thanks Losa If you are running windows and exchange 2003 then there are password requirements that...

prompting to save workbook every time (even when no changes made)
i have 3 workbooks all very similar and every single time i open any o them, even when not changing anything, i am prompted to save th thing. its so bad that i can literally open the workbook then click the clos button straight away and it STILL prompts me to save it because i seems to think something has changed. as far as i can see i dont have any macros or anything that will ru every time it starts and change something (i did have a = today in on cell which kept the date as today but taking this out made n difference -- Message posted from http://www.ExcelForum.com Hi Neowok! You prob...

find match then change cell value
In column A I have cells filled with text and in column B I have cells filled with numbers. I need to check if the number in cell C1 equals any of the numbers in column B. If a match is found then I need to change the text in column A to CBO. e.g. Column A Column B Column C aep 5 7 apa 0 gci 59 xto 5000 xle 7 oih 253 ed 8 Since the cell C1 = 7 equals the 7 from column B, I need to change the data in column A from xle to cbo. Is this possible...

Insert new row as cell contents change
Insert new row as cell contents change. After importing data I have a spread sheet with a column that contains a series of alpha numeric characters. At various random intervals in this column the contents change. EG rows 1 to 4 could contain ABC, then rows 5 to 15 could become 222. I am looking for a method to insert a blank row automatically between the rows were the contents change. Many Thanks Geo George If you are familiar with VBA the code below will do what you want. Preselect the column of data first Sub InsertRowAfterValueChange() Dim myCell As Range Dim sCurrVal As String ...

excel fillin color
Fill-in color does not show on worksheet while working on the sheet only in the preview Have I turned off a switch or what needs to be done? Hi The high contrast setting may be turned on. There's information in the following MSKB article: OFF: Changes to Fill Colour and Fill Pattern Are Not Displayed http://support.microsoft.com/?id=320531 -- Regards Frank Kabel Frankfurt, Germany "ron" <roncyn@bresnan.net> schrieb im Newsbeitrag news:#Ro$W7fOEHA.556@tk2msftngp13.phx.gbl... > Fill-in color does not show on worksheet while working on the sheet only in > the pr...

OWA - change password
Getting the "Object Required" error, when somebody is trying to change their password through OWA. (Win2003/Ex FE 2003) Any ideas what could be causing this? TIA! / Per Did you follow the steps in: http://support.microsoft.com/kb/297121 ? -- Pablo D. Vernocchi Microsoft Exchange MVP MCSA + M / MCSE + Sec https://mvp.support.microsoft.com/profile=8E94A6C0-F6D9-4686-96D5-04230CC0141F http://www.itpros.com.ar http://www.msglue.org http://msmvps.com/exchangebloglatino "Per Hagstrom" <per.hagstrom@swic.eduNOSPAM> wrote in message news:Ojo%23EozNHHA.1240@TK2...

OWA changing password
I'm trying to change my password through Options in Outlook Web Access. I get the following error number - 2147023569. Try researching in KB without success. Has anyone run into this problem before? Contact your mail administrator or ask in an Exchange newsgroup as OWA is part of Exchange; not Outlook -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -Backup and Restore -Create an Office XP CD slipstreamed with Service Pack 3 ----- "cathy smyth" <anonymous@discussions.microsoft.com> wrote in message news:1f6d101c45863$6f00b360$a601280a@...

Protecting user from changing previous data
Hi All, I have a block of data A1:D10 with Protection using ALLOW USER TO EDIT RANGE. The user enter data with the following order: Input 1: A1, B1, C1, D1 Input 2: A2, B2, C2, D2 Input 3: A3, B3, C3, D3 I would like to Automatically prevent the user from changing ROW A1-D1 when Inserting NEW ROWS (Row A2-D2, Row A3-D3). Thank you. This can be a very complex issue if you don't think things out really well ahead of time. What happens if, after they've typed data in A1:D1 and while entering more data in rows below row 1, they realize they made a mistake...