Thread: Constructor with Parameter not Firing

  1. #1
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Posts
    107

    Constructor with Parameter not Firing

    Okie dokie. So I am making a listbox class because it was starting to get messy in my Main. Now in order to make it more self contained I needed to pass a lot of information to the new class when it gets made.

    The problem is that the constructor doesn't seem to be getting triggered, at least it won't break in Debug inside of the constructor, the window that is supposed to created in the constructor does not.

    I am floating through my C++ books and they show a argument constructor demonstration and I mirrored it for mine.

    So with no further ado class declaration.
    Code:
    class CListbox
    {
        
        private:
            HWND m_Hwnd;
            HWND m_OwnerHwnd;
            HINSTANCE m_HInstance;
            bool Created;
            int m_nFunsterStil;
        public:
            /* Constructors */
            CListbox();
           
            CListbox(   HWND hwnd,
                        int iStartPosVertical,
                        int iStartPosHorizontal,
                        int iStyleSetting,
                        int iWidth,
                        int iHeight,
                        HINSTANCE hAppInstance,
                        int nFunsterStil);
                        
            ~CListbox();
            /* Properties */
            void hwnd(HWND l_Hwnd);
            HWND hwnd(void);
            void hinstance(HINSTANCE l_Hinstance);
            HINSTANCE hinstance(void);
            /* Methods */
            long AddString(char * pItemText);
        protected:
    
    };
    Then we have the beautiful calling code...
    Code:
    CListbox MyList(hwnd,0,40,1,520,300,hThisInstance,nFunsterStil);
    MyList.AddString(MyMsg);
    Now the code compiles (I know that doesn't mean much) and it gets to the AddString call, but the window that was supposed to be drawn in the constructor wasn't drawn.

    Now for some odd reason if I add this line....

    Code:
    CListbox Test;
    so now it looks like this
    Code:
    CListbox Test;
    CListbox MyList(hwnd,0,40,1,520,300,hThisInstance,nFunsterStil);
    MyList.AddString(MyMsg);
    The constructor appears to be triggered and works, the window is drawn, and my string is added.

    Here is the implementation code structure fyi.
    Code:
    CListbox::CListbox(HWND hwnd,
                        int iStartPosVertical,
                        int iStartPosHorizontal,
                        int iStyleSetting,
                        int iWidth,
                        int iHeight,
                        HINSTANCE hAppInstance,
                        int nFunsterStil)
    {
        /* Load Class Variables */
        m_OwnerHwnd=hwnd;
        m_HInstance=hAppInstance;
        m_nFunsterStil=nFunsterStil;
        /* Local Variables */
        long lStyleSetting;
        switch(iStyleSetting)
        {
            case 1:
                lStyleSetting=WS_CHILD|WS_VSCROLL|LBS_HASSTRINGS|LBS_DISABLENOSCROLL|LBS_WANTKEYBOARDINPUT;
                break;
            case 2:
                lStyleSetting=WS_CHILD|WS_VSCROLL|LBS_HASSTRINGS|LBS_DISABLENOSCROLL|LBS_WANTKEYBOARDINPUT;
                break;
        }
        
        if(!Created)
        {
            m_Hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               "Listbox",           /* Classname */
               "",                  /* Title Text */
               lStyleSetting, /* default window */
               iStartPosHorizontal,       /* Windows decides the position */
               iStartPosVertical,       /* where the window ends up on the screen */
               iWidth,                 /* The programs width */
               iHeight,                 /* and height in pixels */
               m_OwnerHwnd,                /* The window is a child-window to main window */
               NULL,                /* No menu */
               m_HInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
            ShowWindow(m_Hwnd,m_nFunsterStil);   
            Created=true;
        }
    
    }
    May the compiler be with you.
    Be one with the compiler, and you shall prosper greatly.

  2. #2
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Posts
    107
    Ok, I made a mistake, it seems to work when I run it in Debug mode instead of normal, so the CListbox Text; has nothing to do with it.
    May the compiler be with you.
    Be one with the compiler, and you shall prosper greatly.

  3. #3
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Posts
    107
    So either everyone is stumped, or they are stupified by my question.
    May the compiler be with you.
    Be one with the compiler, and you shall prosper greatly.

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Well i don't know if this is the problem but did you need two constructors cause it looks like you don't too me but im not that good with those sorta things yet
    Code:
            CListbox();//kinda looks useless 
           
            CListbox(   HWND hwnd,
                        int iStartPosVertical,
                        int iStartPosHorizontal,
                        int iStyleSetting,
                        int iWidth,
                        int iHeight,
                        HINSTANCE hAppInstance,
                        int nFunsterStil);
    Woop?

  5. #5
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Posts
    107
    Sorry about bumping this thread but wanted to put a conclusion of sorts to it.


    Prog-bman,
    Thanks very much for your contribution, but however constructors can be overloaded so in effect I wasn't using that default constructor but it wasn't hurting anything.


    I broke out the program into properties and I am still having issues so this thread is DONE.

    But thanks!
    May the compiler be with you.
    Be one with the compiler, and you shall prosper greatly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my error is storage class specified for parameter
    By meli in forum C Programming
    Replies: 5
    Last Post: 03-27-2009, 12:06 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM