Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. CListBox!?

CListBox!?

Scheduled Pinned Locked Moved The Lounge
helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Masoud Samimi
    wrote on last edited by
    #1

    Hi All, This is to request a HELP on the CListBox stuff! The ususal way to stuff the list box control is to use the CListBox::AddString(...) in the WM_INITDIALOG of any dilaog window! But I require this list box to initialize the contents of itself, INDEPENDENTLY! If I derive a class from the CLisBox, how/where is the place to self init the derived class? :) Any help/hint is highly appreciated! :) :) Cheers Masoud

    E 1 Reply Last reply
    0
    • M Masoud Samimi

      Hi All, This is to request a HELP on the CListBox stuff! The ususal way to stuff the list box control is to use the CListBox::AddString(...) in the WM_INITDIALOG of any dilaog window! But I require this list box to initialize the contents of itself, INDEPENDENTLY! If I derive a class from the CLisBox, how/where is the place to self init the derived class? :) Any help/hint is highly appreciated! :) :) Cheers Masoud

      E Offline
      E Offline
      Erik Funkenbusch
      wrote on last edited by
      #2

      You need to do it two places. First, you override WM_CREATE, and do it there. That takes care of dynamic creation. The one most people don't notice is that you have to override the Attach() function as well. When you use classwizard to associate a class with a dialog control, the control is created by Windows, and then the class is attached to it in the DDX. Thus, Create() is never called but Attach() is.

      M 1 Reply Last reply
      0
      • E Erik Funkenbusch

        You need to do it two places. First, you override WM_CREATE, and do it there. That takes care of dynamic creation. The one most people don't notice is that you have to override the Attach() function as well. When you use classwizard to associate a class with a dialog control, the control is created by Windows, and then the class is attached to it in the DDX. Thus, Create() is never called but Attach() is.

        M Offline
        M Offline
        Masoud Samimi
        wrote on last edited by
        #3

        Dear Erik! Hi and thanks for your reply. Just a while ago I did the override of WM_CREATE and tried the AddString("Test!"), but does not catch it here! Also am confused about the Attach(...), is this the BOOL CWnd::Attach(HWND hWndNew); function? If yes then where is the hWndNew going to be set and how? Also about your point on the DDX, when I derive from the CListBox, I also attach the derived class to a member named m_List whcih is the control's object. For both am using the calsswizard to do. And then in the OnInitDialog() am doing these:

        // Add some string
        m_List.AddString("Test1");
        m_List.AddString("Test2");
        m_List.AddString("Test3");
        m_List.AddString("Test4");

        // Select default the first item
        m_List.SetCurSel(0);

        I am confused and lost! Help with some code lines would really solve this! :) However, this thing am doing is gonna be posted here (CP) to benefit everyone else as well! :) :) Thanks in advance already! Cheers Masoud

        E 1 Reply Last reply
        0
        • M Masoud Samimi

          Dear Erik! Hi and thanks for your reply. Just a while ago I did the override of WM_CREATE and tried the AddString("Test!"), but does not catch it here! Also am confused about the Attach(...), is this the BOOL CWnd::Attach(HWND hWndNew); function? If yes then where is the hWndNew going to be set and how? Also about your point on the DDX, when I derive from the CListBox, I also attach the derived class to a member named m_List whcih is the control's object. For both am using the calsswizard to do. And then in the OnInitDialog() am doing these:

          // Add some string
          m_List.AddString("Test1");
          m_List.AddString("Test2");
          m_List.AddString("Test3");
          m_List.AddString("Test4");

          // Select default the first item
          m_List.SetCurSel(0);

          I am confused and lost! Help with some code lines would really solve this! :) However, this thing am doing is gonna be posted here (CP) to benefit everyone else as well! :) :) Thanks in advance already! Cheers Masoud

          E Offline
          E Offline
          Erik Funkenbusch
          wrote on last edited by
          #4

          A control is created two ways. The first way, dynamicly, is when you call control.Create(); This allows you to create controls on the fly whenever you want. The second way, is when you put a control on a dialog. In this way, the Create() method of class is never called because Windows creates the control, not your code. Your code merely attaches to it AFTER it's been created, thus you never get a WM_CREATE message, since your class isn't attached to the actual control until after the window has sent that message. This is all handled for you by the DDX handler for your control when you associate a class with the control in ClassWizard. However, I lead you slightly astray. It's not Attach() that you override, but PreSubclassWindow(). PreSubclassWindow() is called by Attach(). Simply call the base class first, then do whatever you need to do to the control.

          M 1 Reply Last reply
          0
          • E Erik Funkenbusch

            A control is created two ways. The first way, dynamicly, is when you call control.Create(); This allows you to create controls on the fly whenever you want. The second way, is when you put a control on a dialog. In this way, the Create() method of class is never called because Windows creates the control, not your code. Your code merely attaches to it AFTER it's been created, thus you never get a WM_CREATE message, since your class isn't attached to the actual control until after the window has sent that message. This is all handled for you by the DDX handler for your control when you associate a class with the control in ClassWizard. However, I lead you slightly astray. It's not Attach() that you override, but PreSubclassWindow(). PreSubclassWindow() is called by Attach(). Simply call the base class first, then do whatever you need to do to the control.

            M Offline
            M Offline
            Masoud Samimi
            wrote on last edited by
            #5

            Erik!,Thankyou! :) :) It was indeed the PreSubClass() guy! This just FIXED the problem! By 2 days max I'll have the documentations ready to post here on the CP. Have fun and thanx again. Cheers Masoud

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups