Subcalssing…

Its just overriding/adding message hander of another similar kind window (window not necessarily to be exist)to existing same kind window.  This just dynamically overrides the event handler.

one way:

CMyButton m_MyButton; //Can be either member of the class or global variable.

m_MyButton.SubclassDlgItem(IDC_BUTTON1, this);

another way:

CMyButton m_MyButton; //Can be either member of the class or global variable.
CWnd *pWnd;
pWnd = GetDlgItem(IDC_BUTTON1);

m_MyButton.SubclassWindow(pWnd->GetSafeHwnd());

Another Way:


CWnd *pwndEdit = GetDlgItem(IDC_EDIT1);
SetWindowSubclass(pwndEdit->GetSafeHwnd(), MyWndProc, 0, 0);

LRESULT CALLBACK MyWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
switch (msg)
{
case WM_CHAR:
{
if(wParam >= 48 && wParam <= 57)
{
return TRUE;
}
}
}
return DefSubclassProc(hWnd, msg, wParam, lParam);
}

The above code will prevent all numeric key press.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: