Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (2 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 made a tree view control in dialog box, using resource editor.

Tree view also has images, lines and buttons.

I just need instructions on how to make it's background transparent.

Tree's nodes also should have transparent background.

I think that I should use custom draw for this, but I am not very experienced, that is why I ask for help.

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!

EDIT #1:
------------------------------

I have tried subclassing the tree view, and got it to have transparent background, but tree's items don't show.

I am posting the code of the subclassing procedure here in hope that someone can help me with some advice:

C++
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;

			GetClientRect( hWnd, &r );

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

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

			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 ) );

			SelectObject( hdcMem, bmpOld );

			DeleteObject(bmp);

			DeleteDC(hdcMem);

			EndPaint(hWnd, &ps);

		}
		return 0L;

	case WM_ERASEBKGND:
		
		return 0L;
	}

	return CallWindowProc( wp, hWnd, message, wParam, lParam );
}
Posted
Updated 21-Jul-13 14:56pm
v2
Comments
[no name] 20-Jul-13 11:06am    
http://www.google.com/search?q=win32+transparent+tree+control
MyOldAccount 20-Jul-13 14:30pm    
I need one example in pure WIN32 API.
Unfortunately I couldn't find any, but thank you anyway...
I will keep trying.
KarstenK 22-Jul-13 5:12am    
an MFC example can manually divided in Win32-API by doing every step manually.

This task should help you to learn and understand that stuff. (it would help you to train your skills as programmer) ,-)
MyOldAccount 22-Jul-13 14:03pm    
Do you have a simple MFC example where tree's nodes and background are transparent ?

I have tried Google, of course, but I just couldn't find what I need.

Anyway, I am a beginner, I thought this site is for helping people with instructions, at least, so please help me if you can, I ask you kindly since I am desperate at this moment.

Here is outstanding and deep information about this area:

Custom Controls in Win32 API: The Basics[^]

And look at this: A custom-drawn TreeList Control[^]

BTW: customizing a MS-control is some"heavy lifting", so it isnt suitable for a beginner ;-)
 
Share this answer
 
v2
Comments
MyOldAccount 23-Jul-13 5:26am    
Thank you.

I know that customizing MS controls is hard for beginner, but I have no other choice, unfortunately :((
KarstenK 23-Jul-13 6:12am    
So work carefully through the stuff for which i posted the stuff. It is really the KNOWLEDGE you neesd. Read also the online docs in msdn.com for the API. There is a complete overview about all details.

Why have you "no other choice"?
MyOldAccount 24-Jul-13 12:01pm    
I have been through both articles you have provided.
It is just too much for me :((

I tried to find an example with the transparency in the first article, yet it only stretches the bitmap, using double buffering.At this point I just can't figure out how to achieve transparency by going through this example :((

I have tried to cope with the second article despite my lack of knowledge of MFC or Windows Forms ( I think it is written in one of those ), but I have failed miserably there as well :((.

Solution to my problem doesn't need to include subclassing, I just need instructions on how to create transparent tree view.
Something like this:

Subclass it;
Handle WM_PAINT like this:
Create compatible bitmap and compatible hdc;
Do this;
Do that;
...

If you can please help me in this manner I would be very very grateful.
I know i am a pain, but please have some understanding, we were all young and inexperienced once, and I am sure you had those days when you "hit the wall" and feel helpless.
I believe that I don't ask too much, just a small set of instruction, to help me push through this.

Thank you, again, for all the help.
KarstenK 25-Jul-13 2:14am    
One way show transparence is to draw parts of the background image in the control. For that you need to bitblt some bits from the bg image in the control in the background drawi.

Finally set the controls to transparent.

PS: as i said, it isnt a newbies jobs ;-)
MyOldAccount 25-Jul-13 4:30am    
Thank you for the reply!
Please confirm if I have understood you right:
The way I understand it, you want to say that I should copy the parent's background image into some bitmap, and then BitBlt that bitmap as my tree view's control background, right ?
There was a solution provided as a link to the project file, on StackOverflow.

Sadly, the poster of it has deleted it recently.

Still, it helped me to make an acceptable transparent tree view control.

Here is the link to the question on StackOverflow, in case that link to the solution becomes active again:

http://stackoverflow.com/questions/17888038/transparent-tree-view-control[^]
 
Share this answer
 

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