018 在桌面顯示文字

Post date: 2015/2/5 上午 08:19:05

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nShowCmd)

{

HDC hdc;

HWND hwnd;

COLORREF clr;

TCHAR szBuffer[] = TEXT("剩餘遊戲時間:10分鐘");

//获取桌面窗口句柄

hwnd = GetDesktopWindow();

//获取桌面窗口DC

hdc = GetWindowDC(hwnd);

//背景色透明

SetBkMode(hdc, TRANSPARENT);

//设置颜色并输出文字

SetBkMode(hdc, OPAQUE);

clr = SetTextColor(hdc, RGB(255, 0, 0));


int sw;

int sh;

// 取得畫面的寬與高

sw = GetSystemMetrics(SM_CXSCREEN);

sh = GetSystemMetrics(SM_CYSCREEN);


TextOut(hdc, sw - 160, 0, szBuffer, lstrlen(szBuffer));

//还原颜色

SetTextColor(hdc, clr);

//释放句柄DC

ReleaseDC(hwnd, hdc);

Sleep(5000);

return 0;

}