Thread: How to change control styles

  1. #1
    Registered User
    Join Date
    Oct 2002

    Question How to change control styles

    I have a project made with the MFC Apllication Wizard based on dialogs. I have ComboBox in it, connected with the CComboBox Class within the class-wizard.

    I use the style CBS_DROPDOWNLIST.

    Now I want to change the style in CBS_DROPDOWN at run time.
    I tried the functions ModifyStyle, ModifyStyleEx, SetWindowLong, but the ComboBox never changed.

    Please help mew if you have an idea.


  2. #2
    Registered User
    Join Date
    Nov 2002
    don't know if this is possible, but you could always have a 2nd control, maybe created at runtime and destroy that pervious cbox. or you could have them both created at the same time and just keep the one invisible (with ShowWindow()) and vice versa and then back when you need the other one.

    but i dont know if you can directly change the style of a control at runtime. just a way around it if you want.

  3. #3
    Join Date
    Jan 2002
    Sometimes, when you change a control's style, the visible changes are not effected until after a successful call to SetWindowPos (API). I'm not overly familiar with mfc but a quick check of msdn reveals that ModifyStyle/ModifyStyleEx(which you have tried) have an 'nFlags' parameter for calling SetWindowPos - have you tried setting the flags for this or tried calling the API function directly after you have modified the style?

    edit: striving for new ways to misspell 'successful'
    Last edited by Ken Fitlike; 03-01-2003 at 08:49 AM.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Thanks for your solutions.

    (1) I'm still hoping their is away with one control, because otherwise I had to fill both boxes with a lot of data and it will take more memory.

    (2) Yes, I tried ModifyStyle, -Ex with the nFlags Parameter, but it doesn't work.

    I read in an Q&A paper that it is possible to change it at runtime, but the author didn't say how to do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 11:56 AM
  2. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 07:58 AM
  3. Change a control class during runtime
    By Joelito in forum Windows Programming
    Replies: 3
    Last Post: 01-12-2006, 02:13 PM
  4. help with calculating change from a dollar
    By z.tron in forum C++ Programming
    Replies: 3
    Last Post: 09-13-2002, 03:58 PM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM