[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to make transparent control in win32 window

Posted on 2006-11-13
19
Medium Priority
?
1,233 Views
Last Modified: 2013-11-20
Hi
i created a dialog in win32 and on that i have some bitmaps.

now i want to make some bitmap transparent.

Please help me

Raj
0
Comment
Question by:Raj_Kau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 2
19 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 17931021
Check out

http://www.codeproject.com/dialog/wintrans1.asp ("Making any application transparent in Windows 2000/XP")

and

http://www.codeproject.com/bitmap/trans_cimage.asp ("Drawing transparent bitmaps using CImage")
0
 
LVL 3

Author Comment

by:Raj_Kau
ID: 17935640
hi jkr
it make transparent but they make full window transparent not the particular cotrol or bitmap.

Raj
0
 
LVL 86

Expert Comment

by:jkr
ID: 17935660
Have you checked the 2nd article also?
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 3

Author Comment

by:Raj_Kau
ID: 17943842
jkr
i told you again what i want. i think that help u to solve my problem.

actually i want to make diffrent control whith diffrent percentage and i also want to make transparent to my window also.

i think now u help me better


Raj
0
 
LVL 1

Expert Comment

by:Mazen
ID: 17954179
Hello Raj,

  I suggest that you use PNG Images, they could be transparent images and can be loaded to win32 applications directly using GDI+.

However, if u insist on using BMP images and u need to make it transparent, you can use the function(alpha blended):

SetLayeredWindowAttributes(hwnd, 0, (255 * 70) / 100, LWA_ALPHA);

where 70 indicates that the opacity of the image is 70%. In this case, i think u need to handle every BMP as a seperate window.
Here's a link to explain how to use it:

http://msdn2.microsoft.com/en-us/library/ms997507.aspx
0
 
LVL 1

Expert Comment

by:Mazen
ID: 17954199
Going again through your comments, I want to add this: you can pass the handle of every control seperatley to this function and change the opacity of every control.

  Hope this helps.

     MJ
0
 
LVL 3

Author Comment

by:Raj_Kau
ID: 17962835
Mazen

i already try your second suggestion but its not working.


Raj
0
 
LVL 1

Expert Comment

by:Mazen
ID: 17963364
Hello Raj,

I have tried a simple application and it seems that this doesn't work if the control has WS_CHILD style. If you remove this style the controls will appear transparent, but you face other problems in this case which are related to the prosition of the controls and  resizement and movement of the parent window. I think what you can do is handle all window movement and resizement messages and relocate the controls your self.  
Note, you should use CreateWindowEx() when trying to create controls and use the extended style WS_EX_LAYERED.

I can post some code if you would like to try it or I can email u the application I worte.

     Mazen

   
0
 
LVL 3

Author Comment

by:Raj_Kau
ID: 17970597
thanks mazen
that look cool. i also will try what you suggest but please you also send.


Raj
0
 
LVL 1

Assisted Solution

by:Mazen
Mazen earned 500 total points
ID: 17970686
Hello Raj,

Here's a sample code:
      RECT rt;
      GetWindowRect(hWnd, &rt);
         hButton1 = CreateWindowEx(WS_EX_LAYERED |
            WS_EX_TRANSPARENT |
             WS_EX_TOOLWINDOW, "Button","Button 1", WS_POPUP | WS_VISIBLE ,
                               rt.left + 50, rt.top+50,
                               100, 30,
                               hWnd, NULL,
                               hInstance,
                               NULL);
      hButton2 = CreateWindowEx(WS_EX_LAYERED |
            WS_EX_TRANSPARENT |
             WS_EX_TOOLWINDOW, "Button","Button 2", WS_BORDER | WS_POPUP | WS_VISIBLE | BS_PUSHBUTTON,
                               rt.left+ 200, rt.top+ 200,
                               100, 30,
                               hWnd, NULL,
                               hInstance,
                               NULL);

                        SetLayeredWindowAttributes(hButton1, 0, (255 * 70) / 100, LWA_ALPHA);
                        SetLayeredWindowAttributes(hButton2, 0, (255 * 70) / 100, LWA_ALPHA);

Don't forget to import the library User32.lib inorder to use the function SetLayeredWindowsAttributes, here's what you can write:
//define this in the header:

#ifndef WS_EX_LAYERED
#define WS_EX_LAYERED           0x00080000
#define LWA_COLORKEY            0x00000001
#define LWA_ALPHA               0x00000002
#endif
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd,
                                  COLORREF crKey, BYTE bAlpha, DWORD dwFlags);

lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes;
/**********************/
//and this inside any intailizing function:
      HMODULE hUser32 = GetModuleHandle(_T("USER32.DLL"));
SetLayeredWindowAttributes =
                       (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,
                       "SetLayeredWindowAttributes");

Try it and let me know. Try loading an image in the background inorder to see the transparency of the controls.

    Mazen
0
 
LVL 3

Author Comment

by:Raj_Kau
ID: 18017535
mazen
 sorry for late response. that code work but i do not want to use CreateWindowEx.

can you tell me how i load PNG image.

Raj
0
 
LVL 1

Expert Comment

by:Mazen
ID: 18017564
Hello Raj,

  Here's the code that can load png images or any image type:

HDC hdc = GetDC(hWnd);
CImage m_image;
m_image.Load("c:/1.png");
m_image.Draw(hdc,0,0);
ReleaseDC(hWnd,hdc);

You have to include this inorder for CImage to work:

#include "atlimage.h"

  Regards,
     Mazen
0
 
LVL 3

Author Comment

by:Raj_Kau
ID: 18018015
Mazen
i did not able to include
#include "atlimage.h"
when i include this it give fatal error
then how i can show this image into a static control..



Raj
0
 
LVL 1

Expert Comment

by:Mazen
ID: 18018058
Raj,

Are u using VC++ 6.0? Because if so, CImage is not supported and you will get a "fatal error" if you include atlimage.h . I'll post a code that uses GDI+ in this case to load images.

If you are using .net version of visual studio, then post to me the part where u included the atlimage.h library.

Waiting for your reply.

   Regards,
     Mazen

0
 
LVL 3

Author Comment

by:Raj_Kau
ID: 18018121
Mazen

Yes i use VC++ 6.0.


Raj
0
 
LVL 3

Author Comment

by:Raj_Kau
ID: 18018125
Mazen

can you have the idea about "AlphaBlend"

Raj
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question