Problem with Listbox and Subclassing

This is a discussion on Problem with Listbox and Subclassing within the Windows Programming forums, part of the Platform Specific Boards category; The code in red is where I think the problem lies. This is how I create the ListBox (I would ...

  1. #1
    Registered User KonArtis's Avatar
    Join Date
    Mar 2003
    Posts
    34

    Problem with Listbox and Subclassing

    The code in red is where I think the problem lies.

    This is how I create the ListBox (I would specifiy "LISTBOX" in the pszType field):
    Code:
    void cCHILDWINDOW::Create(const char *pszType, HWND hwnd, int cx, int cy, int x, int y, DWORD dwStyle, DWORD dwExStyle)
    {
    	this->hParent=hwnd;
    	this->hwnd=CreateWindowEx(dwExStyle, pszType, NULL, dwStyle | WS_CHILD | WS_VISIBLE, 
    							x, y, cx, cy, hParent, NULL, 0, NULL);
    
    	
    	OldChildProc=(WNDPROC)SetWindowLong(this->hwnd, GWL_WNDPROC, (LONG)ChildProc);
    	SendMessage(this->hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
    }
    Here is the procedure for the subclass:
    Code:
    LRESULT CALLBACK cCHILDWINDOW::ChildProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	cCHILDWINDOW **TempChild;
    	cLINKEDLIST<cCHILDWINDOW*> *ChildWindow=&cWINDOW::ChildWindow;
    
    	if ( ChildWindow->Count() )
    	{
    		//Finds the window message was sent to
    		ChildWindow->Reset();
    		do
    		{
    			if ( hwnd==**(TempChild=ChildWindow->Node()) )
    				break;
    		}
    		while ( ChildWindow->Next() );
    
    		//Call the default function for default actions to happen
    		CallWindowProc((*TempChild)->OldChildProc, (*TempChild)->hwnd, message, wParam, lParam);
    		(*TempChild)->ProcessEvents(hwnd, message, wParam, lParam);
    	}
    
    	return 1;
    }
    The problem is that when I try to get the listbox count it always says its one. Even with the CallWindowProc included.

    Does anyone know why this is happening?

    Thanks

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Try..........

    if you use the WS_CHILD style then the HMENU param becomes the controls resource ID number. You set the ID of all controls to 0.
    You can't have two controls with the same resource ID on the same dialog/window.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,264
    Try the following:

    Code:
    	if ( ChildWindow->Count() )
    	{
    		//Finds the window message was sent to
    		ChildWindow->Reset();
    		do
    		{
    			if ( hwnd==**(TempChild=ChildWindow->Node()) )
    				break;
    		}
    		while ( ChildWindow->Next() );
    
    
    		(*TempChild)->ProcessEvents(hwnd, message, wParam, lParam);
    	}
    
    	return CallWindowProc((*TempChild)->OldChildProc,hwnd, message, wParam, lParam);;
    CallWindowProc needs to be called every time, not just when your if statement evaluates to true.

  4. #4
    Registered User KonArtis's Avatar
    Join Date
    Mar 2003
    Posts
    34
    Thanks bithub! That worked

    Joe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Subclassing a listbox and the speed of the postal service
    By SMurf in forum Windows Programming
    Replies: 3
    Last Post: 09-14-2002, 08:25 PM

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