home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright (c) 1993 by Barking Spider Software, Inc. All rights reserved
-
- Filename...: treedem2.c
-
- Version,,,,: 1.0
-
- Language...: Microsoft C/C++ 7.0
-
- Model......: Small
-
- Environment: Microsoft Windows 3.1
-
- Description: This source module demonstrates the BSS Tree Control as part
- of a dialog template. The dialog box template in treedem2.dlg
- was created with the Dialog Editor. The Dialog Editor
- is shipped with the Windows 3.1 SDK. Since the BSS Tree
- Control has custom control support built in, all that was
- required to use the tree control in the Dialog Editor was to
- select the File menu item, then select Open Custom, type in
- the path for treectrl.dll and hit return. Select New under
- the File menu item to get an empty dialog box frame.
- The Dialog Editor Toolbox will then contain a button
- representing the tree control. Select this button, drag
- the mouse over the new dialog box frame and stretch the
- custom tree control into the desired place.
-
- In the sample code below, a simple top level overlapped
- window is created with a couple of menu items. From these
- menu items, the user can create a modal dialog box or the
- user can exit the application. If the user selects the
- menu item Tree Dialog, a modal dialog box will appear that
- contains a BSS Tree Control, two edit controls, and a
- push button. In the tree control will be a root tree node.
- In the edit controls will be initial values. The first
- edit control is used for entering strings that will be text
- for future tree nodes. The second edit control excepts any
- 3 digit base 10 value. This directs how many tree nodes to
- create with the text in the first edit control when a
- user double clicks on a tree node with a closed folder.
-
- Each node displays a bitmap, an icon, and text. The bitmap
- is a folder and the icon is the infamous BSS Spider icon.
- These items demonstrate the ability of the BSS Tree Control
- to display bitmaps, icons, and text.
-
- When the user decides to quit the dialog box, hitting the
- Enter key, Esc key, or clicking on push button will exit the
- dialog box.
-
- Notes......:
-
- History....:
-
- Author.....: Peter J. Kaufman
- */
-
- #include <windows.h>
- #include "treedem2.h"
- #include "..\bscore.h"
- #include "..\bstree.h"
- #include <string.h>
- #include <stdlib.h>
-
- static char szAppName[] = "TreeDem2";
-
- HANDLE hInst ;
-
-
- /*****************************************************************************
- int PASCAL WinMain ( HANDLE hInstance,
- HANDLE hPrevInstance,
- LPSTR lpszCmdLine,
- int nCmdShow);
-
- *****************************************************************************/
-
- int PASCAL WinMain ( HANDLE hInstance,
- HANDLE hPrevInstance,
- LPSTR lpszCmd,
- int nCmdShow)
- {
- HWND hwnd ;
- MSG msg ;
- WNDCLASS wndclass ;
-
- hInst = hInstance ;
-
- if (!hPrevInstance)
- {
- wndclass.style = CS_HREDRAW | CS_VREDRAW ;
- wndclass.lpfnWndProc = TreeDemo2WndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = 0 ;
- wndclass.hInstance = hInst;
- wndclass.hIcon = LoadIcon (hInst,
- MAKEINTRESOURCE(IDR_TREEDEMO_ICON)) ;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
- wndclass.hbrBackground = COLOR_APPWORKSPACE + 1;
- wndclass.lpszMenuName = szAppName;
- wndclass.lpszClassName = szAppName;
-
- RegisterClass (&wndclass) ;
- }
-
- hwnd = CreateWindow (szAppName,
- "Barking Spider Software, Inc. Tree Demo 2 - Dialog",
- WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL);
-
- ShowWindow (hwnd, nCmdShow) ;
- UpdateWindow (hwnd) ;
-
- while (GetMessage (&msg, NULL, 0, 0))
- {
- TranslateMessage (&msg) ;
- DispatchMessage (&msg) ;
- }
- return msg.wParam ;
- }
-
-
-
- /*****************************************************************************
- long FAR PASCAL _export TreeDemo2WndProc ( HWND hwnd,
- UINT message,
- UINT wParam,
- LONG lParam)
-
- This is the window procedure for the top level window of this application.
- When the user selects the menu item Tree Dialog, a modal dialog box based on
- the dialog box template in treedem2.dlg will be created.
- *****************************************************************************/
-
- long FAR PASCAL _export TreeDemo2WndProc ( HWND hwnd,
- UINT message,
- UINT wParam,
- LONG lParam)
- {
- static FARPROC lpfnTreeDlgProc ;
- static HANDLE hInstance ;
-
- switch (message)
- {
- case WM_CREATE:
- hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
- lpfnTreeDlgProc = MakeProcInstance ((FARPROC) TreeDlgProc,
- hInstance) ;
- return 0 ;
-
- case WM_COMMAND:
- switch (wParam)
- {
- case IDM_TREE_DIALOG:
- DialogBox (hInstance,
- MAKEINTRESOURCE(IDD_DIALOG),
- hwnd,
- lpfnTreeDlgProc);
- return 0;
-
- case IDM_EXIT:
- SendMessage (hwnd, WM_CLOSE, 0, 0L) ;
- return 0;
- }
- break ;
-
- case WM_DESTROY :
- PostQuitMessage (0) ;
- return 0 ;
- }
- return DefWindowProc (hwnd, message, wParam, lParam) ;
- }
-
-
-
-
- /*****************************************************************************
- BOOL FAR PASCAL _export TreeDlgProc ( HWND hwnd,
- UINT message,
- UINT wParam,
- LONG lParam);
-
-
- This is the dialog box procedure for the dialog box template defined in
- treedem2.dlg. It manages the tree control, the edit controls, and the
- push button. The dialog boxes two primary functions are:
-
- 1) Demonstrate the tree control in a dialog box.
- 2) Allow the user to "play" with the tree control.
-
- In WM_INITDIALOG, folder bitmaps are created, the BSS Spider icon is
- loaded, the root node of the tree control is created and inserted,
- and the edit controls are initialize with valid strings and limitations.
-
- When a user double clicks on a node that has a closed folder
- bitmap, this dialog box procedure reads the strings in from the two
- edit controls. One string is the desired tree node text of future nodes
- and the other string represents the number of nodes to be added to the
- selected node as children.
-
- When the user is tire of playing with the tree control, pressing the push
- button will end the fun."
- ******************************************************************************/
- #define MAX_TEXT_LENGTH 2048 // Max number of characters to be used
- // in the tree node text. Can be increased.
- #define MAX_COUNT_DIGITS 3 // Max number of digits in the count value.
-
- char szTextBuffer [ MAX_TEXT_LENGTH + 1]; // Node text storage
- char szCountBuffer [ MAX_COUNT_DIGITS + 1]; // Node count storage
-
- HWND hwndTree; // Tree control handle
- HWND hwndCount; // Count edit control.
- HWND hwndText; // Node text edit control.
-
- // folder bitmaps
-
- HBITMAP hbmClosedActive;
- HBITMAP hbmClosed;
- HBITMAP hbmOpenActive;
- HBITMAP hbmOpen;
- HICON hSpiderIcon;
-
- BOOL FAR PASCAL _export TreeDlgProc ( HWND hwnd,
- UINT message,
- UINT wParam,
- LONG lParam)
- {
- LP_TREE_NODE lpParentTreeNode;// Pointer to tree node
- LP_TREE_NODE_DEF lpTreeNodeDef; // Pointer to tree node definition
- LP_TREE_NODE_DEF lpTreeNodeDef2;
- LP_SELECT_NOTIF lpSelectNotif; // Pointer to tree notification struct.
- WORD i,j;
- WORD wCount;
- char szBuffer[6];
- WORD wErrCode;
-
- switch (message)
- {
- case WM_INITDIALOG: // Create the root node, the folder bitmap, and
- // initialize the node text and count edit controls.
- // Get the handle of the tree control
- hwndTree = GetDlgItem (hwnd, IDC_TREE);
-
- // CreateBackgroundMatchedBitmap() is NOT an exported BSS
- // Tree Control API! It is supplied as a tool for developers to
- // mask the background of an irregular shaped bitmap to the
- // windows background color. This routine only handles 16 color
- // bit bitmaps.
-
- // CreateBackgroundMatchedBitmap creates the folders used in
- // the BSS Tree Control. CreateBackgroundMatchedBitmap does what
- // it says. It loads the initial folder bitmap from the resource,
- // and converts the bitmap's background color to match the system
- // window color. This is done for the closed and open
- // folder bitmaps.
-
- // Notice that this procedure is also done for the COLOR_HIGHLIGHT
- // color. COLOR_HIGHLIGHT is the color used to show the current
- // selection (active node). Feel free to include this and any other
- // routine in your application.
-
- hbmClosed = CreateBackgroundMatchedBitmap (
- GetSysColor (COLOR_WINDOW),
- IDR_CLOSED_FOLDER);
-
- hbmClosedActive = CreateBackgroundMatchedBitmap (
- GetSysColor (COLOR_HIGHLIGHT),
- IDR_CLOSED_FOLDER);
-
- hbmOpen = CreateBackgroundMatchedBitmap (
- GetSysColor (COLOR_WINDOW),
- IDR_OPEN_FOLDER);
-
- hbmOpenActive = CreateBackgroundMatchedBitmap (
- GetSysColor (COLOR_HIGHLIGHT),
- IDR_OPEN_FOLDER);
-
- // Bitmaps spaces are where bitmaps are placed in a tree node. The
- // bitmap spaces are placed left of the text. Below, one bitmap
- // space is defined. The max width and height are defined. The
- // first argument is the BSS Tree Control handle, the second is the
- // bitmap space identifier (which bitmap space is being defined). The
- // third and fourth arguments are the width and height respectively.
- // The last argument signals the BSS Tree Control whether to center
- // or left justify the currently assigned bitmap in this bitmap space.
- // TRUE means center, FALSE means left justify.
-
- // This defines the first bitmap space globally for every tree node.
- // This keeps column alignment per level.
-
- BST_SetBitmapSpace( hwndTree, 0, 23, 17, TRUE);
-
- // For the second bitmap space, the application must specify a
- // height and a width at least large enough to hold an ICON since
- // the application will defined an icon to be placed in the second
- // bitmap space. The required height and width are a result of the
- // Windows API, DrawIcon(), displaying the whole ICON and not
- // offering any clipping functionality. The application can determine
- // the minimum height and width bitmap space needed by the BSS Tree
- // Control, by calling the Windows API, GetSystemMetrics().
- // Calling GetSystemMetrics() with SM_CXICON will return the width
- // of an ICON and calling GetSystemMetrics() with SM_CYICON will
- // return the height of an ICON. After this is accomplished, the
- // application can place additional margins on the height and width
- // of the bitmap space for appearences.
-
- // The advantages of using ICONs instead of bitmaps is:
- // 1) Icon editors are readily available and offer flexiblity to
- // the presentation of the image.
- // 2) MORICONS.DLL offer an array of icons to use as templates
- // for original images. MORICONS.DLL is shipped with Windows 3.1.
- // 3) DrawIcon()s will repect the image created by the developer in
- // the sense of background masking, etc.
- // One major disadvantage is that the size of the ICON is fixed
- // where bitmaps can be any size and clipped to fit in a smaller
- // bitmap space.
-
- BST_SetBitmapSpace( hwndTree,
- 1,
- GetSystemMetrics (SM_CXICON) + 4,
- GetSystemMetrics (SM_CYICON) + 4,
- TRUE);
-
- hSpiderIcon = LoadIcon ( hInst, MAKEINTRESOURCE(IDR_TREEDEMO_ICON));
-
- // Now, the fun part... Defining tree nodes.
-
- // First... define the root!
-
- // Allocate 1 tree node definition space for the root. It
- // is best if this memory is initialize to zero. The tree node
- // definition structure is the vehicle that the application uses
- // to define tree nodes to the BSS Tree Control. This memory is
- // the property of the application. It's contents are copied to
- // the tree control. Once the node is defined, this memory can
- // be freed.
-
- lpTreeNodeDef = (LP_TREE_NODE_DEF)
- MAKEP( GlobalAlloc (GPTR|GMEM_SHARE,
- MAKELONG(sizeof(TREE_NODE_DEF)*1,0)),0);
-
- if(lpTreeNodeDef)
- {
- // Assign the text that will be displayed for the tree node.
-
- lpTreeNodeDef->lpszText = "You cannot have a tree without a root.";
-
- // Length of the above text.
-
- lpTreeNodeDef->wTextLength = lstrlen(lpTreeNodeDef->lpszText);
-
- // Assign bitmaps created earlier to the first bitmap space which
- // was defined earlier. PS. The active bitmap is the bitmap that
- // is displayed when the tree node is highlighted. Currently, there
- // are two bitmap spaces defined per node. If more is needed, then
- // the source can be purchased and the number of bitmap spaces can
- // be increased. In most case only two bitmaps are good enough.
- // If any of the bitmap spaces are not used, then make sure that a
- // NULL handle is assigned to the bitmap space.
-
- lpTreeNodeDef->hBitmap[0] = hbmClosed;
-
- lpTreeNodeDef->hActiveBitmap[0] = hbmClosedActive;
-
- lpTreeNodeDef->chBitmapTypeBits = 0x0002;
- lpTreeNodeDef->hBitmap[1] = hSpiderIcon;
- lpTreeNodeDef->hBitmap[2] = NULL;
-
- // No user-defined data associated with the node.
- lpTreeNodeDef->lpUserData = NULL;
- lpTreeNodeDef->wUserDataSize = 0;
-
- // Since the tree node definition structure is defined then call
- // the BST_AddChildrenToParent API. Notice the 0L value. This
- // is the indicator that this node is the root. The tree can
- // only have one root. If the root is NOT defined then calling
- // any other API will cause havoc.
-
- BST_AddChildrenToParent(hwndTree, 0L, 1,lpTreeNodeDef);
-
- // The lpTreeNode member is an important animal. When
- // BST_AddChildrenToParent is called with the tree node definitions,
- // the tree control internally allocates the memory to store the
- // tree node definition information, and assigns the pointer to this
- // memory to the tree node definition member 'lpTreeNode'. Remember,
- // the tree node definition structure is shared memory between the
- // application and the tree control. The application will use the
- // 'lpTreeNode' value for future references to the new node such as
- // adding nodes as children.
-
- FREEP(lpTreeNodeDef);
- }
- else
- {
- MessageBox (hwnd, "Out of memory.", "WM_INITDIALOG", MB_OK);
- }
- SetFocus (hwndTree);
-
- // Setup the two edit controls.
- hwndText = GetDlgItem (hwnd, IDC_NODE_TEXT);
-
- SendMessage(hwndText, EM_LIMITTEXT, MAX_TEXT_LENGTH, 0L);
- strcpy( szTextBuffer, "Barking Spider Software, Inc.");
- SendMessage(hwndText, WM_SETTEXT, 0, (LONG)((LPSTR)szTextBuffer));
-
- hwndCount = GetDlgItem (hwnd, IDC_COUNT);
-
- SendMessage(hwndCount, EM_LIMITTEXT, 3, 0L);
- SendMessage(hwndCount, WM_SETTEXT, 0, (LONG)((LPSTR)"8"));
-
- return FALSE;
-
-
- case WM_BST_SELECT_NOTIF_DBLCLK:
-
-
- // WM_BST_SELECT_NOTIF_DBLCLK is a notification message sent to
- // the application when the user double clicks on a tree node.
- // lParam is a pointer to a notification structure which is owned by
- // the tree control. DO NOT FREE THIS MEMORY OR ALL HELL WILL
- // BREAK LOOSE. The members of the SELECT_NOTIF structure consist
- // of the pointer to the tree node that was selected and a flags
- // member that describes what region of the tree node which was
- // clicked and if the tree node had children or not (OPEN or
- // CLOSED).
-
- lpSelectNotif = (LP_SELECT_NOTIF) lParam;
-
- lpParentTreeNode = lpSelectNotif->lpTreeNode;
-
- // Is the selected tree node OPENED?
-
- if(lpSelectNotif->wFlags & NODE_OPENED)
- {
- // Yes... then delete the children
-
- BST_DeleteChildrenOfParent( (HWND)wParam, lpParentTreeNode );
-
- // Close the folder. wParam is the handle of the tree control.
- BST_SetBitmapAndActiveBitmap( wParam,
- 0,
- lpParentTreeNode ,
- hbmClosed,
- hbmClosedActive);
- }
- else
- {
- // No... then open it and add children if this tree node gots them.
-
- // Get the number of new nodes to be added to the tree as
- // children of the given parent node.
- GetWindowText ( hwndCount, szCountBuffer, MAX_COUNT_DIGITS + 1);
- wCount = atoi (szCountBuffer);
-
- if(wCount) // Must have something to add.
- {
- // Get the tree node text and the length. Add a fudge factor
- // to this length.
- j = GetWindowText ( hwndText, szTextBuffer, MAX_TEXT_LENGTH + 1);
- j += 10; // 3 digits, terminating 0, space, period, etc
-
-
- // Define the children as in WM_CREATE: but use the
- // tree node pointer defined in the SELECT_NOTIF structure
- // (lParam) as the parent.
-
- lpTreeNodeDef = (LP_TREE_NODE_DEF)
- MAKEP( GlobalAlloc (GPTR|GMEM_SHARE,
- MAKELONG(sizeof(TREE_NODE_DEF)* wCount ,0)),0);
-
- if(lpTreeNodeDef)
- {
- lpTreeNodeDef2 = lpTreeNodeDef;
-
- for (i = 0;
- i < wCount;
- i++, lpTreeNodeDef2++)
- {
- if((lpTreeNodeDef2->lpszText =
- MAKEP(GlobalAlloc(GPTR|GMEM_SHARE, j),0)) != NULL)
- {
-
- szBuffer [0] = ' ';
- _itoa (i, &(szBuffer[1]), 10);
-
- lstrcpy (lpTreeNodeDef2->lpszText, (LPSTR) szTextBuffer);
- lstrcat (lpTreeNodeDef2->lpszText, szBuffer);
-
- lpTreeNodeDef2->wTextLength =
- lstrlen(lpTreeNodeDef2->lpszText);
-
- lpTreeNodeDef2->hBitmap[0] = hbmClosed;
- lpTreeNodeDef2->hActiveBitmap[0] = hbmClosedActive;
- lpTreeNodeDef2->chBitmapTypeBits = 0x0002;
- lpTreeNodeDef2->hBitmap[1] = hSpiderIcon;
- lpTreeNodeDef2->hBitmap[2] = NULL;
-
- // No user-defined data associated with the node.
- lpTreeNodeDef2->lpUserData = NULL;
- lpTreeNodeDef2->wUserDataSize = 0;
- }
- else
- {
- wCount = i;
- MessageBox ( hwnd,
- "Out of string memory.",
- "WM_BST_SELECT_NOTIF_DBLCLK",
- MB_OK);
- }
- }
- // Add 'em ...
- wErrCode = BST_AddChildrenToParent( wParam,
- lpParentTreeNode,
- wCount,
- lpTreeNodeDef);
-
- if(HandleAddChildrenError( hwnd, wErrCode) == 0)
- // Open the folder
- BST_SetBitmapAndActiveBitmap( wParam,
- 0,
- lpParentTreeNode,
- hbmOpen,
- hbmOpenActive);
-
-
- lpTreeNodeDef2 = lpTreeNodeDef;
-
- for (i = 0;
- i < wCount;
- i++, lpTreeNodeDef2++)
- {
- FREEP(lpTreeNodeDef2->lpszText);
- }
- FREEP(lpTreeNodeDef);
- }
- else
- {
- MessageBox ( hwnd,
- "Out of TREE_NODE_DEF memory.",
- "WM_BST_SELECT_NOTIF_DBLCLK",
- MB_OK);
- }
- }
- }
- return 0;
-
-
- case WM_SYSCOLORCHANGE:
-
- // Sad but true... The WM_SYSCOLORCHANGE notification has be sent
- // to the tree control since only top level windows get this
- // notification. Since the colors are going to change in the
- // tree control, better make sure that the background color of
- // the bitmaps is correct.
-
- // CreateBackgroundMatchedBitmap() is NOT an exported BSS
- // Tree Control API! It is supplied as a tool for developers to
- // mask the background of an irregular shaped bitmap to the
- // windows background color. This routine only handles 16 color
- // bit bitmaps.
-
-
- if(hwndTree)
- {
- ChangeBitmapToMatchBackground ( GetSysColor (COLOR_WINDOW),
- hbmClosed,
- IDR_CLOSED_FOLDER);
- ChangeBitmapToMatchBackground ( GetSysColor (COLOR_WINDOW),
- hbmOpen,
- IDR_OPEN_FOLDER);
- ChangeBitmapToMatchBackground ( GetSysColor (COLOR_HIGHLIGHT),
- hbmClosedActive,
- IDR_CLOSED_FOLDER);
- ChangeBitmapToMatchBackground ( GetSysColor (COLOR_HIGHLIGHT),
- hbmOpenActive,
- IDR_OPEN_FOLDER);
- SendMessage (hwndTree, message, wParam, lParam);
- }
- return TRUE;
-
- case WM_COMMAND:
- switch (wParam)
- {
- case IDOK:
- if(GetFocus () != GetDlgItem (hwnd, IDOK))
- break;
-
- case IDCANCEL:
- // Delete all nodes in the tree and free bitmap resources.
- BST_EraseTree( hwndTree);
- DeleteObject(hbmClosed);
- DeleteObject(hbmClosedActive);
- DeleteObject(hbmOpen);
- DeleteObject(hbmOpenActive);
- DestroyIcon(hSpiderIcon);
- EndDialog (hwnd, TRUE) ;
- return TRUE ;
- }
- break ;
- }
- return FALSE ;
- }
-
-
-
- char * npszAddChildrenErrors [] =
- {
- "Memory allocation failure.",
- "Level limit exceeded.",
- "The number of nodes supported has been exeeded.",
- "Only on root per tree.",
- "Given parent node is invalid.",
- "Invalid error code"
- };
-
- WORD HandleAddChildrenError( HWND hwnd, WORD wErrCode)
- {
- WORD i;
-
- switch (wErrCode)
- {
- case BST_NO_ERROR:
- i = 0;
- break;
-
- case BST_ERR_MEMORY_ALLOC_FAILED:
- i = 1;
- break;
-
- case BST_ERR_LEVEL_LIMIT_EXCEEDED:
- i = 2;
- break;
-
- case BST_ERR_TOO_MANY_NODES:
- i = 3;
- break;
-
- case BST_ERR_ONLY_ONE_ROOT_ALLOWED:
- i = 4;
- break;
-
- case BST_ERR_INVALID_PARENT_FOR_INSERTION:
- i = 5;
- break;
-
- default:
- i = 6;
- break;
- }
- if ( i != 0)
- {
- MessageBox ( hwnd,
- npszAddChildrenErrors[i-1],
- "BST_AddChildrenToParent",
- MB_OK);
- }
- return i;
- }
-
-
- /***************************************************************************/
- /* Below are support routines for the 16 color bitmaps used in the tree */
- // Enjoy!
-
- HBITMAP CreateBackgroundMatchedBitmap (DWORD dwrgbBackground, int nBitmapResouce)
- {
- HANDLE hBitmap;
- HANDLE hRes;
- HANDLE hResMem;
- LPBITMAPINFOHEADER lpbi;
- DWORD FAR * lpColorTable;
- LPSTR lpBits;
- int bc;
- HDC hdc;
-
- hRes = FindResource ( hInst,
- MAKEINTRESOURCE (nBitmapResouce),
- RT_BITMAP);
-
- hResMem = LoadResource (hInst, hRes);
- lpbi = (LPBITMAPINFOHEADER) LockResource (hResMem);
-
- lpColorTable = (DWORD FAR *)(lpbi + 1);
- lpBits = (LPSTR) (lpColorTable + 16);
-
- bc = (lpBits[0] & 0xF0) >> 4;
-
- lpColorTable [bc] = RGB( GetBValue (dwrgbBackground),
- GetGValue (dwrgbBackground),
- GetRValue (dwrgbBackground));
- hdc = GetDC(NULL);
- hBitmap = CreateDIBitmap ( hdc,
- lpbi,
- (DWORD) CBM_INIT,
- lpBits,
- (LPBITMAPINFO) lpbi,
- DIB_RGB_COLORS);
- ReleaseDC(NULL, hdc);
- UnlockResource (hResMem);
- FreeResource(hResMem);
- return hBitmap;
- }
-
-
- char rgchBits [2048];
-
- short ChangeBitmapToMatchBackground ( DWORD dwrgbBackground,
- HANDLE hBitmap,
- int nBitmapResouce)
- {
- int bc;
- HDC hdc;
- LPBITMAPINFO lpbi;
- HANDLE hRes;
- HANDLE hResMem;
-
- hRes = FindResource ( hInst,
- MAKEINTRESOURCE (nBitmapResouce),
- RT_BITMAP);
-
- hResMem = LoadResource (hInst, hRes);
- lpbi = ( LPBITMAPINFO ) LockResource (hResMem);
-
- hdc = GetDC (NULL);
-
- GetDIBits ( hdc,
- hBitmap,
- 0,
- LOWORD(lpbi->bmiHeader.biHeight),
- rgchBits,
- lpbi,
- DIB_RGB_COLORS);
-
- bc = (rgchBits[0] & 0xF0) >> 4;
-
- lpbi->bmiColors[bc].rgbBlue = GetBValue (dwrgbBackground);
- lpbi->bmiColors[bc].rgbGreen = GetGValue (dwrgbBackground);
- lpbi->bmiColors[bc].rgbRed = GetRValue (dwrgbBackground);
- lpbi->bmiColors[bc].rgbReserved = 0;
-
- SetDIBits(hdc,
- hBitmap,
- 0,
- LOWORD(lpbi->bmiHeader.biHeight),
- rgchBits,
- lpbi,
- DIB_RGB_COLORS);
-
- ReleaseDC(NULL, hdc );
- UnlockResource (hResMem);
- FreeResource(hResMem);
- return 0;
- }
-
- /*--------------------------------- EOF -----------------------------------*/
-
-