Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. Transparency Issues with Rebar Toolbars (C++, WIN32, VS2005) [modified]

Transparency Issues with Rebar Toolbars (C++, WIN32, VS2005) [modified]

Scheduled Pinned Locked Moved Windows API
c++delphicssgraphicshelp
5 Posts 2 Posters 13 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    D G McKay
    wrote on last edited by
    #1

    I've recently updated the look of a WIN32 application under VS2005 by incorporating a common controls manifest. Everything seems to be operating fine, and I've updated some toolbar-within-a-rebar items with a greater colour depth and transparency. I have an annoying issue with a self-drawn toolbar item which creates a bank of toggleable mini-LEDs using two half-height bitmaps (on & off) with an alpha channel. The initial display is fine, but, on toggling, the existing bitmap isn't cleared, and so successive toggles end up darker (ie the transparent areas get less transparent). See the LedProc(...) code below. I've been playing around with various methods, but nothing seems to work. I almost need some sort of WM_ERASEBKGND code which erases to transparency, if that's possible. I've ripped the code, kicking and screaming, into a basic WIN32 application. Apologies for the many shortcuts I've taken to get it to compile! Anyone got any clues?! :confused: IDI_BITMAP1 is an 79x15 standard bitmap "toolbar". IDI_BITMAP2&3 are 10x10 32-bit bitmaps.

    // ToolbarTest.cpp : Defines the entry point for the application.
    //

    #include "stdafx.h"
    #include "ToolbarTest.h"

    #include "commctrl.h"

    #define MAX_LOADSTRING 100

    // Global Variables:
    HINSTANCE hInst; // current instance
    TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
    TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

    // Forward declarations of functions included in this code module:
    ATOM MyRegisterClass(HINSTANCE hInstance);
    BOOL InitInstance(HINSTANCE, int);
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

    HWND WINAPI CreateToolbar(HWND hwndOwner);
    HWND WINAPI CreateRebar(HWND hwndOwner);
    LONG FAR PASCAL LedProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);

    int APIENTRY _tWinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nCmdShow)
    {
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable;
    
    // Initialize global strings
    LoadString(hInstance, IDS\_APP\_TITLE, szTitle, MAX\_LOADSTRING);
    LoadString(hInstance, IDC\_TOOLBARTEST, szWindowClass, MAX\_LOADSTRING);
    MyRegisterClass(hInstance);
    
    {
    	WNDCLASS win;
    	win.hCursor = NULL;
    	win.hIcon = NULL;
    	win.lpszMenuName = NULL;
    
    	win.lpszClassName = L"MY:LED";
    	win.hInstance = hIn
    
    P 1 Reply Last reply
    0
    • D D G McKay

      I've recently updated the look of a WIN32 application under VS2005 by incorporating a common controls manifest. Everything seems to be operating fine, and I've updated some toolbar-within-a-rebar items with a greater colour depth and transparency. I have an annoying issue with a self-drawn toolbar item which creates a bank of toggleable mini-LEDs using two half-height bitmaps (on & off) with an alpha channel. The initial display is fine, but, on toggling, the existing bitmap isn't cleared, and so successive toggles end up darker (ie the transparent areas get less transparent). See the LedProc(...) code below. I've been playing around with various methods, but nothing seems to work. I almost need some sort of WM_ERASEBKGND code which erases to transparency, if that's possible. I've ripped the code, kicking and screaming, into a basic WIN32 application. Apologies for the many shortcuts I've taken to get it to compile! Anyone got any clues?! :confused: IDI_BITMAP1 is an 79x15 standard bitmap "toolbar". IDI_BITMAP2&3 are 10x10 32-bit bitmaps.

      // ToolbarTest.cpp : Defines the entry point for the application.
      //

      #include "stdafx.h"
      #include "ToolbarTest.h"

      #include "commctrl.h"

      #define MAX_LOADSTRING 100

      // Global Variables:
      HINSTANCE hInst; // current instance
      TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
      TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

      // Forward declarations of functions included in this code module:
      ATOM MyRegisterClass(HINSTANCE hInstance);
      BOOL InitInstance(HINSTANCE, int);
      LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
      INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

      HWND WINAPI CreateToolbar(HWND hwndOwner);
      HWND WINAPI CreateRebar(HWND hwndOwner);
      LONG FAR PASCAL LedProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);

      int APIENTRY _tWinMain(HINSTANCE hInstance,
      HINSTANCE hPrevInstance,
      LPTSTR lpCmdLine,
      int nCmdShow)
      {
      UNREFERENCED_PARAMETER(hPrevInstance);
      UNREFERENCED_PARAMETER(lpCmdLine);

      // TODO: Place code here.
      MSG msg;
      HACCEL hAccelTable;
      
      // Initialize global strings
      LoadString(hInstance, IDS\_APP\_TITLE, szTitle, MAX\_LOADSTRING);
      LoadString(hInstance, IDC\_TOOLBARTEST, szWindowClass, MAX\_LOADSTRING);
      MyRegisterClass(hInstance);
      
      {
      	WNDCLASS win;
      	win.hCursor = NULL;
      	win.hIcon = NULL;
      	win.lpszMenuName = NULL;
      
      	win.lpszClassName = L"MY:LED";
      	win.hInstance = hIn
      
      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      You definitely are disabling the WM_ERASEBKGND processing with this code:

      case WM_ERASEBKGND:
      GetClientRect(hWnd, &Rect);
      return TRUE;

      Returning true says you processed the message. You have two fairly simple options. Number 1 seems like less work: 1) Change your WM_ERASEBKGND handler to paint the base image if your led, you can get the HDC to paint in from the wParam paremeter. Then your WM_PAINT handler should work the way you described. 2) Create a 2nd memory DC in your WM_PAINT handler for double buffering. Paint the base bitmap, then the alphablend into this 2nd memory DC. When that is done, BitBlt that to the PAINT DC. Regards, Paul

      D 2 Replies Last reply
      0
      • P Paul M Watt

        You definitely are disabling the WM_ERASEBKGND processing with this code:

        case WM_ERASEBKGND:
        GetClientRect(hWnd, &Rect);
        return TRUE;

        Returning true says you processed the message. You have two fairly simple options. Number 1 seems like less work: 1) Change your WM_ERASEBKGND handler to paint the base image if your led, you can get the HDC to paint in from the wParam paremeter. Then your WM_PAINT handler should work the way you described. 2) Create a 2nd memory DC in your WM_PAINT handler for double buffering. Paint the base bitmap, then the alphablend into this 2nd memory DC. When that is done, BitBlt that to the PAINT DC. Regards, Paul

        D Offline
        D Offline
        D G McKay
        wrote on last edited by
        #3

        Cheers, Paul, those definitely sound like a couple of useful solutions. I'm not, however, sure how to get hold of the base image for the toolbar. Under Window 7 (at least), the rebar is shaded to give a 3D feel, and so the background for the toolbar is dependent on its vertical positioning within the rebar, and the overall height of the rebar. I wonder if I could grab a single-bit-width sliver of the background from an area I know is not overpainted by the LED bitmap, and use that to "recreate" the background using one of your suggested methods? Dave.

        1 Reply Last reply
        0
        • P Paul M Watt

          You definitely are disabling the WM_ERASEBKGND processing with this code:

          case WM_ERASEBKGND:
          GetClientRect(hWnd, &Rect);
          return TRUE;

          Returning true says you processed the message. You have two fairly simple options. Number 1 seems like less work: 1) Change your WM_ERASEBKGND handler to paint the base image if your led, you can get the HDC to paint in from the wParam paremeter. Then your WM_PAINT handler should work the way you described. 2) Create a 2nd memory DC in your WM_PAINT handler for double buffering. Paint the base bitmap, then the alphablend into this 2nd memory DC. When that is done, BitBlt that to the PAINT DC. Regards, Paul

          D Offline
          D Offline
          D G McKay
          wrote on last edited by
          #4

          Eureka! A StretchBlt in the WM_ERASEBKGND handler does the trick! Thanks for the nudge in the right direction, Paul! :)

          P 1 Reply Last reply
          0
          • D D G McKay

            Eureka! A StretchBlt in the WM_ERASEBKGND handler does the trick! Thanks for the nudge in the right direction, Paul! :)

            P Offline
            P Offline
            Paul M Watt
            wrote on last edited by
            #5

            Great! I am glad YOU worked it out, and that I could help. Regards,

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups