40 个解决方案
#1
取得桌面窗口句柄,直接画屏,CDC::TestOut, 可支持透明,或是用一个置顶的透明窗体,在窗体背景中写字
#2
如果要让文字滚动的话可以在窗体的时间事件中设置窗体位置即可,当到达一边时再从另一边开始移就OK了
相关函数:
CDC::SetBKMode(TRANSPARENT);
CDC::TextOut();
CDC::SetTextColor();
CDialog::OnEraseBkgnd(CDC * pDC)
SetWindowsPos
MoveWindow
如果要设置字体
CFont font;
LOGFONT lf; //LOGFONT结构中的变量用于定义字体的各种特性
memset(&lf,0,sizeof(lf));
lf.lfHeight = 20;
strcpy(lf.lfFaceName,"MingLiu"); //设置字体名称 MingLiu为MS提供的BIG5字体
font.CreateFontIndirect(&lf); //创建字体
CFont* pF = (CFont*)dc.SelectObject(&font); //保存当前字体
dc.TextOut(0,0,_T("what you want to display"));
dc.SelectObject(pF); //恢复以前的字体
相关函数:
CDC::SetBKMode(TRANSPARENT);
CDC::TextOut();
CDC::SetTextColor();
CDialog::OnEraseBkgnd(CDC * pDC)
SetWindowsPos
MoveWindow
如果要设置字体
CFont font;
LOGFONT lf; //LOGFONT结构中的变量用于定义字体的各种特性
memset(&lf,0,sizeof(lf));
lf.lfHeight = 20;
strcpy(lf.lfFaceName,"MingLiu"); //设置字体名称 MingLiu为MS提供的BIG5字体
font.CreateFontIndirect(&lf); //创建字体
CFont* pF = (CFont*)dc.SelectObject(&font); //保存当前字体
dc.TextOut(0,0,_T("what you want to display"));
dc.SelectObject(pF); //恢复以前的字体
#3
呵呵,忘了 WM_TIMER 消息相关函数
OnTimer
SetTimer
OnTimer
SetTimer
#4
我要求是要一直在最上面,所以取桌面DC来画是不可能的,只能是用一个置顶的而且透明的窗口,在窗口背景上写字,但是一移动就很闪动,请问有什么方法可能防止闪动吗??
#5
我是移动窗口,而不是移动所写的文字,因为所写的文字要用位图存起来后然后再根据位图产生RGN,然后再用SETWINDOWRGN,这样才能实现文字也透明,如果移动文字的话也是很闪动,请问还有别的比较好的办法吗??救救我吧,,高手们,这个问题已经困扰我一个星期了......
#6
桌面文字透明化工具 http://vip.6to23.com/zerolu/TransDesktop/Help.htm
你可以和他联系
你可以和他联系
#7
透明我现在也可以实现了,但就是滚动的时候很闪动,我的方法是这样的:
先用一个内存DC,选入一幅颜色为透明色的位图,然后再在内存DC上面写字,然后再根据这个内存DC计算出RGN,再用SETWINDOWRGN函数将窗口设置成为RGN窗口,这样就剩下文字在窗口上面了,其它的都透明,但是当我用SETWINDOWPOS函数移动窗口时,窗口闪动非常厉害..
这种方法不知是否可靠??
先用一个内存DC,选入一幅颜色为透明色的位图,然后再在内存DC上面写字,然后再根据这个内存DC计算出RGN,再用SETWINDOWRGN函数将窗口设置成为RGN窗口,这样就剩下文字在窗口上面了,其它的都透明,但是当我用SETWINDOWPOS函数移动窗口时,窗口闪动非常厉害..
这种方法不知是否可靠??
#8
假如我不用SETWINDOWPOS函数,而改用每次用不同的RGN的话,同样也是非常闪动...
#9
高手们啊...帮帮我啊....
#10
楼主可以不一定要用RGN来做透明窗体呀(那个实在是慢),本身如果你象我说的那样在OnEraseBkgnd中画透明位图,再返回TRUE就可以做窗体的其它部分不显示,这样会快一些
使用双缓冲以提高刷新速度,可以减小闪烁
在没有必要的情况下,不要重画背景,也可以减少闪烁
使用双缓冲以提高刷新速度,可以减小闪烁
在没有必要的情况下,不要重画背景,也可以减少闪烁
#11
呵呵,楼还是不要用OnEraseBkgnd的方法吧,我才试过了,为了透明,一样闪得很
关注
关注
#12
我看了很多桌面上的时钟等等很多软件,都没有达到我这个效果,如果透明的外观是固定的,比较说一幅画就非常简单了,但如果是在上面写字或者说画一些经常变化的东西就还没有软件实现这个功能,但我觉得这应该是有办法实现的,只有想不到的,没有做不到的嘛.
#13
哪位高手能给点建议啊??教教我吧...
#14
把对话框做成字体形状,然后移动对话框
class CTestDlg : public CDialog
{
// Construction
public:
void SetupBk(HDC);
CTestDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CTestDlg)
enum { IDD = IDD_TEST_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
CRgn Working,Temp;
// Generated message map functions
//{{AFX_MSG(CTestDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
class CTestDlg : public CDialog
{
// Construction
public:
void SetupBk(HDC);
CTestDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CTestDlg)
enum { IDD = IDD_TEST_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
CRgn Working,Temp;
// Generated message map functions
//{{AFX_MSG(CTestDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#15
//.cpp
// testDlg.cpp : implementation file
//
#include "stdafx.h"
#include "test.h"
#include "testDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int FirstRun = 1;
void TransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc,
COLORREF colorTransparent, HPALETTE hPal );
static void MessageBlast(int iColumn,int iRow,LPCTSTR lpszMsg);
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//Initialize fisrt run flag
FirstRun = 1;
//resize window to fit bitmap rect
MoveWindow(200,200,535,105,TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
//Get and HDC pointer and pass it to SetupBk()
HDC hdc;
hdc = dc.GetSafeHdc();
SetupBk(dc);
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//Overridden to allow for mouse draging
void CTestDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
}
// testDlg.cpp : implementation file
//
#include "stdafx.h"
#include "test.h"
#include "testDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int FirstRun = 1;
void TransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc,
COLORREF colorTransparent, HPALETTE hPal );
static void MessageBlast(int iColumn,int iRow,LPCTSTR lpszMsg);
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//Initialize fisrt run flag
FirstRun = 1;
//resize window to fit bitmap rect
MoveWindow(200,200,535,105,TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
//Get and HDC pointer and pass it to SetupBk()
HDC hdc;
hdc = dc.GetSafeHdc();
SetupBk(dc);
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//Overridden to allow for mouse draging
void CTestDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
}
#16
//From Codeguru.. by Zafir Anjum, the transparency here is overkill,
//SetupBk() will take care of the transparency that we are dealing with
void TransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc,
COLORREF colorTransparent, HPALETTE hPal )
{
CDC dc, memDC, maskDC, tempDC;
dc.Attach( hdcDest );
maskDC.CreateCompatibleDC(&dc);
CBitmap maskBitmap;
//add these to store return of SelectObject() calls
CBitmap* pOldMemBmp = NULL;
CBitmap* pOldMaskBmp = NULL;
HBITMAP hOldTempBmp = NULL;
memDC.CreateCompatibleDC(&dc);
tempDC.CreateCompatibleDC(&dc);
CBitmap bmpImage;
bmpImage.CreateCompatibleBitmap( &dc, nWidth, nHeight );
pOldMemBmp = memDC.SelectObject( &bmpImage );
// Select and realize the palette
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && hPal )
{
::SelectPalette( dc, hPal, FALSE );
dc.RealizePalette();
::SelectPalette( memDC, hPal, FALSE );
}
hOldTempBmp = (HBITMAP) ::SelectObject( tempDC.m_hDC, hBitmap );
memDC.BitBlt( 0,0,nWidth, nHeight, &tempDC, nXSrc, nYSrc, SRCCOPY );
// Create monochrome bitmap for the mask
maskBitmap.CreateBitmap( nWidth, nHeight, 1, 1, NULL );
pOldMaskBmp = maskDC.SelectObject( &maskBitmap );
memDC.SetBkColor( colorTransparent );
// Create the mask from the memory DC
maskDC.BitBlt( 0, 0, nWidth, nHeight, &memDC,
0, 0, SRCCOPY );
// Set the background in memDC to black. Using SRCPAINT with black
// and any other color results in the other color, thus making
// black the transparent color
memDC.SetBkColor(RGB(0,0,0));
memDC.SetTextColor(RGB(255,255,255));
memDC.BitBlt(0, 0, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
// Set the foreground to black. See comment above.
dc.SetBkColor(RGB(255,255,255));
dc.SetTextColor(RGB(0,0,0));
dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
// Combine the foreground with the background
dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &memDC,
0, 0, SRCPAINT);
if (hOldTempBmp)
::SelectObject( tempDC.m_hDC, hOldTempBmp);
if (pOldMaskBmp)
maskDC.SelectObject( pOldMaskBmp );
if (pOldMemBmp)
memDC.SelectObject( pOldMemBmp );
dc.Detach();
}
//Used for debugging.....
static void MessageBlast(int iColumn,int iRow,LPCTSTR lpszMsg)
{
HDC hdcScreen;
// Get a raw screen DC
hdcScreen = GetWindowDC( GetDesktopWindow() );
if (hdcScreen)
{
TextOut( hdcScreen, iColumn, iRow, lpszMsg, lstrlen(lpszMsg));
// Release the screen DC
ReleaseDC( GetDesktopWindow(), hdcScreen );
}
}
//Setup the windows Region
//The windows region controls what the OS will draw in reguards to the window
//The loop below will search for the "magic color" and add it to a region
//then Xor the region and assign it to the window and viola.
void CTestDlg::SetupBk(HDC hdc)
{
int X,Y,H,W;
CBitmap CB;
CRect R;
COLORREF C;
GetWindowRect(&R);
H = R.bottom - R.top;
W = R.right - R.left;
CB.LoadBitmap(IDB_BITMAP2);
HBITMAP HB = (HBITMAP)CB;
TransparentBlt( hdc , 0, 0, 535, 105, HB, 0, 0,0x00000000 , NULL );
//Only do this once because it takes some time.
//maybe should pre-make a seperate file to hold region data?
if (FirstRun){
int Set = 0;
//begin pixel by pixel scan for transparent color
for(X=0;X<=W;X++){
for(Y=0;Y<=H;Y++){
C = GetPixel(hdc,X,Y);
//Get the color
if(C == 0x00FFFFFF){
if(Set == 0){
//First, init the working region
//never delete Working, the OS does not store the value, only a pointer to it.
Working.CreateRectRgn(X,Y,X+1,Y+1);
Set = 1;
}
else{
Temp.CreateRectRgn(X,Y,X+1,Y+1);
//Add pixel to region
Working.CombineRgn( &Working, &Temp,RGN_OR );
Temp.DeleteObject();
}
}
}
}
FirstRun = 0;
Temp.CreateRectRgn(0,0,1200,1200);
//flip to get the non-transparent region
Working.CombineRgn( &Working, &Temp,RGN_XOR );
Temp.DeleteObject();
if (Set) SetWindowRgn((HRGN)Working,TRUE);
//redraw just incase.. trust me.. leave this here
RedrawWindow();
}
}
//SetupBk() will take care of the transparency that we are dealing with
void TransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc,
COLORREF colorTransparent, HPALETTE hPal )
{
CDC dc, memDC, maskDC, tempDC;
dc.Attach( hdcDest );
maskDC.CreateCompatibleDC(&dc);
CBitmap maskBitmap;
//add these to store return of SelectObject() calls
CBitmap* pOldMemBmp = NULL;
CBitmap* pOldMaskBmp = NULL;
HBITMAP hOldTempBmp = NULL;
memDC.CreateCompatibleDC(&dc);
tempDC.CreateCompatibleDC(&dc);
CBitmap bmpImage;
bmpImage.CreateCompatibleBitmap( &dc, nWidth, nHeight );
pOldMemBmp = memDC.SelectObject( &bmpImage );
// Select and realize the palette
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && hPal )
{
::SelectPalette( dc, hPal, FALSE );
dc.RealizePalette();
::SelectPalette( memDC, hPal, FALSE );
}
hOldTempBmp = (HBITMAP) ::SelectObject( tempDC.m_hDC, hBitmap );
memDC.BitBlt( 0,0,nWidth, nHeight, &tempDC, nXSrc, nYSrc, SRCCOPY );
// Create monochrome bitmap for the mask
maskBitmap.CreateBitmap( nWidth, nHeight, 1, 1, NULL );
pOldMaskBmp = maskDC.SelectObject( &maskBitmap );
memDC.SetBkColor( colorTransparent );
// Create the mask from the memory DC
maskDC.BitBlt( 0, 0, nWidth, nHeight, &memDC,
0, 0, SRCCOPY );
// Set the background in memDC to black. Using SRCPAINT with black
// and any other color results in the other color, thus making
// black the transparent color
memDC.SetBkColor(RGB(0,0,0));
memDC.SetTextColor(RGB(255,255,255));
memDC.BitBlt(0, 0, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
// Set the foreground to black. See comment above.
dc.SetBkColor(RGB(255,255,255));
dc.SetTextColor(RGB(0,0,0));
dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
// Combine the foreground with the background
dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &memDC,
0, 0, SRCPAINT);
if (hOldTempBmp)
::SelectObject( tempDC.m_hDC, hOldTempBmp);
if (pOldMaskBmp)
maskDC.SelectObject( pOldMaskBmp );
if (pOldMemBmp)
memDC.SelectObject( pOldMemBmp );
dc.Detach();
}
//Used for debugging.....
static void MessageBlast(int iColumn,int iRow,LPCTSTR lpszMsg)
{
HDC hdcScreen;
// Get a raw screen DC
hdcScreen = GetWindowDC( GetDesktopWindow() );
if (hdcScreen)
{
TextOut( hdcScreen, iColumn, iRow, lpszMsg, lstrlen(lpszMsg));
// Release the screen DC
ReleaseDC( GetDesktopWindow(), hdcScreen );
}
}
//Setup the windows Region
//The windows region controls what the OS will draw in reguards to the window
//The loop below will search for the "magic color" and add it to a region
//then Xor the region and assign it to the window and viola.
void CTestDlg::SetupBk(HDC hdc)
{
int X,Y,H,W;
CBitmap CB;
CRect R;
COLORREF C;
GetWindowRect(&R);
H = R.bottom - R.top;
W = R.right - R.left;
CB.LoadBitmap(IDB_BITMAP2);
HBITMAP HB = (HBITMAP)CB;
TransparentBlt( hdc , 0, 0, 535, 105, HB, 0, 0,0x00000000 , NULL );
//Only do this once because it takes some time.
//maybe should pre-make a seperate file to hold region data?
if (FirstRun){
int Set = 0;
//begin pixel by pixel scan for transparent color
for(X=0;X<=W;X++){
for(Y=0;Y<=H;Y++){
C = GetPixel(hdc,X,Y);
//Get the color
if(C == 0x00FFFFFF){
if(Set == 0){
//First, init the working region
//never delete Working, the OS does not store the value, only a pointer to it.
Working.CreateRectRgn(X,Y,X+1,Y+1);
Set = 1;
}
else{
Temp.CreateRectRgn(X,Y,X+1,Y+1);
//Add pixel to region
Working.CombineRgn( &Working, &Temp,RGN_OR );
Temp.DeleteObject();
}
}
}
}
FirstRun = 0;
Temp.CreateRectRgn(0,0,1200,1200);
//flip to get the non-transparent region
Working.CombineRgn( &Working, &Temp,RGN_XOR );
Temp.DeleteObject();
if (Set) SetWindowRgn((HRGN)Working,TRUE);
//redraw just incase.. trust me.. leave this here
RedrawWindow();
}
}
#17
我的思路也是这样,把要写的字写到内存里面的位图上去,然后根据位图的信息来生产字体的窗口,这样是可行的,但是当我的文字要经常变的时候(比如说是时间),就需要不停地产生位图,产生RGN,这样造成的效果是产生了非常大的闪烁,可能是SETWINDOWRGN函数频频使用的原因吧,不知道还有什么别的方法可以解决这个问题呢??
#18
这个问题我看是没人能解决了??因为我还没见到有这样的东西,比较说在永远在桌面的最上面滚动一行透明文字,上面的文字是时间,而且要求不能闪动太明显??有哪位高手能做到??我就服了....是高手的快点站出来吧...
#19
帮帮我吧...8858....
#20
remark
#21
为什么高手还没有出现呢??
#22
闪烁是应为屏幕先被刷成倍景色,然后又被画上你的图片。
故:
在Erase Back Ground 的时候直接返回TRUE使得系统不用背景色Fill整个client screen
然后把所有要画的东西先画到一个CDC上,然后一次性的话到client的CDC上
不知问题可迎刃而解否?
故:
在Erase Back Ground 的时候直接返回TRUE使得系统不用背景色Fill整个client screen
然后把所有要画的东西先画到一个CDC上,然后一次性的话到client的CDC上
不知问题可迎刃而解否?
#23
我要求是要一直在最上面,所以取桌面DC来画是不可能的,只能是用一个置顶的而且透明的窗口,在窗口背景上写字,但是一移动就很闪动,请问有什么方法可能防止闪动吗??
其实用SetWindowsPos设置就能保证在最上方,如果不对,那是你参数不对。
而且我可以告诉你,我见过你这样的东西
比如说背英语的一些软件,什么 迷你单词之类的
那个应该比你这个更加难
其实用SetWindowsPos设置就能保证在最上方,如果不对,那是你参数不对。
而且我可以告诉你,我见过你这样的东西
比如说背英语的一些软件,什么 迷你单词之类的
那个应该比你这个更加难
#24
金山迷你单词我下载了看过了它的背景不能够透明啊??
#25
我下载了差不多10个背单词的软件,它们无非是把窗口做得很漂亮,但是没有一个能够实现透明的功能啊????
还是没有高手???
我..正等待着奇迹出现.................
还是没有高手???
我..正等待着奇迹出现.................
#26
你为什么要找一个能实现全部功能的软件呢?
透明又不是不能实现,你可以用上面几种方法来试试看
大多数时候是没办法给你完全满意的代码的,不满意的地方就需要自己去做
透明又不是不能实现,你可以用上面几种方法来试试看
大多数时候是没办法给你完全满意的代码的,不满意的地方就需要自己去做
#27
我是想自己做啊..但是效果不是很好..想问一问大家有没有更好的办法??
我的方法:1.在内存DC中画透明的底图,再在上面写文字或者画上图片.
2.通过内存DC中的图形和透明色值计算出CRGN.
3.将窗口设置成为上一步中产生出来的形状.
4.在ONPAINT中将内存DC画上.
效果:如果文字及位置不变动,则效果非常好,其实就是做一个不规则的窗口.
如果文字及位置经常变动(如显示的是时间),则效果非常差,闪烁不停.
我的方法:1.在内存DC中画透明的底图,再在上面写文字或者画上图片.
2.通过内存DC中的图形和透明色值计算出CRGN.
3.将窗口设置成为上一步中产生出来的形状.
4.在ONPAINT中将内存DC画上.
效果:如果文字及位置不变动,则效果非常好,其实就是做一个不规则的窗口.
如果文字及位置经常变动(如显示的是时间),则效果非常差,闪烁不停.
#28
直接保存一部分桌面,再画透明的文字上去,文字变的时候再BLT保存的那部分,再画.应该不慢吧
#29
我以前做过一个,就是hook+注入explore进程的dll+subclassing技术做的,效果不错,还可以显示滚动图片,可以自己设定滚动速度等等,如果要的话,我可以发给你源代码,不过别忘了给分哦^_^
#30
tofoxmail(萧遥 www.LoveSnow.com),这个方法我也试过。。但是如果背景也是动画的话也是很慢的。。
#31
to:checkyvc6(checkyvc6),要啊。。要多少分都可以给你。。我的邮箱:
zxz@danter.net
postmaster@danter.net都可以。。
zxz@danter.net
postmaster@danter.net都可以。。
#32
大哥,怎么还没发给我啊??
#33
不好意思,今天我才看到,现在我已经发给你了,不好意思哦
不过有个前提,把ActiveDesktop关闭掉.别忘了 给分哦 ^_^
不过有个前提,把ActiveDesktop关闭掉.别忘了 给分哦 ^_^
#34
checkyvc6(checkyvc6)
给我一个行不行?
bandry_li@163.com
给我一个行不行?
bandry_li@163.com
#35
可以啊,不过你能给我分吗?我现在正在升级呢,没有办法!帮帮忙 ^_^
我已经发给你了!
我已经发给你了!
#36
To:checkyvc6
麻烦也发我一份,谢谢!
ioat@sina.com
麻烦也发我一份,谢谢!
ioat@sina.com
#37
你有分吗?开个贴给我分,ok?我马上发.没有办法啊
#38
我试运行了一下,只是在桌面上透明,而我是要求要在所有窗口上面都能够透明,而且要永远在所有窗口上面能够透明啊。。。
#39
你什么意思?
我不太明白。
能不能说的更清楚一点。或者举个例子(有什么类似的软件或者效果)
我不太明白。
能不能说的更清楚一点。或者举个例子(有什么类似的软件或者效果)
#40
你的窗口注意处理成是一直最前面的
#1
取得桌面窗口句柄,直接画屏,CDC::TestOut, 可支持透明,或是用一个置顶的透明窗体,在窗体背景中写字
#2
如果要让文字滚动的话可以在窗体的时间事件中设置窗体位置即可,当到达一边时再从另一边开始移就OK了
相关函数:
CDC::SetBKMode(TRANSPARENT);
CDC::TextOut();
CDC::SetTextColor();
CDialog::OnEraseBkgnd(CDC * pDC)
SetWindowsPos
MoveWindow
如果要设置字体
CFont font;
LOGFONT lf; //LOGFONT结构中的变量用于定义字体的各种特性
memset(&lf,0,sizeof(lf));
lf.lfHeight = 20;
strcpy(lf.lfFaceName,"MingLiu"); //设置字体名称 MingLiu为MS提供的BIG5字体
font.CreateFontIndirect(&lf); //创建字体
CFont* pF = (CFont*)dc.SelectObject(&font); //保存当前字体
dc.TextOut(0,0,_T("what you want to display"));
dc.SelectObject(pF); //恢复以前的字体
相关函数:
CDC::SetBKMode(TRANSPARENT);
CDC::TextOut();
CDC::SetTextColor();
CDialog::OnEraseBkgnd(CDC * pDC)
SetWindowsPos
MoveWindow
如果要设置字体
CFont font;
LOGFONT lf; //LOGFONT结构中的变量用于定义字体的各种特性
memset(&lf,0,sizeof(lf));
lf.lfHeight = 20;
strcpy(lf.lfFaceName,"MingLiu"); //设置字体名称 MingLiu为MS提供的BIG5字体
font.CreateFontIndirect(&lf); //创建字体
CFont* pF = (CFont*)dc.SelectObject(&font); //保存当前字体
dc.TextOut(0,0,_T("what you want to display"));
dc.SelectObject(pF); //恢复以前的字体
#3
呵呵,忘了 WM_TIMER 消息相关函数
OnTimer
SetTimer
OnTimer
SetTimer
#4
我要求是要一直在最上面,所以取桌面DC来画是不可能的,只能是用一个置顶的而且透明的窗口,在窗口背景上写字,但是一移动就很闪动,请问有什么方法可能防止闪动吗??
#5
我是移动窗口,而不是移动所写的文字,因为所写的文字要用位图存起来后然后再根据位图产生RGN,然后再用SETWINDOWRGN,这样才能实现文字也透明,如果移动文字的话也是很闪动,请问还有别的比较好的办法吗??救救我吧,,高手们,这个问题已经困扰我一个星期了......
#6
桌面文字透明化工具 http://vip.6to23.com/zerolu/TransDesktop/Help.htm
你可以和他联系
你可以和他联系
#7
透明我现在也可以实现了,但就是滚动的时候很闪动,我的方法是这样的:
先用一个内存DC,选入一幅颜色为透明色的位图,然后再在内存DC上面写字,然后再根据这个内存DC计算出RGN,再用SETWINDOWRGN函数将窗口设置成为RGN窗口,这样就剩下文字在窗口上面了,其它的都透明,但是当我用SETWINDOWPOS函数移动窗口时,窗口闪动非常厉害..
这种方法不知是否可靠??
先用一个内存DC,选入一幅颜色为透明色的位图,然后再在内存DC上面写字,然后再根据这个内存DC计算出RGN,再用SETWINDOWRGN函数将窗口设置成为RGN窗口,这样就剩下文字在窗口上面了,其它的都透明,但是当我用SETWINDOWPOS函数移动窗口时,窗口闪动非常厉害..
这种方法不知是否可靠??
#8
假如我不用SETWINDOWPOS函数,而改用每次用不同的RGN的话,同样也是非常闪动...
#9
高手们啊...帮帮我啊....
#10
楼主可以不一定要用RGN来做透明窗体呀(那个实在是慢),本身如果你象我说的那样在OnEraseBkgnd中画透明位图,再返回TRUE就可以做窗体的其它部分不显示,这样会快一些
使用双缓冲以提高刷新速度,可以减小闪烁
在没有必要的情况下,不要重画背景,也可以减少闪烁
使用双缓冲以提高刷新速度,可以减小闪烁
在没有必要的情况下,不要重画背景,也可以减少闪烁
#11
呵呵,楼还是不要用OnEraseBkgnd的方法吧,我才试过了,为了透明,一样闪得很
关注
关注
#12
我看了很多桌面上的时钟等等很多软件,都没有达到我这个效果,如果透明的外观是固定的,比较说一幅画就非常简单了,但如果是在上面写字或者说画一些经常变化的东西就还没有软件实现这个功能,但我觉得这应该是有办法实现的,只有想不到的,没有做不到的嘛.
#13
哪位高手能给点建议啊??教教我吧...
#14
把对话框做成字体形状,然后移动对话框
class CTestDlg : public CDialog
{
// Construction
public:
void SetupBk(HDC);
CTestDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CTestDlg)
enum { IDD = IDD_TEST_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
CRgn Working,Temp;
// Generated message map functions
//{{AFX_MSG(CTestDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
class CTestDlg : public CDialog
{
// Construction
public:
void SetupBk(HDC);
CTestDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CTestDlg)
enum { IDD = IDD_TEST_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
CRgn Working,Temp;
// Generated message map functions
//{{AFX_MSG(CTestDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#15
//.cpp
// testDlg.cpp : implementation file
//
#include "stdafx.h"
#include "test.h"
#include "testDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int FirstRun = 1;
void TransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc,
COLORREF colorTransparent, HPALETTE hPal );
static void MessageBlast(int iColumn,int iRow,LPCTSTR lpszMsg);
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//Initialize fisrt run flag
FirstRun = 1;
//resize window to fit bitmap rect
MoveWindow(200,200,535,105,TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
//Get and HDC pointer and pass it to SetupBk()
HDC hdc;
hdc = dc.GetSafeHdc();
SetupBk(dc);
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//Overridden to allow for mouse draging
void CTestDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
}
// testDlg.cpp : implementation file
//
#include "stdafx.h"
#include "test.h"
#include "testDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int FirstRun = 1;
void TransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc,
COLORREF colorTransparent, HPALETTE hPal );
static void MessageBlast(int iColumn,int iRow,LPCTSTR lpszMsg);
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//Initialize fisrt run flag
FirstRun = 1;
//resize window to fit bitmap rect
MoveWindow(200,200,535,105,TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
//Get and HDC pointer and pass it to SetupBk()
HDC hdc;
hdc = dc.GetSafeHdc();
SetupBk(dc);
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//Overridden to allow for mouse draging
void CTestDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
}
#16
//From Codeguru.. by Zafir Anjum, the transparency here is overkill,
//SetupBk() will take care of the transparency that we are dealing with
void TransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc,
COLORREF colorTransparent, HPALETTE hPal )
{
CDC dc, memDC, maskDC, tempDC;
dc.Attach( hdcDest );
maskDC.CreateCompatibleDC(&dc);
CBitmap maskBitmap;
//add these to store return of SelectObject() calls
CBitmap* pOldMemBmp = NULL;
CBitmap* pOldMaskBmp = NULL;
HBITMAP hOldTempBmp = NULL;
memDC.CreateCompatibleDC(&dc);
tempDC.CreateCompatibleDC(&dc);
CBitmap bmpImage;
bmpImage.CreateCompatibleBitmap( &dc, nWidth, nHeight );
pOldMemBmp = memDC.SelectObject( &bmpImage );
// Select and realize the palette
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && hPal )
{
::SelectPalette( dc, hPal, FALSE );
dc.RealizePalette();
::SelectPalette( memDC, hPal, FALSE );
}
hOldTempBmp = (HBITMAP) ::SelectObject( tempDC.m_hDC, hBitmap );
memDC.BitBlt( 0,0,nWidth, nHeight, &tempDC, nXSrc, nYSrc, SRCCOPY );
// Create monochrome bitmap for the mask
maskBitmap.CreateBitmap( nWidth, nHeight, 1, 1, NULL );
pOldMaskBmp = maskDC.SelectObject( &maskBitmap );
memDC.SetBkColor( colorTransparent );
// Create the mask from the memory DC
maskDC.BitBlt( 0, 0, nWidth, nHeight, &memDC,
0, 0, SRCCOPY );
// Set the background in memDC to black. Using SRCPAINT with black
// and any other color results in the other color, thus making
// black the transparent color
memDC.SetBkColor(RGB(0,0,0));
memDC.SetTextColor(RGB(255,255,255));
memDC.BitBlt(0, 0, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
// Set the foreground to black. See comment above.
dc.SetBkColor(RGB(255,255,255));
dc.SetTextColor(RGB(0,0,0));
dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
// Combine the foreground with the background
dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &memDC,
0, 0, SRCPAINT);
if (hOldTempBmp)
::SelectObject( tempDC.m_hDC, hOldTempBmp);
if (pOldMaskBmp)
maskDC.SelectObject( pOldMaskBmp );
if (pOldMemBmp)
memDC.SelectObject( pOldMemBmp );
dc.Detach();
}
//Used for debugging.....
static void MessageBlast(int iColumn,int iRow,LPCTSTR lpszMsg)
{
HDC hdcScreen;
// Get a raw screen DC
hdcScreen = GetWindowDC( GetDesktopWindow() );
if (hdcScreen)
{
TextOut( hdcScreen, iColumn, iRow, lpszMsg, lstrlen(lpszMsg));
// Release the screen DC
ReleaseDC( GetDesktopWindow(), hdcScreen );
}
}
//Setup the windows Region
//The windows region controls what the OS will draw in reguards to the window
//The loop below will search for the "magic color" and add it to a region
//then Xor the region and assign it to the window and viola.
void CTestDlg::SetupBk(HDC hdc)
{
int X,Y,H,W;
CBitmap CB;
CRect R;
COLORREF C;
GetWindowRect(&R);
H = R.bottom - R.top;
W = R.right - R.left;
CB.LoadBitmap(IDB_BITMAP2);
HBITMAP HB = (HBITMAP)CB;
TransparentBlt( hdc , 0, 0, 535, 105, HB, 0, 0,0x00000000 , NULL );
//Only do this once because it takes some time.
//maybe should pre-make a seperate file to hold region data?
if (FirstRun){
int Set = 0;
//begin pixel by pixel scan for transparent color
for(X=0;X<=W;X++){
for(Y=0;Y<=H;Y++){
C = GetPixel(hdc,X,Y);
//Get the color
if(C == 0x00FFFFFF){
if(Set == 0){
//First, init the working region
//never delete Working, the OS does not store the value, only a pointer to it.
Working.CreateRectRgn(X,Y,X+1,Y+1);
Set = 1;
}
else{
Temp.CreateRectRgn(X,Y,X+1,Y+1);
//Add pixel to region
Working.CombineRgn( &Working, &Temp,RGN_OR );
Temp.DeleteObject();
}
}
}
}
FirstRun = 0;
Temp.CreateRectRgn(0,0,1200,1200);
//flip to get the non-transparent region
Working.CombineRgn( &Working, &Temp,RGN_XOR );
Temp.DeleteObject();
if (Set) SetWindowRgn((HRGN)Working,TRUE);
//redraw just incase.. trust me.. leave this here
RedrawWindow();
}
}
//SetupBk() will take care of the transparency that we are dealing with
void TransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc,
COLORREF colorTransparent, HPALETTE hPal )
{
CDC dc, memDC, maskDC, tempDC;
dc.Attach( hdcDest );
maskDC.CreateCompatibleDC(&dc);
CBitmap maskBitmap;
//add these to store return of SelectObject() calls
CBitmap* pOldMemBmp = NULL;
CBitmap* pOldMaskBmp = NULL;
HBITMAP hOldTempBmp = NULL;
memDC.CreateCompatibleDC(&dc);
tempDC.CreateCompatibleDC(&dc);
CBitmap bmpImage;
bmpImage.CreateCompatibleBitmap( &dc, nWidth, nHeight );
pOldMemBmp = memDC.SelectObject( &bmpImage );
// Select and realize the palette
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && hPal )
{
::SelectPalette( dc, hPal, FALSE );
dc.RealizePalette();
::SelectPalette( memDC, hPal, FALSE );
}
hOldTempBmp = (HBITMAP) ::SelectObject( tempDC.m_hDC, hBitmap );
memDC.BitBlt( 0,0,nWidth, nHeight, &tempDC, nXSrc, nYSrc, SRCCOPY );
// Create monochrome bitmap for the mask
maskBitmap.CreateBitmap( nWidth, nHeight, 1, 1, NULL );
pOldMaskBmp = maskDC.SelectObject( &maskBitmap );
memDC.SetBkColor( colorTransparent );
// Create the mask from the memory DC
maskDC.BitBlt( 0, 0, nWidth, nHeight, &memDC,
0, 0, SRCCOPY );
// Set the background in memDC to black. Using SRCPAINT with black
// and any other color results in the other color, thus making
// black the transparent color
memDC.SetBkColor(RGB(0,0,0));
memDC.SetTextColor(RGB(255,255,255));
memDC.BitBlt(0, 0, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
// Set the foreground to black. See comment above.
dc.SetBkColor(RGB(255,255,255));
dc.SetTextColor(RGB(0,0,0));
dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
// Combine the foreground with the background
dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &memDC,
0, 0, SRCPAINT);
if (hOldTempBmp)
::SelectObject( tempDC.m_hDC, hOldTempBmp);
if (pOldMaskBmp)
maskDC.SelectObject( pOldMaskBmp );
if (pOldMemBmp)
memDC.SelectObject( pOldMemBmp );
dc.Detach();
}
//Used for debugging.....
static void MessageBlast(int iColumn,int iRow,LPCTSTR lpszMsg)
{
HDC hdcScreen;
// Get a raw screen DC
hdcScreen = GetWindowDC( GetDesktopWindow() );
if (hdcScreen)
{
TextOut( hdcScreen, iColumn, iRow, lpszMsg, lstrlen(lpszMsg));
// Release the screen DC
ReleaseDC( GetDesktopWindow(), hdcScreen );
}
}
//Setup the windows Region
//The windows region controls what the OS will draw in reguards to the window
//The loop below will search for the "magic color" and add it to a region
//then Xor the region and assign it to the window and viola.
void CTestDlg::SetupBk(HDC hdc)
{
int X,Y,H,W;
CBitmap CB;
CRect R;
COLORREF C;
GetWindowRect(&R);
H = R.bottom - R.top;
W = R.right - R.left;
CB.LoadBitmap(IDB_BITMAP2);
HBITMAP HB = (HBITMAP)CB;
TransparentBlt( hdc , 0, 0, 535, 105, HB, 0, 0,0x00000000 , NULL );
//Only do this once because it takes some time.
//maybe should pre-make a seperate file to hold region data?
if (FirstRun){
int Set = 0;
//begin pixel by pixel scan for transparent color
for(X=0;X<=W;X++){
for(Y=0;Y<=H;Y++){
C = GetPixel(hdc,X,Y);
//Get the color
if(C == 0x00FFFFFF){
if(Set == 0){
//First, init the working region
//never delete Working, the OS does not store the value, only a pointer to it.
Working.CreateRectRgn(X,Y,X+1,Y+1);
Set = 1;
}
else{
Temp.CreateRectRgn(X,Y,X+1,Y+1);
//Add pixel to region
Working.CombineRgn( &Working, &Temp,RGN_OR );
Temp.DeleteObject();
}
}
}
}
FirstRun = 0;
Temp.CreateRectRgn(0,0,1200,1200);
//flip to get the non-transparent region
Working.CombineRgn( &Working, &Temp,RGN_XOR );
Temp.DeleteObject();
if (Set) SetWindowRgn((HRGN)Working,TRUE);
//redraw just incase.. trust me.. leave this here
RedrawWindow();
}
}
#17
我的思路也是这样,把要写的字写到内存里面的位图上去,然后根据位图的信息来生产字体的窗口,这样是可行的,但是当我的文字要经常变的时候(比如说是时间),就需要不停地产生位图,产生RGN,这样造成的效果是产生了非常大的闪烁,可能是SETWINDOWRGN函数频频使用的原因吧,不知道还有什么别的方法可以解决这个问题呢??
#18
这个问题我看是没人能解决了??因为我还没见到有这样的东西,比较说在永远在桌面的最上面滚动一行透明文字,上面的文字是时间,而且要求不能闪动太明显??有哪位高手能做到??我就服了....是高手的快点站出来吧...
#19
帮帮我吧...8858....
#20
remark
#21
为什么高手还没有出现呢??
#22
闪烁是应为屏幕先被刷成倍景色,然后又被画上你的图片。
故:
在Erase Back Ground 的时候直接返回TRUE使得系统不用背景色Fill整个client screen
然后把所有要画的东西先画到一个CDC上,然后一次性的话到client的CDC上
不知问题可迎刃而解否?
故:
在Erase Back Ground 的时候直接返回TRUE使得系统不用背景色Fill整个client screen
然后把所有要画的东西先画到一个CDC上,然后一次性的话到client的CDC上
不知问题可迎刃而解否?
#23
我要求是要一直在最上面,所以取桌面DC来画是不可能的,只能是用一个置顶的而且透明的窗口,在窗口背景上写字,但是一移动就很闪动,请问有什么方法可能防止闪动吗??
其实用SetWindowsPos设置就能保证在最上方,如果不对,那是你参数不对。
而且我可以告诉你,我见过你这样的东西
比如说背英语的一些软件,什么 迷你单词之类的
那个应该比你这个更加难
其实用SetWindowsPos设置就能保证在最上方,如果不对,那是你参数不对。
而且我可以告诉你,我见过你这样的东西
比如说背英语的一些软件,什么 迷你单词之类的
那个应该比你这个更加难
#24
金山迷你单词我下载了看过了它的背景不能够透明啊??
#25
我下载了差不多10个背单词的软件,它们无非是把窗口做得很漂亮,但是没有一个能够实现透明的功能啊????
还是没有高手???
我..正等待着奇迹出现.................
还是没有高手???
我..正等待着奇迹出现.................
#26
你为什么要找一个能实现全部功能的软件呢?
透明又不是不能实现,你可以用上面几种方法来试试看
大多数时候是没办法给你完全满意的代码的,不满意的地方就需要自己去做
透明又不是不能实现,你可以用上面几种方法来试试看
大多数时候是没办法给你完全满意的代码的,不满意的地方就需要自己去做
#27
我是想自己做啊..但是效果不是很好..想问一问大家有没有更好的办法??
我的方法:1.在内存DC中画透明的底图,再在上面写文字或者画上图片.
2.通过内存DC中的图形和透明色值计算出CRGN.
3.将窗口设置成为上一步中产生出来的形状.
4.在ONPAINT中将内存DC画上.
效果:如果文字及位置不变动,则效果非常好,其实就是做一个不规则的窗口.
如果文字及位置经常变动(如显示的是时间),则效果非常差,闪烁不停.
我的方法:1.在内存DC中画透明的底图,再在上面写文字或者画上图片.
2.通过内存DC中的图形和透明色值计算出CRGN.
3.将窗口设置成为上一步中产生出来的形状.
4.在ONPAINT中将内存DC画上.
效果:如果文字及位置不变动,则效果非常好,其实就是做一个不规则的窗口.
如果文字及位置经常变动(如显示的是时间),则效果非常差,闪烁不停.
#28
直接保存一部分桌面,再画透明的文字上去,文字变的时候再BLT保存的那部分,再画.应该不慢吧
#29
我以前做过一个,就是hook+注入explore进程的dll+subclassing技术做的,效果不错,还可以显示滚动图片,可以自己设定滚动速度等等,如果要的话,我可以发给你源代码,不过别忘了给分哦^_^
#30
tofoxmail(萧遥 www.LoveSnow.com),这个方法我也试过。。但是如果背景也是动画的话也是很慢的。。
#31
to:checkyvc6(checkyvc6),要啊。。要多少分都可以给你。。我的邮箱:
zxz@danter.net
postmaster@danter.net都可以。。
zxz@danter.net
postmaster@danter.net都可以。。
#32
大哥,怎么还没发给我啊??
#33
不好意思,今天我才看到,现在我已经发给你了,不好意思哦
不过有个前提,把ActiveDesktop关闭掉.别忘了 给分哦 ^_^
不过有个前提,把ActiveDesktop关闭掉.别忘了 给分哦 ^_^
#34
checkyvc6(checkyvc6)
给我一个行不行?
bandry_li@163.com
给我一个行不行?
bandry_li@163.com
#35
可以啊,不过你能给我分吗?我现在正在升级呢,没有办法!帮帮忙 ^_^
我已经发给你了!
我已经发给你了!
#36
To:checkyvc6
麻烦也发我一份,谢谢!
ioat@sina.com
麻烦也发我一份,谢谢!
ioat@sina.com
#37
你有分吗?开个贴给我分,ok?我马上发.没有办法啊
#38
我试运行了一下,只是在桌面上透明,而我是要求要在所有窗口上面都能够透明,而且要永远在所有窗口上面能够透明啊。。。
#39
你什么意思?
我不太明白。
能不能说的更清楚一点。或者举个例子(有什么类似的软件或者效果)
我不太明白。
能不能说的更清楚一点。或者举个例子(有什么类似的软件或者效果)
#40
你的窗口注意处理成是一直最前面的