WTL Subclassing

This is a discussion on WTL Subclassing within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to subclass an edit control using WTL. I am using this article for instruction http://www.codeproject.com/wtl/subcl...ditcontrol.asp So, basically, what ...

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    WTL Subclassing

    I'm trying to subclass an edit control using WTL. I am using this article for instruction

    http://www.codeproject.com/wtl/subcl...ditcontrol.asp

    So, basically, what I have, is a bunch of edit boxes that I create from a rc template, and my edit control subclass (in the article, this is CEditEnterAsTabT, in my code it's CEditArrowsT), and when I try to AttachToDlgItem (actually subclass the edit controls) in my dialogs OnInitDlg routine.

    AttachToDlgItem

    Code:
    	BOOL AttachToDlgItem(HWND parent, UINT dlgID)
    	{
    		m_dlgItem = dlgID;
    		m_parent = parent;
    		m_hWnd = ::GetDlgItem(parent, dlgID);
    		
    		return SubclassWindow(m_hWnd);
    	}
    In this method, SubclassWindow in the failiure. On MSDN it comments

    Do not call SubclassWindow if you have already called Create.
    But I don't call create, they're dialog elements programmed into the resource script. This comment is the only reason I can see for failure, is there anyway I might get around it? I might try hardcoding the edit controls into the dialog if there isn't but that seems very inconvenient.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I get error 1400 - ERROR_INVALID_WINDOW_HANDLE: Invalid window handle for each and every time I tryh it. Here is essentially the code for my dialog

    Code:
    class WtlKbdCtrlsDlg : 
    	public CDialogImpl<WtlKbdCtrlsDlg>,
    	public CDialogResize<WtlKbdCtrlsDlg>,
    	public CMessageFilter
    {
    	WtlWindow * parent;
    	CEditArrowsT<CWindow> * arr;
    
    public:
    
    	enum { IDD = IDD_KBDCTRLS };
    
    	BEGIN_MSG_MAP(CAboutDlg)
    		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
    		MESSAGE_HANDLER(WM_CLOSE, OnClose)
    		COMMAND_ID_HANDLER(IDOK, OnOKCancel)
    	END_MSG_MAP()
    
    	virtual BOOL PreTranslateMessage(MSG * msg) 
    	{
    		return IsDialogMessage(msg);
    	}
    
    	LRESULT OnInitDialog(UINT msg, WPARAM wparam, LPARAM lparam, BOOL & handled)
    	{
    		arr = new CEditArrowsT<CWindow>[16];
    		for(int i = 0; i < 16; ++i)
    		{
    			if(!arr[i].AttachToDlgItem(this->m_hWnd, IDC_NYAW + i))
    			{
    				DWORD err = ::GetLastError(); // Always 1400
    			}
    		}
    
    		CenterWindow();
    		_Module.GetMessageLoop()->AddMessageFilter(this);
    Here;s the rest

    http://zxcvbn.googlecode.com/svn/trunk/wtltrip/WtlDlg.h
    http://zxcvbn.googlecode.com/svn/trunk/wtltrip/

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I got subclassing to work, but....
    By cl2606 in forum Windows Programming
    Replies: 2
    Last Post: 07-06-2008, 04:28 PM
  2. Subclassing
    By alex0751 in forum C++ Programming
    Replies: 2
    Last Post: 01-21-2008, 06:39 PM
  3. MFC, WTL or .NET?
    By microchip in forum C++ Programming
    Replies: 7
    Last Post: 11-07-2005, 03:14 PM
  4. Subclassing Problem
    By Thunder in forum Windows Programming
    Replies: 4
    Last Post: 10-22-2003, 04:49 PM
  5. Subclassing a dialog->Calling DialogProc
    By knutso in forum Windows Programming
    Replies: 7
    Last Post: 05-20-2003, 01:33 AM

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