Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone!

I would like to start by saying thanks to everyone who takes some time to view this thread and try to help.

I have subclassed tree view in my main window to make his background transparent, which works fine, but its items are not painted at all!

I am inexperienced in subclassing, so I ask more experienced members to help me modify following code, so I can get transparent tree view with all nodes displayed properly:

C++
// variable for storing old window procedure

static WNDPROC wp;

LRESULT CALLBACK wpTree(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
         switch(message)
	 {

	  case WM_PAINT:
		{
		        PAINTSTRUCT ps;

		        HDC hdc = BeginPaint(hWnd, &ps), 
                             hdcMem = CreateCompatibleDC(hdc);
		
 			RECT r;

                        // get tree view's client rectangle

			GetClientRect( hWnd, &r );

                        /* create compatible bitmap, size of tree's client 
                                                                    rectangle */

			HBITMAP bmp = CreateCompatibleBitmap( hdc, 
                                                              r.right - r.left, 
                                                              r.bottom - r.top ) , 
                                bmpOld;

			bmpOld = (HBITMAP)SelectObject( hdcMem, bmp );

                        // Blt it and make background transparent

			TransparentBlt( hdc, 0, 0, 
                                        r.right - r.left, 
                                        r.bottom - r.top, 
                                        hdcMem, 0, 0, 
                                        r.right - r.left,
                                        r.bottom - r.top, 
                                        RGB( 0, 0, 0 ) );

                        // take care for memory leak
  
			SelectObject( hdcMem, bmpOld );

                        // cleanup

			DeleteObject(bmp);

			DeleteDC(hdcMem);

			EndPaint(hWnd, &ps);

		}
		return 0L;

	case WM_ERASEBKGND:
		return 0L;
	}

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


This is how I have subclassed tree in main window procedure:

C++
case WM_CREATE:
    {
         // create tree view

         hwndTV = CreateWindowEx( ... );

         // store old procedure

         wp = (WNDPROC)GetWindowLongPtr( hwndTV, GWL_WNDPROC);

         // subclass tree

         SetWindowLongPtr( hwndTV, GWL_WNDPROC, (LONG)wpTree );

         // add some nodes to the tree
               .
               .
               .
    }


Code example, or snippet would be very helpful, but I would also appreciate written instructions as well, but make them detailed please, since I am not very experienced.

I work in MS Visual Studio Express 2008, on Windows XP, in C++, using pure WIN32 API.

That would be all, again I thank everyone who tries to help.Thank you very very much!
Posted
Updated 26-Jul-13 3:17am
v3

This forum is labelled "Quick Answers" because the questions asked should be limited in scope, and a simple quick answer should suffice.

A request like yours, for someone to spend hours of their valuable time writing code, detailed comments and explanations, doesn't fit any sort of definition of 'quick'.

There are many sites from which you can hire programmers to do work like this. You'll be much more likely to get a pleasing response from one of those.

When employers have asked me to write code of this nature, I went to this site, and found everything i needed to know.

How To subclass a CTreeCtrl[^]
 
Share this answer
 
Comments
MyOldAccount 24-Jul-13 17:40pm    
Thank you for you answer.

I do not ask people to write code for me, just to give me some advice, but maybe I have formulated my question poorly because I am getting desperate and frustrated over this issue.

I have edited my post to remove the offending sentence, and I apologize.

Yes, Google knows it all, but I need a solution in PURE Win32 API, not MFC, unfortunately, since I am a beginner.
JackDingler 25-Jul-13 9:59am    
You'll probably have to deconstruct an MFC solution then.

Developers who do this kind of work for a living, mostly avoid raw SDK programming for controls. It's costly, in that it takes more time to develop, and is difficult to maintain. I'm sure there are exceptions to this rule, but I haven't met anyone who chooses to develop overloaded controls at the SDK level in many years.
MyOldAccount 25-Jul-13 15:28pm    
I agree with you, but I am a student who tried to learn basic Win32 before going for MFC and C#.
In the meantime, I got an offer for a small job, and I took it.
However, my employers "buffed up" the original project beyond recognition, so now I am stuck...
I have done a little research, and found that tree can't be owner drawn. That leaves me custom draw or subclassing right ?
I have tried custom draw, and have posted a question here http://www.codeproject.com/Questions/625831/How-to-modify-my-custom-draw-handler-to-acheve-tra , so I am asking you as a colleague who surely has been through "my shoes" to see it and try to help.
Again, thank you very much for your comments and suggestions, I do appreciate it highly.
JackDingler 25-Jul-13 15:47pm    
My suggestion on MFC is to see if you can find an example that does something close to what you want, then follow the code path for that draw code and implement your version of it.

Remember...
Professionals Steal
Amateurs Borrow
JackDingler 25-Jul-13 15:45pm    
I honestly don't know if what you want, is possible with the Microsoft Tree Control.

But yes, the custom draw is likely the way to go. I've had difficulties in overriding the tree control behavior in the past and came close to just writing my own control.
There are additional messages that must be handled in tree view's subclassing procedure, so the nodes can be properly drawn...

I guess there is a lot of work waiting for me...
 
Share this answer
 
Comments
[no name] 28-Jul-13 18:56pm    
How does this qualify as a solution? We should all try to maintain a standard in this forum and not clog it up with thought bubbles. You have accepted your own answer?
MyOldAccount 29-Jul-13 8:21am    
The reason why I couldn't see any nodes in my tree view after subclassing it, is because additional messages must be handled in order for my subclassing procedure to work properly. That is the answer to my question: Why can't I see tree view's nodes when I subclass it this way ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900