A transparent CSTATIC control [Original] If we call a background-based dialog box, the Static control is not transparent to it. The improvement method is very simple, derived from the MFC CSTATIC, the following is the corresponding code: (Modify the control ID as other value, do not use IDC_STATIC, otherwise the variable for DDX)
/ / =========================================================================================================================================================================================== ========= //// Copyright (C) 2000-2004 iWise Technologies, co. Ltd.//////////product: q988 // file : TransparentStatic.h // Author: Tiansuit Sewed // Created: 2004.12.29 23: 40 // // Description: // Valueadded Main Program for IW98.///// Waterpub@mail.9cbs .net /// / =============================================================================================================================================================================================== ============= #pragma overce // ctransparentstatic
Class CTransparentStatic: public cstatic {declare_dynamic (cTransparentStatic)
CTransparentStatic (); virtual ~ ctransparentstatic ();
Protected: declare_message_map () public: AFX_MSG void onpaint ();
/ / =========================================================================================================================================================================================== ========= //// Copyright (C) 2000-2004 iWise Technologies, co. Ltd.//////////product: q988 // file : TransparentStatic.cpp // Author: Tiansault Sewed // Created: 2004.12.29 23: 40 // // Description: // ValueAdded Main Program for IW98.//// Waterpub@mail.9cbs .net /// / =============================================================================================================================================================================================== ============= // TRANSPARENTSTATIC.CPP: Implementation File // # include "stdafx.h" #include "transparentstatic.h"
// cTransparentStatic
Implement_dynamic (cTransparentStatic, CSTATIC) cTransparentStatic :: ctransparentStatic () {}
CTransparentStatic :: ~ ctransparentStatic () {}
Begin_Message_Map (CTRANSPARENTSTATIC, CSTIC) ON_WM_PAINT () end_MESSAGE_MAP ()
// CTransparentStatic Message Handlers
Void CTransparentStatic :: onpaint () {cpaintdc DC (this); // Device file for the control
// Get the position CRECT Client_Rect; getClientRect (Client_Rect);
// obtain text CString sztext; getWindowText (sztext);
// Get the font and select the device file cfont * pfont, * PoldFont; pfont = getFont (); PoldFont = dc.selectObject (pfont);
// Fill the device file Dc.SetBkmode (Transparent) with a transparent background;
// Display text dc.drawtext (sztext, client_rect, 0);
/ / Clear font dc.selectObject (PoldFont);} Reprinting Please note: The following background dialog is from CButtonSt, copyright belongs to: davide carabro 'davide_calabro@yahoo.com
/ / =========================================================================================================================================================================================== ========= Copyright (C) 2000-2004 iWise Technologies, Co. Ltd. Class: CBKDIALOLOGST Product: IW988 / / File: bkdialogst.h // Author: Tianda // create: 2004.12.29 23: 50 // // Description: // valueadded main program for w988.// Contact: shenzhen @ guangdong // waterpub@mail.9cbs.net========== ======================================================== #pragma ONCE
class CBkDialogST: public CDialog {public: CBkDialogST (CWnd * pParent = NULL); // Constructors standard CBkDialogST (UINT uResourceID, CWnd * pParent = NULL); CBkDialogST (LPCTSTR pszResourceID, CWnd * pParent = NULL); virtual ~ CBkDialogST ( ); // destruct
DWORD SETMODE (BYTE BYMODE, BOOL BREPAINT = true); // Set background bitmap display mode
DWORD setBitMap; // Set background bitmap DWORD setBitmap (int nbitmap); // Set background bitmap
DWORD ACTIVATEEASYMOVEMODE (BOOL BACTIVATE); // Customer area can disclose DWORD ShrinkTofit (Bool Brepaint = true); // Make the dialog only shows a background bitmap size, the upper left corner position is constant
enum {// background bitmap display mode BKDLGST_MODE_TILE, // tile BKDLGST_MODE_CENTER, // center BKDLGST_MODE_STRETCH, // stretching BKDLGST_MODE_TILETOP, // only tile row, top BKDLGST_MODE_TILEBOTTOM, // only tile row, bottom BKDLGST_MODE_TILELEFT, // only a tiled, left BKDLGST_MODE_TILERIGHT, // only one tile, right BKDLGST_MODE_TOPLEFT, // only show a map: top left BKDLGST_MODE_TOPRIGHT, // only show a map: top right BKDLGST_MODE_TOPCENTER, // only show a map: top center BKDLGST_MODE_BOTTOMLEFT , // only display a picture: bottom LEFT BKDLGST_MODE_BOTTOMRIGHT, // Online only display: bottom Right Bkdlgst_mode_bottomcenter, // Show only one image: bottom centerbkdlgst_max_modes};
Enum {bkdlgst_ok, // Function Sets Success BKDLGST_INVALIDRESOURCE, // Invalid Bitmap Resources BKDLGST_INVALIDMODE // Invalid Display Mode};
protected: // {{AFX_MSG (CBkDialogST) afx_msg BOOL OnEraseBkgnd (CDC * pDC); afx_msg void OnSize (UINT nType, int cx, int cy); //}} AFX_MSG virtual void DoDataExchange (CDataExchange * pDX); // DDX / DDV supports Virtual Void OnPOSteraseBkGnd (CDC * PDC); // Extension AFX_MSG Void OnlButtondown (Uint Nflags, CPoint Point); / / Support Mouse Drag Dialog
Static short getversioni () {return 11;} // Program version static lpctstr getversionc () {return (lpctstr) _t ("1.1");} // Program version
PRIVATE: VOID INIT (); Void FreeResources (Bool Bcheckfornull = true);
Hbitmap m_hbitmap; // Bit Handle to Bitmap DWORD M_DWWIDTH; // Bittap Width DWORD M_DWHEIGHT; // Bittap Height BYTE M_BYMODE; / / Current display mode BOOL M_BEASYMOVEMODE; / / Whether to use mouse to drag dialog box
DECLARE_MESSAGE_MAP ()}; / / =========================================== ============== Copyright (C) 2000-2004 iWise Technologies, Co. Ltd. Ltd. Class: CBKDIALOGST PRODUCT: IW988 / / FILE: BKDIALOGST.CPP / / Author : Tiangye Hand // Created: 2004.12.29 23: 50 // // Description: // Valueadded Main Program for IW98.///// Waterpub@mail.9cbs.net===== ============================================================================================================================================================================================================= == #include "stdafx.h" #include "bkdialogst.h" CBKDIALOGST :: CBKDIALOGST (cwnd * pparent / * = null * /) {init ();
CBKDIALOGST :: CBKDIALOGST (uint uresourceid, cwnd * pparent): cdialog (uresourceid, pparent) {init ();
CBKDIALOGST :: CBKDialogst (lpctstr pszresourceid, cdialog (pszresourceid, pparent) {init ();
CBKDIALOGST :: ~ CBKDIALOGST () {freeeresources ();
Void CBKDIALOGST :: DODATAEXCHANGE (CDATAEXCHANGE * PDX) {cdialog :: DODATAEXCHANGE (PDX);
Begin_MESSAGE_MAP (CBKDIALOGST, CDIALOG) ON_WM_ERASEBKGND () ON_WM_SIZE () ON_WM_LBUTTONDOWN () end_MESSAGE_MAP ()
Void CBKDIALOGST :: init () {freeeresources (false);
// Default bitmap display mode M_Bymode = bkdlgst_mode_tile;
// Customer area can drag the window m_beasymovemode = true;}
void CBkDialogST :: FreeResources (BOOL bCheckForNULL) {// offload resource if (bCheckForNULL == TRUE) {if (m_hBitmap) :: DeleteObject (m_hBitmap);} m_hBitmap = NULL; m_dwWidth = 0; m_dwHeight = 0;}
void CBkDialogST :: OnLButtonDown (UINT nFlags, CPoint point) {// the client area of the window can easily drag if (m_bEasyMoveMode == TRUE) PostMessage (WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM (point.x, point.y)); CDialog :: ONLBUTTONDOWN (NFLAGS, POINT);
DWORD CBKDIALOGST :: ActivateEasyMovemode (Bool BactiVate) {// Set whether you can discharge the window m_beasymovemode = bactivate; return bkdlgst_ok;}
DWORD CBKDIALOGST :: setBitmap (int nbitmap) {hbitmap hbitmap = null; hinstance hinstresource = null;
/ / Find the handle of bitmap resources hinstresource = AFXFINDRESOURCEHANDE (MakeintResource (nbitmap), RT_bitmap);
// Load bitmap hbitmap = (hbitmap) :: loadImage (HinstResource, makeintresource (nbitmap), image_bitmap, 0, 0, 0);
Return setBitmap (hbitmap); // Call the following function}
DWORD CBKDIALOGST :: setBitmap (hbitmap hbitmap) {int NRetValue; Bitmap Csbitmapsize
// Uninstall the resource freeResources ();
IF (hbitmap) {m_hbitmap = hbitmap;
// bitmap information acquired nRetValue = :: GetObject (hBitmap, sizeof (csBitmapSize), & csBitmapSize); if (nRetValue == 0) {// Invalid bitmap handle FreeResources (); return BKDLGST_INVALIDRESOURCE;} m_dwWidth = (DWORD) Csbitmapsize.bmwidth; // bitmap width m_dwheight = (dword) csbitmapsize.bmheight; // bitmap height}
Invalidate ();
Return bkdlgst_ok;}
DWORD CBKDIALOGST :: SETMODE (BYTE BYMODE, BOOL BREPAINT) {IF (Bymode> = BKDLGST_MAX_MODES) Return Bkdlgst_INValidMode;
/ / Set bitmap display mode m_bymode = bymode;
IF (BREPAINT == True) invalidate ();
Return bkdlgst_ok;}
DWORD CBKDIALOGST:: ShrinkTofit (Bool Brepaint) {// Makes the dialog only shows a background bitmap size, the upper left corner position is constant CRECT RWND; CRECT RCLIENT; DWORD DWDIFFCX; DWORD DWDIFFCY; :: getWindowRect (m_hwnd, & rwnd); / / Compared to the screen:: getClientRect (m_hwnd, & rclient); // Customer Zone relative to the location of the left corner of the dialog
DWDIFFCX = rwnd.width () - rclient.width (); // left and right frame width and dwdiffcy = rwnd.Height () - rclient.Height (); // dialog box title Lan and lower frame width
m_bymode = bkdlgst_mode_center; // Display mode is a pair map
/ / Calculate the border size, move it, so that only one bitmap size MoveWindow (rwnd.left, rwnd.top, dwdiffcy m_dwheight, dwdiffcy m_dwheight, dwdiffcy m_dwheight, dwdiffcy m_dwheight, dwdiffcx m_dwheight
Return bkdlgst_ok;}
Void CBKDIALOGST :: OnSize (uint ntype, int cx, int cy) {cdialog :: Onsize (NTYPE, CX, CY);
// If you have a bitmap resource, you will call if (m_hbitmap! = Null) {invalidate ();}}
Void CBKDIALOGST :: OnPosteraseBkGnd (CDC * PDC) {// Reserved Extension}
Bool CBKDIALOGST :: OneRaseBkgnd (CDC * PDC) {CRECT RWND; INT NX = 0; int NY = 0;
Bool BretValue = CDIALOG :: OneRaseBkGnd (PDC);
// Bitchart is loaded when the heavy blow background IF (m_hbitmap) {getClientRect (RWND); / / customer area location, relative to the left upper corner of the dialog
CDC DCMEMORYDC; // Target Graphics Click BMPMEMORYBITMAP; / / Bitmap CBITMAP * PBMPoldMemoryBitmap = NULL;
DcMemorydc.createCompaTibleDC (PDC); // Create a memory graphic device compatible with device files BmpMemoryBitMap.createCompAtibleBitmap (PDC, RWND.Width (), RWND.HEIGHT ()); // Initialize this memory bitmap PBMPoldMemorybitmap = (Cbitmap *) DCMEMORYDC.SELECTOBJECT (& BmpMemoryBitmap); // In the memory graphics device, this bitmap DCMEMORYDC.FILLSOLIDRECT (RWND, PDC-> getBkcolor ()); // Pack background color
CDC DCTempdc; // Source Graphics Device, bitmap HBMPoldTemPbitMap = NULL; DCTEMPDC.CREATECMMPALDC (PDC); HBMPoldTemPbitmap = (HbitMap) :: selectObject (DcTemPdc.m_hdc, m_hbitmap);
Switch (m_bymode) {case bkdlgst_mode_tile: // Table map While (NY dcTempDC, 0, 0, SRCCOPY); break; case BKDLGST_MODE_TOPCENTER: nX = ((rWnd.Width () - m_dwWidth) / 2); dcMemoryDC.BitBlt (nX, 0, m_dwWidth, m_dwHeight, & dcTempDC, 0, 0, SRCCOPY) ; break; case BKDLGST_MODE_BOTTOMLEFT: dcMemoryDC.BitBlt (0, rWnd.bottom - m_dwHeight, m_dwWidth, m_dwHeight, & dcTempDC, 0, 0, SRCCOPY); break; case BKDLGST_MODE_BOTTOMRIGHT: dcMemoryDC.BitBlt (rWnd.right - m_dwWidth, rWnd.bottom - m_dwHeight, m_dwWidth, m_dwHeight, & dcTempDC, 0, 0, SRCCOPY); break; case BKDLGST_MODE_BOTTOMCENTER: nX = ((rWnd.Width () - m_dwWidth) / 2); dcMemoryDC.BitBlt (nX, rWnd.bottom - m_dwHeight, m_dwWidth, M_dwheight, & dctempdc, 0, 0, srccopy; BREAK;} PDC-> Bitblt (0, 0, RWND.Width (), RWND.Height (), & DCMEMORYDC, 0, 0, SRCCOPY; OnPOSteraseBkGnd (& DCMEMORYDC); :: SelectObject (dcTempdc.m_hdc, hbmpoldtempbitmap); dcMemorydc.selectObject (pbmpoldmemorybitmap);} Return BretValue;