Thread: Why won't my derived controls work?!

  1. #1
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    Why won't my derived controls work?!

    Okay, can someone please explain to me the steps I have to take to add functionality to a derived control? Say I want to derive a control from CEdit, which only allows numbers (like the example in my book)

    I did everything my book said to do about creating your own derived controls, but yet it still doesn't work.

    ClassWizard->Add Class->New->Base Class: CEdit; Name: CNumericalEdit

    Add Windows Message Handler for WM_CHAR in CNumericalEdit which looks like the following:

    void CNumericalEdit::OnChar(UINT nChar, UINT nRepCount, UINT nFlags)
    {
    if (0 <= nChar && 9 >= nChar)
    {
    CEdit::OnChar(nChar, nRepCnt, nFlags);
    }
    }


    Then, ClassWizard->Member Variables->IDC_EDIT1->Add Variable->Categoty: Control; Type: CNumericalEdit

    Voila. Now to test it, we build and try typing some characters into the CNumericalEdit box... and they still freaking show up. What am I doing wrong?

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Ooooh, it is working...
    Let me explain the situation

    I have a main dialog, CColorCoder. This has a few member variables, of types CPropertyPage, and CPropertySheet.
    (CPropretyPage and CPropertySheet being Tab Control related classes)

    in CColorCoder::OnInitDialog The CPropertyPage member variables are initilized and added to the CPropertySheet variable, this is then created and positioned on the main dialog.

    Each CPropertyPage variable has a cooresponding Dialog resource which has its own correspoding class.

    Okay, now for the problem. Whenever I create one of these CNumericalEdit controls on any of the CPropertyPage dialogs, they don't work, but whenever they're on the main dialog, they do work. What do I have to do to make these controls work on dialogs other than my main one?

    I believe this has something to do with PreTranslateMessage or something on the CPropertyPage dialogs, but i'm not too sure.
    I hope this makes sense to someone, as I had trouble explaining it

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    They are children of the dialog, not main dialog.

    In CreateWindow() / CreateWindowEx()
    What HWND are you specifing as the HWND parent? Are you casting the HMENU as an int ID#?
    Is there a conflict in these ID#'s?
    Are you using MDI? (multiple document interface) as the frame may be the parent.

    (for edits with numbers only why not use ES_NUMBER ?)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    They are children of the dialog, not main dialog.
    Sorry, I don't quite understand.

    In CreateWindow() / CreateWindowEx()
    What HWND are you specifing as the HWND parent? Are you casting the HMENU as an int ID#?
    I didn't use CreateWindow or CreateWindowEx.. I'm using MFC

    Are you using MDI? (multiple document interface) as the frame may be the parent.
    Nope, Dialog based application (MFC)

    (for edits with numbers only why not use ES_NUMBER ?)
    Well this was only an example, I don't actually need the functionality of a numerical edit, although there are others.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    The msg for the ctrl is being sent ot the wrong dialog as you are probably supplying the wrong HWND value, the HWND of the main dialog not that of the property sheet.

    When you create a ctrl it is a 'child' of the dialog. The dialog is its 'parent'. You must also supply a ID# for the ctrl.

    Look at these values when you create your ctrl.

    Sorry I don't use MFC. It feel hides too much from me.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    I supplied an ID number for the control. However, all controls that are a member variable of my main dialog's class, inherit the custom behavior. All controls which are member variables of any other dialog's class, don't work correctly.

    As I said, these other dialogs are created as property sheets on my main dialog. I placed a AfxMessageBox("Hi!"); in my other classes constructor... but it never popped up. This leads me to believe that the class isn't actually connected to the dialog unless I call the dialog via DoModal or Create. Which means, I can't use custom controls on property sheets... which seems extremely constraining to me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 06-03-2009, 03:00 PM
  2. storing derived classes in a stl container
    By *DEAD* in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2008, 07:50 PM
  3. Derived class linking error
    By Enahs in forum C++ Programming
    Replies: 3
    Last Post: 11-12-2005, 10:18 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Diff between window controls and dialog controls
    By Garfield in forum Windows Programming
    Replies: 13
    Last Post: 01-18-2002, 05:49 AM