Click here to Skip to main content
Email Password   helpLost your password?

screenshot - pellucid.gif

Note: this would run only under Windows 2000 and the successors.

Introduction

Well - some time ago I wrote a few lines of code which came out to be a hit to some companies. This happened nearly 10 years ago. Those people were used to rent a software - so I finally gave in :)

Nowadays nearly everything is going to get not cheaper - I thought this would be the right time to give my old settled customers the opportunity to pay back my patience. I changed nearly every bit of code I knew working well to some code I expect to do the same ;) I didn't touch a piece of code on which I forgot the usage, so it wasn't much to do!

Multithreading, Inter Process Communication, Kernel Mode Execution, Native API-Support - hmmm, this you can talk to a sales engineer for centuries, he would keep on looking the same cool inter-face which means - he doesn't know what's going on but he has the key to the safe.

Time to posh up my UI ( Unique Identity - also known as User Interface )

My program is used by officials in charge - means: busy, critical on every change that doesn't make them do their job better.

They do need some information temporary but also need to view what they have in front with no change. This sounds like a popup window is needed and indeed this is what I have done there. The general feedback was: Yes we need what you show in your popup, and thanks, really nice but: We also need to see the things underneath the popup so we always don't have to move your information popup window around on the screen. Not so nice.

Pellucid was born. A popup-window showing the additional information in a flexible way by letting view the covered section of the original window. Reducing the amount of window-moves while looking cool.

This code does not work on machines with OS-versions lower than W2K because of the usage of window style WS_EX_LAYERED.

The classes

There are 3 classes doing the whole work:

PellucidChild is derived from CWnd and functions as a shell for the original control. It replaces the control's window procedure with its own. The reason for this was the requirement for the control being dragged by mouse as you do this on main windows by dragging the caption bar.

PellucidSelf is derived from CFrameWnd because this gives the opportunity of being placed anywhere on the screen. PellucidSelf becomes the parent of PellucidChild

Pellucid is the shell setting up all required connections between the original control, PellucidSelf and PellucidChild. It also makes the transparency by calling the appropriate functions in Pellucid::CreateSelf().

Usage

  1. Include the header Pellucid.h where you want the transparent windows to be shown e.g.: MainFrm.h or any CDialog-derived window or ...
  2. Add member variables of type Pellucid
  3. Add member variables of type of control you want to be shown e.g. CEdit, CTreeCtrl ...
  4. Create the control by using the appropriate Create functions
  5. Create Pellucid
  6. If you want to process the notification messages send by the controls then you have to insert message handler for WM_COMMAND and WM_NOTIFY messages
  7. If you are done with Pellucid - the destructor will do the job or just call Pellucid::Destroy()

Sample for 1,2,3

///////////////////////////////////////////////////////////

// >> demo extension

//

#include "Pellucid.h"

///////////////////////////////////////////////////////////

// << demo extension

//

#include "ChildView.h"

class CMainFrame : public CFrameWnd
{
public:
    CMainFrame();
protected:
    DECLARE_DYNAMIC(CMainFrame)
// Attributes

public:
///////////////////////////////////////////////////////////

// >> demo extension

//

