Marco Luzzara February 2016

subclassing child window c++

I am working on windows and i chose the c++ as language. My application is a win32 application and I am not using MFC classes, but only the native API.

My main window contain a Tab control in which there is a Listview control. I tried to Subclass both the control, but it is not working even though i follow the msdn guide.

The function I used are: SetWindowLong and GetWindowLong so I changed the child's procedures but it seems the main window catches every messages that controls send ( through WM_NOTIFY ) and every WM messages. I thought that it may concern focus but I do not have any idea on how implement this kind of situation: a child control which is the parent of an another child control.

I have created the Tab control in this way. code:

hwndTab = CreateWindow(WC_TABCONTROL, "",
    WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
    0, 0, rcClient.right, rcClient.bottom,
    winHandle, NULL, hInst, NULL);

OldUserTabProc = (WNDPROC)GetWindowLong(hwndTab, GWL_WNDPROC);
SetWindowLong(hwndTab, GWL_WNDPROC, (LONG_PTR)UserTabProc);

Here The Tab control procedure

LRESULT CALLBACK UserTabProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
  switch ( message )
  {
  case WM_LBUTTONDOWN:
    break;
  case WM_RBUTTONUP:
    break;
  case TCN_SELCHANGE:
  {
    userCurrentTab = TabCtrl_GetCurSel( userTab );
    break;
  }
  case TCN_SELCHANGING:
  {
    break;
  }
  };

  return CallWindowProc( OldUserTabProc, hWnd, message, wParam, lParam );
}

The listview has as parent the Tab control.

Answers


Adrian McCarthy February 2016

Values like TCN_SELCHANGE are not message types and they aren't sent to the control themselves. They are notifications (the N stands for "notification"). Notifications are sent by the control to the parent using a message like WM_NOTIFY or WM_COMMAND. You cannot intercept them by subclassing the control.

If you want to change the way the parent handles those notifications, you need to subclass the parent.

Post Status

Asked in February 2016
Viewed 2,403 times
Voted 5
Answered 1 times

Search




Leave an answer