-
June 5th, 2007, 09:59 AM
#1
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
-
June 5th, 2007, 10:32 AM
#2
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.
-
June 5th, 2007, 12:24 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|