#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <tchar.h>
//全局变量
HINSTANCE hInst;
UINT nDesktopWidth;
UINT nDesktopHeight;
//绘制文本
static void FLOATTEXT_OnPaint(HWND hWnd)
{
HDC hdc;
int len;
TCHAR text[256];
PAINTSTRUCT ps;
hdc = BeginPaint(hWnd,&ps);
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(255,0,0));
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
len = GetWindowText(hWnd,text,256);
TextOut(hdc,0,0,text,len);
EndPaint(hWnd,&ps);
}
//窗口定时器,移动窗口
static void FLOATTEXT_OnTimer(HWND hWnd)
{
RECT rc;
GetWindowRect(hWnd,&rc);
if(rc.right < 0)
{
OffsetRect(&rc,-rc.left,0);
OffsetRect(&rc,nDesktopWidth,0);
}
OffsetRect(&rc,-1,0);
MoveWindow(hWnd,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,1);
}
//初始化窗口属性
static void FLOATTEXT_OnCreate(HWND hWnd, LPCREATESTRUCT cs)
{
SetLayeredWindowAttributes(hWnd,0,0,LWA_COLORKEY);
SetTimer
C++实现弹幕
最新推荐文章于 2024-10-22 20:46:20 发布