Jump to content
Tuts 4 You

[SOLVED] [C++, WinApi] Transparent EditBox


Recommended Posts

Hey everyone,

Today I've wasted quite a lot of hours with trying to make a transparent edit box, which operates properly.

I managed to create this transparent background, but when I typ is stuff or remove stuff it goes all bad (on windows xp only)

I use this code to make the edit transparent:

RECT rect_edit= {0};
RECT rect_window= {0};
GetWindowRect(hwndDlg, &rect_window); //Window placement
GetWindowRect((HWND)lParam, &rect_edit); //Control placement SetBkMode((HDC) wParam, TRANSPARENT); //Transparent control
SetTextColor((HDC) wParam, RGB(255, 255, 255)); //White text
//Set the brush origin (relative placement)
SetBrushOrgEx((HDC)wParam, rect_window.left-rect_edit.left, rect_window.top-rect_edit.top, 0);
return (BOOL)hBrush;

My question to you guys: What should I do? Maybe handle some messages and force redraw?

Thanks in advance,

Mr. eXoDia

PS I attached the full source code...


PS2 For the ones who cannot download my source: http://codepad.org/ajqIvwl1

Edited by Mr. eXoDia
  • Like 1
Link to comment

If you're using MSVC , try adding this to your main cpp file.

#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' ""version='' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")

Don't really know if it'll help in your case but I used to have issues with the way controls showed up in XP as well and this fixed it back in the day.

Link to comment

I solved it!

Basically the only thing I had to do was redrawing the window every time the user entered something in the text box. I simply added:


Thanks for all your suggestions, hopefully this is helpful to somebody else too!


Mr. eXoDia

Edited by Mr. eXoDia
  • Like 1
Link to comment
  • 2 weeks later...

Mr. eXoDia,

Great share! This keygen code is elite.

Hehe, not THAT elite though... Try dragging another window so it overlaps the keygen window and then type stuff in the editbox. It still fails :(

Edited by Mr. eXoDia
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...