Image background in a LISTVIEW item (win32)

I have a classic window, Parent, in with I create a ListView item, with CreateWindow(WC_LISTVIEW, ... Parent).

What are the messages I have to manage into the Parent window to draw a HBITMAP as background for my ListView item ?

Note : It have to work with old versions of Comctl32.dll too, since my app have to work without MSIE on Win95 or NT.

How to do this ? Code sample, maybe ?
Thank you !
LVL 2
lif081199Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lif081199Author Commented:
Edited text of question.
0
lif081199Author Commented:
Adjusted points to 200
0
LischkeCommented:
You could use WM_ERASEBKGND of the list view and blit the image to the window DC.

Ciao, Mike
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

lif081199Author Commented:
How to get this message from the parent Wnd ? with the WM_NOTIFY message ?
Have you a small code sample ?
Thanks, LiF.
0
LischkeCommented:
Unfortunately, my code wouldn't be of use for you as I'm programming with Delphi (unless you understand it?...).

The erase message is sent to the window which needs to erase the background. Just include another case in your message handler and do the blit there. Usually, it looks like:

  case (Message)
    switch WM_CREATE: ...
    swith WM_ERASEBKGND:
  end;

or something like that (can't remeber the case syntax very well). The parent window is only responsible to supply the background bitmap.

Ciao, Mike
0
lif081199Author Commented:
Yes, but the parent Window receive its one WM_ERASEBKGND.

For a TreeView, for example, this message is not send to the parent !

Should I register my own class to handle the TreeView ?


0
LischkeCommented:
This is correct, but why should the parent window get the erase message for one of its children? Shouldn't the child handle this case itself?

And yes, I would derive a new treeview class with only a little enhancement to handle the background (say, receiving a HBITMAP and handling the erase message).

Ciao, Mike
0
lif081199Author Commented:
I have solve my problem. I have to hook the window proc like this :

MyTreeView_OldWndProc = (WNDPROC)GetWindowLong(_hTV,GWL_WNDPROC);
SetWindowLong(_hTV,GWL_WNDPROC,(LONG)MyTreeViewWndProc);

and no it works. I have the WM_ERASEBKGND within my own WndProc !

Anyway, please post a message as an answer to get your points. Thank you for all your advices.

I will give you B, or A if you know how to change the bkgnd color of the text in a TreeView (or make it transparent)

Thank you,
Lionel.



0
LischkeCommented:
:-)

Okay, the background of a single tree node can be changed by handling the WM_NOTIFY message in the parent of the tree view. The code member of the NMHdr structure contains NM_CUSTOMDRAW in the case of a socalled paint cycle (i.e., the tree view needs a repaint). You need to cast NMHdr to a NMTVCustomDraw structure and can then access the member nmcd.dwDrawStage of this structure which tells you the stage of the current paint cycle. In your case you only need CDDS_ITEMPREPAINT. Set the clrTextBk member of the custom draw structure to the color you want and "Bob's your uncle" :-)

Ciao, Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lif081199Author Commented:
He he he... You fall into the trap :)

Read again the initial question :

"...
Note : It have to work with old versions of Comctl32.dll too, since my app have to work without MSIE on Win95 or NT.
...."

and NM_CUSTOMDRAW works only with Comctl32.dll v4.7 (that is MSIE 3.0 or later)

Other idea ?
0
lif081199Author Commented:
He he he... You fall into the trap :)

Read again the initial question :

"...
Note : It have to work with old versions of Comctl32.dll too, since my app have to work without MSIE on Win95 or NT.
...."

and NM_CUSTOMDRAW works only with Comctl32.dll v4.7 (that is MSIE 3.0 or later)

Other idea ?
0
LischkeCommented:
:-))) aaah you are right, my fault... Sorry, but in this case there's no chance to change the background of individual nodes or control transparency. I'm the author of TreeNT, a totally rewritten treeview for Delphi for which I had to search through all resources I could get. Believe me, I haven't found anything useful for pre 4.70 releases of Comctl32.dll and I'm quite sure you won't either...

Ciao, Mike
0
lif081199Author Commented:
You are right !
So I have persuaded my boss to install at least the v4.70 :)))))))))

Thank you a lot,
Lionel.
0
LischkeCommented:
:-)
0
lif081199Author Commented:
Euh...

I still have a problem with the back color of the text. The NM_CUSTOMDRAW is received, the CDDS_PREPAINT is ok, but not the CDDS_ITEMPREPAINT !!!
Have you an idea ?

Thank you :)

case NM_CUSTOMDRAW:
{
LPNMTVCUSTOMDRAW pd = (LPNMTVCUSTOMDRAW)ph;

if (pd->nmcd.dwDrawStage==CDDS_PREPAINT)
      return CDRF_NOTIFYITEMDRAW;
if (pd->nmcd.dwDrawStage==CDDS_ITEMPREPAINT)
{
      pd->clrTextBk = WEYellow;
      return CDRF_NEWFONT;
}
return CDRF_DODEFAULT;
}
0
LischkeCommented:
Mmmh, it *should* work. Here's a sample directly copied from MSDN:

LRESULT DoNotify (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  LPNMLISTVIEW pnm = (LPNMLISTVIEW)lParam;

  switch (pnm->hdr.code)
  {
    case NM_CUSTOMDRAW:
    {
      LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)lParam;

      if (lplvcd->nmcd.dwDrawStage == CDDS_PREPAINT)
        return CDRF_NOTIFYITEMDRAW;

      if (lplvcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
      {
        if (!(lplvcd->nmcd.dwItemSpec % 3))
          SelectObject (lplvcd->nmcd.hdc, g_hNewFont);
        else
          return CDRF_DODEFAULT;

        lplvcd->clrText = RGB(150, 75, 150);
        lplvcd->clrTextBk = RGB(255,255,255);

        return CDRF_NEWFONT;
      }
    }

    default:
      break;
  }

  return 0;
}

It is almost the same as your version so I assume you have not installed the correct ComCtl32.dll?

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.