CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2005
    Posts
    478

    Subclassing Using WTL

    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.
    Windows XP, Visual Studio 2008, SVN

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Subclassing Using WTL

    SubclassWindow internally calls SetWindowLong API. If SetWindowLong fails you can call GetLastError to get extended error information. So try to call GetLastError.

  3. #3
    Join Date
    Aug 2005
    Posts
    478

    Re: Subclassing Using WTL

    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/
    Windows XP, Visual Studio 2008, SVN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured