Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

true color image for a button

chick80chick80 Member Posts: 349
[b][red]This message was edited by chick80 at 2002-8-31 2:15:57[/red][/b][hr]
I'm writing a program that uses owner-drawn buttons.
I want to use an true color bitmap with transparency for a button.

This is the code I've written

[...]
case WM_DRAWITEM:

DRAWITEMSTRUCT *draw;
HDC hcomp;
HBITMAP hbmp;

draw = (LPDRAWITEMSTRUCT) lParam;

switch(draw->CtlID)
{
case IDC_ADD: // I want this button to display the bitmap

hbmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_PLUS));
hcomp = CreateCompatibleDC(draw->hDC);
SelectObject(hcomp, hbmp);
BitBlt(draw->hDC, 0, 0, draw->rcItem.right, draw->rcItem.bottom,
hcomp, 0, 0, SRCAND);

break;
}
break;
[...]

If I use SRCAND in BitBlt I have the transparency, but colors are ugly... if I use SRCCOPY I have very nice 32 bit colors... but no transparency.
What's the trick to have 32 bit colors && transparency???

Tnx in advance
nICO



Comments

  • KITEKITE Member Posts: 4
    Use function TransparentBlt and set KEYCOLOR to the color of a button
    ______________________
    Warm regards,
    Vladimir V. Polischuk
    AlarIT developer
    URL: http://www.alarit.com
  • GreyWolfSftwreGreyWolfSftwre Member Posts: 82
    : [b][red]This message was edited by chick80 at 2002-8-31 2:15:57[/red][/b][hr]
    : I'm writing a program that uses owner-drawn buttons.
    : I want to use an true color bitmap with transparency for a button.
    :
    : This is the code I've written
    :
    : [...]
    : case WM_DRAWITEM:
    :
    : DRAWITEMSTRUCT *draw;
    : HDC hcomp;
    : HBITMAP hbmp;
    :
    : draw = (LPDRAWITEMSTRUCT) lParam;
    :
    : switch(draw->CtlID)
    : {
    : case IDC_ADD: // I want this button to display the bitmap
    :
    : hbmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_PLUS));
    : hcomp = CreateCompatibleDC(draw->hDC);
    : SelectObject(hcomp, hbmp);
    : BitBlt(draw->hDC, 0, 0, draw->rcItem.right, draw->rcItem.bottom,
    : hcomp, 0, 0, SRCAND);
    :
    : break;
    : }
    : break;
    : [...]
    :
    : If I use SRCAND in BitBlt I have the transparency, but colors are ugly... if I use SRCCOPY I have very nice 32 bit colors... but no transparency.
    : What's the trick to have 32 bit colors && transparency???
    :
    : Tnx in advance
    : nICO

    by using transparency, the program combines the background color, and the color of the image, you can't really get the colors to be that great. one of the following raster codes might give you a more desireable effect, but by allowing the transparency, the background colors are always going to influence the appearance of the image.

    ~DaN

    [code]
    [red] Value Description [/red]
    BLACKNESS Fills the destination rectangle using the color
    associated with index 0 in the physical palette. (This
    color is black for the default physical palette.)
    CAPTUREBLT Windows 98/Me, Windows 2000/XP: Includes any windows that
    are layered on top of your window in the resulting
    image. By default, the image only contains your window.
    DSTINVERT Inverts the destination rectangle.
    MERGECOPY Merges the colors of the source rectangle with the brush
    currently selected in hdcDest, by using the Boolean AND
    operator.
    MERGEPAINT Merges the colors of the inverted source rectangle with
    the colors of the destination rectangle by using the
    Boolean OR operator.
    NOMIRRORBITMAP Windows 98/Me, Windows 2000/XP: Prevents the bitmap from
    being mirrored.
    NOTSRCCOPY Copies the inverted source rectangle to the destination.
    NOTSRCERASE Combines the colors of the source and destination
    rectangles by using the Boolean OR operator and then
    inverts the resultant color.
    PATCOPY Copies the brush currently selected in hdcDest, into the
    destination bitmap.
    PATINVERT Combines the colors of the brush currently selected in
    hdcDest, with the colors of the destination rectangle by
    using the Boolean XOR operator.
    PATPAINT Combines the colors of the brush currently selected in
    hdcDest, with the colors of the inverted source
    rectangle by using the Boolean OR operator. The result
    of this operation is combined with the colors of the
    destination rectangle by using the Boolean OR operator.
    SRCAND Combines the colors of the source and destination
    rectangles by using the Boolean AND operator.
    SRCCOPY Copies the source rectangle directly to the destination
    rectangle.
    SRCERASE Combines the inverted colors of the destination
    rectangle with the colors of the source rectangle by
    using the Boolean AND operator.
    SRCINVERT Combines the colors of the source and destination
    rectangles by using the Boolean XOR operator.
    SRCPAINT Combines the colors of the source and destination
    rectangles by using the Boolean OR operator.
    WHITENESS Fills the destination rectangle using the color
    associated with index 1 in the physical palette. (This
    color is white for the default physical palette.)
    [/code]
  • chick80chick80 Member Posts: 349
    Thanks, but I managed the problem in another way (just not using
    an image with transparency! ;-)).
    By the way, I tried using TransparentBlt, but I have a problem:
    when I link the program I get a linker error like it cannot find
    the function.
    I'm linking Msimg32.lib and I included Wingdi.h
    What else have I to do???

    nICO
  • GreyWolfSftwreGreyWolfSftwre Member Posts: 82
    : Thanks, but I managed the problem in another way (just not using
    : an image with transparency! ;-)).
    : By the way, I tried using TransparentBlt, but I have a problem:
    : when I link the program I get a linker error like it cannot find
    : the function.
    : I'm linking Msimg32.lib and I included Wingdi.h
    : What else have I to do???
    :
    : nICO
    :

    try including msimg32.lib in the project settings. under the link tab, i believe, is a long listbox, in which you put all of the libraries you are using. add it there.

    ~DaN

  • chick80chick80 Member Posts: 349
    : try including msimg32.lib in the project settings. under the link tab, i believe, is a long listbox, in which you put all of the libraries you are using. add it there.
    :
    : ~DaN

    When I said I was linking msimg32.lib, I meant I had added it there,
    but strangely, it doesn't work!
    Anyway, don't mind about it, as I resolved my problem in another way.

    Thanks a lot
    nICO
    [hr]
    [italic]How beautiful, if sorrow had not made Sorrow more beautiful than Beauty itself.[/italic]
    JOHN KEATS


  • Justin BibJustin Bib USAMember Posts: 0

    _____ | http://forcoder.org | free video tutorials and ebooks about { C# Visual Basic .NET Python C Go PL/SQL Ruby PHP Scratch Java Swift MATLAB Assembly Perl JavaScript Objective-C C++ R Delphi Visual Basic Fortran Bash Kotlin Erlang Rust COBOL Dart Lisp Logo VBScript Apex SAS Crystal LabVIEW D Lua Clojure Prolog Transact-SQL Julia FoxPro F# ABAP Scala Scheme Alice ML Ada Awk Hack } ___

Sign In or Register to comment.