If we call a background dialog box, the Static control is very uncomfortable on it.
The improvement method is simple, derived from the MFC's CSTATIC, and below is the corresponding code:
(Modify the control ID when using it, don't be IDC_STATIC, otherwise the variable used for DDX can not be added)
/ / =========================================================================================================================================================================================== =========
//
// CopyRight (C) 2000-2004 IWISE TECHNOLOGIES, CO. LTD.
// All Rights Reserved.
//// Class: CTransparentStatic
//
// Product: IW988
// file: transparentstatic.h
// Author: Tianda has seamless
// Created: 2004.12.29 23: 40 // // Description: // Valueadded Main Program for IW988.// Contact: shenzhen @ guangdong // Waterpub@mail.9cbs.net/ / / ====== ============================================================================================================================================================================================================= =
#pragma overce
// cTransparentStatic
Class CTransparentStatic:
Public CSTATIC
{
Declare_dynamic (CTransparentStatic)
PUBLIC:
CTransparentStatic ();
Virtual ~ ctransparentStatic ();
protected:
Declare_message_map ()
PUBLIC:
AFX_MSG
Void onpaint ();
}
/ / =========================================================================================================================================================================================== ========= //// CopyRight (C) 2000-2004 iWise Technologies, Co. Ltd.// - all rights reserved./// CTRANSPARENTSTAC /
// Product: IW988
// file: transparentStatic.cpp
// Author: Tianda has seamless
// Created: 2004.12.29 23: 40 // // Description: // Valueadded Main Program for IW988.// Contact: shenzhen @ guangdong // 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); // Control device file
// get position
CRECT Client_Rect;
GetClientRect (client_Rect);
// get the 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 with a transparent background
Dc.setbkmode (transparent);
// Show text
Dc.drawtext (sztext, client_rect, 0); // Clear font
Dc.selectObject (PoldFont);
}
Reprint Please pay attention:
The following background dialog is organized from cbuttonst,
Copyright belongs to:
Davide Calabro 'Davide_calabro@yahoo.com
/ / =========================================================================================================================================================================================== ========= //// Copyright (C) 2000-2004 iWise Technologies, Co. Ltd./////// Class: CBKDIALOGST
//// Product: IW988 // file: bkdialogst.h // Author: Tianda has seamless
// Created: 2004.12.29 23:50
//// description: // valueadded main program for ing988.///// Waterpub@mail.9cbs.net/ / / ================ ==============================================================================================================================================
#pragma overce
Class CBKDIALOGST:
Public CDIALOG
{
PUBLIC:
CBKDIALOGST (CWND * PParent)
= NULL);
// Standard constructor
CBKDIALOGST (uint uresourceid, cwnd * pparent
= NULL);
CBKDIALOGST (LPCTSTSTR PSZRESOURCEID, CWND * PPARENT
= NULL);
Virtual ~ cbkdialogst ();
// destruct
DWORD SETMODE (BYTE BYMODE, BOOL BREPAINT
= TRUE);
/ / Set background bitmap display mode
DWORD setBitmap (HbitMap Hbitmap);
// Set background bitmap
DWORD SETBITMAP
INT nbitmap;
// Set background bitmap
DWord ActivateEasyMoveMode (Bool BactiVate);
// Customer area can drag at will
DWORD SHRINKTOFIT (Bool Brepaint
= TRUE);
// Make the dialog only display a background bitmap size, the position of the upper left corner is constant
ENUM {
// Background bitmap display mode
BKDLGST_MODE_TILE,
// Tile BKDLGST_MODE_CENTER,
//
BKDLGST_MODE_STRETCH,
// stretch
BKDLGST_MODE_TILETOP,
// Only tiled, TOP
BKDLGST_MODE_TILEBOTTOM,
// Only tiled, Bottom
BKDLGST_MODE_TILELEFT,
// only tile one column, Left
BKDLGST_MODE_TILERIGHT,
// Only tiled, Right
BKDLGST_MODE_TOPLEFT,
// only display a picture: Top Left
BKDLGST_MODE_TOPRIGHT,
// only display a picture: Top Right
BKDLGST_MODE_TOPCENTER,
// only display a picture: Top Center
BKDLGST_MODE_BOTTOMLEFT,
// Online only display: bottom Left
BKDLGST_MODE_BOTTOMRIGHT,
// Only show the picture: bottom Right
BKDLGST_MODE_BOTTOMCENTER,
// Only displayed a picture: bottom center
BKDLGST_MAX_MODES
}
ENUM {
BKDLGST_OK,
// Function setting success
BKDLGST_INVALIDRESOURES,
// 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 support
Virtual
Void OnPosteraseBkGnd (CDC * PDC);
// extensions
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;
// bitmap width
DWORD M_DWHEIGHT;
// bitmap height
BYTE M_BYMODE;
// Current display mode
BOOL M_BEASYMOVEMODE;
/ / Whether you can use the mouse to drag dialog
Declare_message_map ()
}
/ / =========================================================================================================================================================================================== ========= //// Copyright (C) 2000-2004 iWise Technologies, Co. Ltd.////////////product: IW988 // File : Bkdialogst.cpp // Author: Tianda
// Created: 2004.12.29 23: 50 // // Description: // ValueAdded main program for w988.// Contact: shenzhen @ guangdong // 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 (LPCTSTSTSTSZRESOURCEID, CWND * PPARENT)
: Cdialog (pszResourceId, PParent)
{
INIT ();
}
CBKDIALOGST :: ~ CBKDIALOGST ()
{
FREERESOURES ();
}
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 ()
{
Freeresources (false);
// Default bitmap display mode
m_bymode = bkdlgst_mode_tile;
// Customer area can drag the window at will
m_beasymovemode = true;
}
Void CBKDIALOGST :: FreeResources (Bool Bcheckfornull) {
// Uninstall resources
IF (BCheckfornull == True)
{
IF (m_hbitmap) :: deleteObject (m_hbitmap);
}
m_hbitmap = null;
m_dwwidth = 0;
m_dwheight = 0;
}
Void CBKDIALOGST :: ONLBUTTONDOWN (UINT NFLAGS, CPOINT)
{
// Customer area can drag the window at will
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 drag the window at will
m_beasymovemode = bactage;
Return bkdlgst_ok;
}
DWORD CBKDIALOGST :: setBitmap (int nbitmap)
{
Hbitmap hbitmap = null;
Hinstance hinstresource = null;
/ / Find the handle of a bitmap resource
HinstResource = AFXFINDRESOURCEHANDLE (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 resources
FREERESOURES ();
IF (HBitmap)
{
m_hbitmap = hbitmap;
/ / Get bitmap information
NRETVALUE = :: getObject (hbitmap, sizeof (csbitmapsize), & csbitmapsize
IF (NRetValue == 0)
{
// invalid bitmap handle
FREERESOURES ();
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)
{
// Make 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); / / / / relative to the position of the screen
:: getClientRect (m_hwnd, & rclient); // Customer area relative to the location of the left corner of the dialog
DWDIFFCX = RWND.Width () - rclient.width (); // Left and right frame width
Dwdiffcy = rwnd.height () - rclient.Height (); // dialog box title Lan and lower box width
m_bymode = bkdlgst_mode_center; // Display mode is a pair map
// calculate the size of the border, move again, so that the customer area only shows a bitmap size
MoveWindow (rwnd.Left, rwnd.top, dwdiffcx m_dwwidth, dwdiffcy m_dwheight, brepaint);
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
IF (M_Hbitmap! = NULL)
{
Invalidate ();
}
}
Void CBKDIALOGST :: OnPosteraseBkGnd (CDC * PDC)
{
// Remaining extension
}
Bool CBKDIALOGST :: OneRaseBkGnd (CDC * PDC)
{
CRECT RWND;
INT NX = 0;
INT NY = 0;
Bool BretValue = CDIALOG :: OneRaseBkGnd (PDC);
// Directive is loaded when you load
IF (m_hbitmap)
{
GetClientRect (RWND); // Customer area location, relative to dialog box
CDC DCMEMORYDC; / / Target Graphics Equipment
CBITMAP BMPMEMORYBITMAP; / / Bitmap of the above equipment
CBITMAP * pbmpoldmemorybitmap = null;
DCMEMORYDC.CREATECOMPATIPLEDC (PDC); // Create a memory graphic device compatible with device files
BmpMemoryBitmap.createCompATIBLEBITMAP (PDC, RWND.Width (), RWND.HEIGHT ());
// initialize this memory bitmap with a memory graphic device
PBMPoldMemoryBitmap = (cbitmap *) DCMemorydc.selectObject (& BmpMemoryBitmap);
// In the memory graphics device, this bitmap is selected.
DcMemorydc.FillSolidRect (rwnd, pdc-> getBkcolor ()); // Pack background color
CDC DCTEMPDC; // Source Graphics Equipment, bitmap first
Hbitmap hbmpoldtempbitmap = null;
DCTempdc.createCompAMPALDC (PDC);
HBMPoldTempBitmap = (hbitmap) :: SelectObject (dcTempdc.m_hdc, m_hbitmap);
Switch (m_bymode)
{
Case bkdlgst_mode_tile:
// Table map
While (NY { While (Nx { DcMemorydc.bitblt (NX, NY, M_DWWIDTH, M_DWHEIGHT, & DCTEMPDC, 0, 0, SRCCOPY); NX = m_dwwidth; } Nx = 0; NY = m_dwheight; } Break; Case bkdlgst_mode_center: Nx = ((rwnd.width () - m_dwwidth) / 2); NY = ((RWnd.Height () - m_dwheight) / 2); DcMemorydc.bitblt (NX, NY, M_DWWIDTH, M_DWHEIGHT, & DCTEMPDC, 0, 0, SRCCOPY); Break; Case bkdlgst_mode_stretch: // stretch bitmap DcMemorydc.stretchChblt (0, 0, rwnd.width (), rwnd.Height (), & DCTEMPDC, 0, 0, M_Dwwidth, m_dwheight, srccopy; Break; Case bkdlgst_mode_tiletop: While (Nx { Dcmemorydc.bitblt (NX, 0, M_dwwidth, m_dwheight, & dcTempdc, 0, 0, srcopy); NX = m_dwwidth; } Break; Case bkdlgst_mode_tilebottom: While (Nx { DcMemorydc.bitblt (NX, RWND.BOTTOM - M_DWHEIGHT, M_DWWIDTH, M_DWHEIGHT, & DCTEMPDC, 0, 0, SRCCOPY); NX = m_dwwidth; } Break; Case bkdlgst_mode_tileleft: While (NY { Dcmemorydc.bitblt (0, NY, M_DWPIDTH, M_DWHEIGHT, & DCTEMPDC, 0, 0, SRCCPY); NY = m_dwheight; } Break; Case bkdlgst_mode_tileright: While (NY { DcMemorydc.bitblt (rwnd.right - m_dwwidth, ny, m_dwwidth, m_dwheight, & dcTempdc, 0, 0, srcopy); NY = m_dwheight; } Break; Case bkdlgst_mode_topleft: DcMemorydc.bitblt (0, 0, m_dwwidth, m_dwheight, & dcTempdc, 0, 0, srcopy); Break; Case bkdlgst_mode_topright: DcMemorydc.bitblt (rwnd.right - m_dwwidth, 0, m_dwwidth, m_dwheight, & dcTempdc, 0, 0, srcopy); Break; Case bkdlgst_mode_topcenter: Nx = ((rwnd.width () - m_dwwidth) / 2); Dcmemorydc.bitblt (NX, 0, M_dwwidth, m_dwheight, & dcTempdc, 0, 0, srcopy); Break; Case bkdlgst_mode_bottomleaseft: 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, srcopy); 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; }