程序的目的是希望在用户打开的当前窗口上按照一定的频率显示指定文字,理想效果是频率调得足够小时,用户的眼睛观察不到闪烁的文字
现在存在的问题是在某些不同的页面(比如vc6),文字信息会保持显示而刷新无效,而且似乎有明显的闪烁。
请求高手指点,下面是代码。
#include "stdafx.h"
#include "afxwin.h"
#include
//不显示黑框窗体
//#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
void drawtop()
{
char text[]="test";
//
CFont font;
font.CreateFont(
160, // nHeight
100, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("宋体"));
HDC hdc = GetWindowDC(GetForegroundWindow());
SetTextColor(hdc,RGB(255,0,0));
//背景色透明
SetBkMode(hdc,TRANSPARENT);
SelectObject( hdc, font );
TextOut(hdc, 100, 100, text, sizeof(text));
ReleaseDC(NULL,hdc);
}
int main( void )
{
RECT rect;
int wait=10;
//自己按ctrl+c退出
while(true)
{
HWND hwnd=GetForegroundWindow();
GetWindowRect(hwnd,&rect);
drawtop();
Sleep(wait);
InvalidateRect(hwnd,&rect,true);
//RedrawWindow(hwnd,&rect,NULL,RDW_INVALIDATE);
Sleep(1000-wait);
}
return 0;
}