VB icon

Make Transparent Forms by a Forms Picture

Email
Submitted on: 1/1/2015 9:01:00 AM
By: Shawn Elliott (from psc cd)  
Level: Beginner
User Rating: By 4 Users
Compatibility: C++ (general)
Views: 1071
 
     This will make a Form Transparent according to a Pixel of it's Picture. Be patient with me as I am learning how to code in C++. This code was ported from a project in VB by Chris Yates. However VB is horribly slow so I thought I'd make a Dll in C++ that did the same. Here's the result
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Make Transparent Forms by a Forms Picture
// Description:This will make a Form Transparent according to a Pixel of it's Picture. Be patient with me as I am learning how to code in C++. This code was ported from a project in VB by Chris Yates. However VB is horribly slow so I thought I'd make a Dll in C++ that did the same. Here's the result
// By: Shawn Elliott (from psc cd)
//
// Returns:0
//
// Side Effects:In the VB runtime you can call the Dll but the Function will do 1 of 2 things either no Transparencies will show or the whole form will disappear. However, after you compile it works fine.
//**************************************

/*This code is derived from Visual Basic code developed by :
Chris Yates
cyates@neo.rr.com
This has been ported by :
Shawn Elliott
selliott@speedgate.net
This code comes with no warranty whatsoever and is FREE for distribution without Royalty fees of any kind
*/
#include "stdafx.h"
#include "Windows.h"
#include "Windef.h"
int __stdcall MakeTransparent(HWND,int,int,int,int,int);
BOOL APIENTRY DllMain( HANDLE hModule, 
DWORD ul_reason_for_call, 
LPVOID lpReserved
					 )
{
	
return TRUE;
}
int __stdcall MakeTransparent(HWND WinHandle,int Red,int Blue, int Green,int Width,int Height)
{
/*Varaible Declarations*/
int X;
int Y;
HRGN CurRgn;
HRGN TempRgn;
bool set;
set = FALSE;
COLORREF Pixel,Transparent;
HDC hdc;
/*Assign our values*/
hdc = GetDC( WinHandle );
CurRgn = CreateRectRgn(0, 0, Width, Height);
Transparent = RGB(Red,Green,Blue);
X = 0;
Y = 0;
do
{
	do
	{
		Pixel = GetPixel(hdc,X,Y);
		if (Pixel == Transparent)
		{
				set = TRUE;
				/*This is a Pixel that we want to make transparent*/
				TempRgn = CreateRectRgn(X,Y,X + 1,Y + 1);			/*Create a Temporary Region with this Location*/
				CombineRgn(CurRgn, CurRgn, TempRgn, RGN_DIFF);		/*Combine the Temporary Region with the Created one*/
				DeleteObject(TempRgn);								/*Clean the Temporary Region from Memory*/
		}
	X = X + 1;
	if (X > Width) break;
	}while(FALSE == FALSE);
	X = 0;
	Y = Y + 1;
if (Y > Height) break;
}while(FALSE == FALSE);
/*Now we set the Region to the Calling Handle if there was any changes*/
if (set == TRUE)
{
	SetWindowRgn(WinHandle, CurRgn, TRUE);	/*Set the Region*/
}
ReleaseDC( WinHandle, hdc );
DeleteObject(CurRgn);					/*Clean up the Region we worked with*/
return 0;
} /* End Transparency */


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.