    Pellucid m_pellucid1;
    Pellucid m_pellucid2;
    Pellucid m_pellucid3;
    Pellucid m_pellucid4;
    Pellucid m_pellucid5;
    Pellucid m_pellucid6;
    CListBox m_listbox;
    CEdit m_edit;
    CTreeCtrl m_tree;
    CButton m_button;
    CButton m_button2;
    CButton m_checkbox;
///////////////////////////////////////////////////////////

// << demo extension

//

Sample for 4,5

///////////////////////////////////////////////////////////

// << demo extension

//

void CMainFrame::OnShow()
{
///////////////////////////////////////////////////////////

// >> demo extension

//

    int id = 42;
    m_listbox.Create (WS_CHILD | WS_VSCROLL | LBS_NOTIFY, 
                                    CRect(0,0,0,0),this,id);
    int i;
    // add some fake data to the listbox

    for(i = 0; i < 100; i ++) {
        CString s;
        s.Format (TEXT("listboxitem %d"),i+1);
        m_listbox.AddString (s);
    }
    CRect rw; // parent rectangle

    GetWindowRect(rw);
    CRect rp; // pellucid rectangle

    rp.SetRect (rw.left + 20,rw.top + 70,rw.left + 220,rw.top + 250);
    // m_pellucid1 is a container for m_listbox

    // note: the rectangle for the container is in screen coordinates,

    // the child rectangle is in client coordinates regarding to the

    // container

    m_pellucid1.Create (
        this,         // parent

        rp,         // position and size in screen coordinates

        &m_listbox,     // childwindow to capture

                // position and size of child

        CRect(15,15,rp.Width() - 15,rp.Height () - 15)
    );
    ///////////////////////////////////////////////////////

    //

    // Next pellucid plz - an edit control capture by pellucid2

    //

    id ++;
    m_edit.Create (WS_CHILD | ES_WANTRETURN | ES_MULTILINE, 
                                   CRect(0,0,0,0),this,id);
    m_edit.SetWindowText (TEXT("this editcontrol\r\nis made for you"));
    // m_pellucid2 is a container for m_edit

    rp.OffsetRect (rp.Width () + 10,0);
    rp.bottom = rp.top + 400;
    m_pellucid2.Create (
        this,           // parent

        rp,             // position and size in screen coordinates

        &m_edit,        // childwindow to capture

        CRect(15,15,185,375),     // position and size of child

        CSize(0,0),     // rounded corners ?

        RGB(0,128,128), // backgroundcolor of parent of childwindow

        170,            // how many steps to get visible

        170,            // how many steps to hide

        170,            // ( 0 == invisible .... 255 = opaque )

        true,           // special effect when mouse is over

        220);           // nearly opaque while mouse is over


...

Sample for 6

//////////////////////////////////////////////////////

// >> demo extension

//

BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
{
            // ancient controls will yell on this message

            int lw = LOWORD(wParam);
            int hw = HIWORD(wParam);
            int sel;
            TCHAR s[100];
            CString s2;
            //

            // note : this is hardcoded - replace it with your

            // own smart encoding-algorithm for identifiers

            //

            if(lw == 42) {
                // this is our listbox thing

                switch(hw) {
                case LBN_SELCHANGE:
                    sel = ::SendMessage ((HWND) lParam,LB_GETCURSEL,0,0);
                    ::SendMessage((HWND)lParam,
                        LB_GETTEXT,sel,(LONG)(LPSTR)s);
                    SetWindowText(s);                            
                    break;
                case LBN_DBLCLK:
                    sel = ::SendMessage ((HWND) lParam,LB_GETCURSEL,0,0);
                    ::SendMessage((HWND)lParam,
                        LB_GETTEXT,sel,(LONG)(LPSTR)s);
                    s2 = s;
                    s2 +=  " double clicked";
                    SetWindowText(s2); 
                    break;
                }
            }

...


BOOL CMainFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
            // some controls feel special so they yell on this ....

            NMHDR *pnmhdr;
            pnmhdr = (NMHDR*)lParam;
            CString s;
            bool treeee = false;
            if(wParam == 44) {
               switch(pnmhdr->code) {
               case NM_CLICK:
                  s = " treecntrl click";
                  treeee = true;
                  break;
               case NM_DBLCLK:
                  s = " treecntrl dblclk";
                  treeee = true;
                  break;
                        }
               if(treeee)
                  // this is our tree thing

                  SetWindowText(s);
            }
           
            return CFrameWnd::OnNotify(wParam, lParam, pResult);
}

Sample for 7

void CMainFrame::OnPellucidDestroy()
{
   m_pellucid1.Destroy();
   m_pellucid2.Destroy ();
}
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralAdding string to a listbox
GoranPrpic
17:23 4 Nov '06  
I've created another menu item (Add_string) and it is supposed to do:

void CMainFrame::OnAddString()
{
m_listbox.AddString ("just a simple add");
}

Well the bottom line is it doesn't add string to the listbox. Any comments are welcome. I'm a newbie so please try to be nice Smile
Generallike vista
TheCardinal
17:13 22 May '06  
how do you do tranparent window without making the control inside the form to transparent? like in windows vista? can it be done using winXP?
GeneralNice piece of Coding...
mjpetersonsc
16:22 4 Aug '03  
very creative.
Generalwhat about the pellucid act like a child of the main window?
skygg
16:28 9 Jun '03  

i do'nt need mouse drag at all
just let the pellucid at least act like a child of the main window,move with main widow
respond to all his window messages...
how can i do this?

Confused Rose
GeneralNeed controls' position all in dialog and process all their notification messages,
skygg
4:26 9 Jun '03  
When i use these classea,the controls do'nt positioned in their parent window and do'nt move with their parent window at all?

also why i have to insert messagehandler for WM_COMMAND and WM_NOTIFY messages ?Do the winproc function hide all window messages?
can i process some in their own classes' message fuctions?


THANk u very much

Confused Rose Rose
Generalbackward compatible
bluntagain
8:47 19 Apr '02  
Hello, Franz. Thanks for your great work. Just wonder if you even think of making this class backward compatible to other window platforms? any tips on this topic? anyone did anything about it... please advise.
Generalno move
Franz Brunner
13:42 30 Jan '02  
LRESULT PellucidChild::
WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
         ....
         case WM_MOUSEMOVE:
               .....
               // do not allow to move the window
               if(wParam & MK_LBUTTON) {  
          break;
               ....

GeneralObject position
Guido Orellana
7:26 30 Jan '02  
Another little question:

How do I prevent the child window from moving?

thanks in advance.
Guido.
Generalmissing functions - missing constants
Franz Brunner
10:44 29 Jan '02  
please note: to compile the demo or to include the sources into your own project you have to install the latest Platform SDK-files (well, for this special matter it will work on SDK's from last millenium Wink )
The functions essential to this demo are prototyped in winuser.h as well as the constants (LWA_ALPHA etc. )
The winuser.h distributed with your developement environment may not meet the requirements.
If you install the Platform SDK-files make sure you set the search path for the new files (new and enhanced winuser.h) in front of all your ordinary include files.

GeneralGuido's question
Franz Brunner
10:28 29 Jan '02  
//////////////////////////////////////////////////////
// >> Guido's extension
//

// extension made in file Pellucid.h
// i made some extensions (to access the private members)
class Pellucid  
{
     ....
public:
     CWnd* GetPellucid() { return (CWnd*)m_pWndSelf; };
     CWnd* GetChild() { return (CWnd*)m_pChild;     };
     .....

// extension made in MainFrm.cpp
// MainFrm.cpp -> Messagehandler for a new Menuitem
// i made for this question from Guido
//
void CMainFrame::OnPellucidChangeEditText()
{
      if(m_pellucid2.GetPellucid()->GetSafeHwnd()) {
     // NOTE: there is a member variable called
     // m_pChild which is in fact the pointer
     // to the captured child window, e.g. Listbox,Edit...
     if(m_pellucid2.GetChild()->GetSafeHwnd()) {
                 // if you want to do something typical
          // you can of course cast to the real windowclass
          // captured by pellucid:
          CEdit* pEdit = (CEdit*)m_pellucid2.GetChild();
          pEdit->SetLimitText(42);
          m_pellucid2.GetChild()->
                              SetWindowText("altered text\r\nhas 2 lines now");
          } else {
                MessageBox(
                                 "pellucid2 doesn't have a valid Window Handle");
          }
     } else {
          MessageBox(
                           "you should create the pellucids"
                           " before you can change the text");
     }
}
/////////////////////////////////////////////////////////////////////////////////////
//
// << Guido's extension
//

GeneralSet Text after pellucid is created.
Guido Orellana
9:21 29 Jan '02  
How can i set text of CEdit (m_edit) control, after pellucid2 is created?

m_edit.SetWindowText("mytext"); don't work Cry

because SetWindowText stops into assert macro ASSERT(::IsWindow(m_hWnd));

Can you help me? Confused Confused
GeneralOn our 2K platform = OPAQUE
Michel Yossef David
23:39 15 Dec '01  
Nothing is transparent. On all our 2K Platform. I already installed the SDK. It compiles but...
Everyting is without transparency at all.

Do I miss something ?
Thank you
GeneralRe: On our 2K platform = OPAQUE
Davy Boy
12:43 2 Mar '02  
I have had similar problems with win2k, but solved very quickly. The solution may be simple, or beyond my grasp...

I noticed when win2k first installed, with it's VGA ultra-compatible mode, that such features as fading menus etc... were not visible. I changed to 16/24 bit colour depth, and voila, the fading effect appeared.

So, the solution may lie in the colour depth of your desktop.


Davy Boy Out
GeneralRe: On our 2K platform = OPAQUE
Mandalay
23:44 22 Jul '02  
right .. some progs uses only 16bit depth .. but some - i'doesn't meter. it's depends how your are making this window tranparent ...(layered).

----------------------------
my eng is bad, so am i .. (:
GeneralDon't compile
Anonymous
19:50 16 Sep '01  
I can't compile Sample. Because the compile don't know the function SetLayeredWindowAttributes. Can you help me?
GeneralRe: Don't compile
Christian Graus
20:02 16 Sep '01  
*sigh* Can we add a comment to the FAQ reminding people that they will need to download the Platform SDK if they want newer functions like this to compile ?

Maybe you should read the other comments for the article before asking the same question over again.

Christian

As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.

Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
GeneralIt's so cool, but the compile is failed
sun.wizard
23:31 20 Jul '01  
but the compile is failed.
It said that LWA_ALPHA not defined ......
Which .h should be included? but the MSDN say that it's include in windows.h
and implemented in user32.dll.Confused Confused
GeneralInstall the latest Platform SDK
Uwe Keim
6:51 6 Sep '01  
http://www.microsoft.com/msdownload/platformsdk/sdkupdate
--
See me: www.magerquark.de Want a job? www.zeta-software.de/jobs
GeneralIf you don't wanna install Platform SDK, get these files
npcomple
0:20 14 Jan '03  
I modified some files to compile without installing Platform SDK.
http://oldmimosa.snucse.org/~seyun/Pellucid.h
http://oldmimosa.snucse.org/~seyun/Pellucid.cpp

(It is inconvenient that I can't upload files to this bulletin directly)


Last Updated 28 Apr 2001 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010