CWnd::ModifyStyle Problem

This is a discussion on CWnd::ModifyStyle Problem within the Windows Programming forums, part of the Platform Specific Boards category; Is there a way to modify a window's style (CWnd base type) after it has been created? Here's what I've ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    28

    CWnd::ModifyStyle Problem

    Is there a way to modify a window's style (CWnd base type) after it has been created? Here's what I've been doing, and it doesn't seem to do anything. I'm using MFC to create my windows.

    Code:
    // Assume myBox is a CListBox, already created
    int result;
    result = myBox.ModifyStyle(0, LBS_EXTENDEDSEL, 0);
    Now when I run this, result gets the value of 1, which according to the help files means it successfully modified the style. Yet when I go to click on stuff in the list box, I can't select more than one item. If I set the LBS_EXTENDEDSEL flag when using the resource editor, it lets me select more than one item in the box, but using this way it doesn't.

    Depending on what I'm sticking in myBox, then I may or may not want the user to be able to select more than 1 item. Any way to do this, other than making 2 list box's and hiding one?
    -Grunt (Malek)

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is SetExtendedStyle().

    CListCtrl listCltr = GetListCtrl();
    listCltr.SetExtendedStyle(listCltr GetExtendedStyle() | LBS_EXTENDEDSEL);

    Kuphryn

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    28

    Hmm...

    SetExtendedStyle does not appear to be a function for CListBox. I tried using ModifyStyleEx, which supposedly lets me modify extended styles, but that doesn't appear to work either.

    I've tried creating my own CListBox class using the normal CListBox class as the base, and tried changing the style in there. But as far as I can tell, the CListBox::Create function never gets called, as my breakpoint I put in there never happened. I tried putting in in several other places, like PreCreateWindow, or the Constructor of the object, but none of that seemed to work, and sticking it in the constructor crashed the program.

    In the dialog box that creates and uses the CListBox, I tried putting the ModifyStyle in when I override the InitDialog() function, but if I stick it in afterwards, it does nothing. If I stick it in before it calls the CWnd::InitDialog(), then it crashes. Again, CDialog does not appear to call its own Create function somehow, as any breakpoint I stuck in there never happened.

    Any other ideas?
    -Grunt (Malek)

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Can you get a hold of CListCtrl via GetListCtrl()?

    Kuphryn

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    28

    Came up with something...

    I can't seem get get a hold of a CListCtrl, the help files say that belongs to a CListView, and I'm using a CListBox, so I dont think I can use that. When searching the web more trying to find some way to do it, I came across a brief tutorial that says its impossible to modify the style after its been created, and it suggested destroying and recreating the box every time you wanted a style. So I played around with creating a CListBox at run time, and managed to get it to do what I want. Takes a little bit more coding, but it seems to work.

    Thanks for suggestions though.
    -Grunt (Malek)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21