Jump to content
Tuts 4 You
Sign in to follow this  
mrexodia

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

Rate this topic

Recommended Posts

mrexodia

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:


case WM_CTLCOLOREDIT:
{
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...

KeyGen_example.rar

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

Edited by Mr. eXoDia (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites
paul

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='6.0.0.0' 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.

Share this post


Link to post
Share on other sites
mrexodia

@kao: thanks for your suggestion, but I've already seens that page..

@paul: good suggestion, but I already embedding a manifest in my exe

  • Like 1

Share this post


Link to post
Share on other sites
mrexodia

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:


case WM_COMMAND:
RedrawWindow((HWND)lParam, 0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE);

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

Greetings,

Mr. eXoDia

Edited by Mr. eXoDia (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites
alaphate

Mr. eXoDia,

Great share! This keygen code is elite.

Share this post


Link to post
Share on other sites
mrexodia

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 (see edit history)

Share this post


Link to post
Share on other sites
mrexodia

Smart one indeed, will keep it :)

Greetings

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×