只是往桌面上写一次,刷新就没有了,如果需要一直显示的话,就需要连续的写和画了.偶尔看了一下,还有不少人踩了上来,怎么就不留个脚印呢?
#include "stdafx.h"
#include "stdio.h"
#include "TCHAR.H"
HWND hWndDesk;
HDC hdc,hdcmem;//hdc1,
BITMAP bm;
HBITMAP hOldBmp;
HPEN hPen;
HANDLE hBitmapImag;
TCHAR szTemp[MAX_PATH]={0};
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char* cpText ="在桌面输出例程"; //要显示的字符串
hWndDesk=GetDesktopWindow();
if(hWndDesk==NULL)
MessageBox(NULL,"GetDesktopWindow() fail",NULL,0);
hPen=CreatePen(PS_SOLID,20,RGB(255,0,0));
if(hPen==NULL) MessageBox(NULL,"CreatePen() fail",NULL,0);
//hdc1=GetDC(hWndDesk);
hdc=GetWindowDC(hWndDesk); //hdc1 hdc 的结果不一样,句柄不一样,使用hdc1显示将没有效果,原因GetDC()得到的只是客户区的句柄,而GetWindowDC()得到的是包括非客户区的整个窗口的句柄,你可以在标题栏操作
//GetWindowText(hWndDesk,szTemp,MAX_PATH);
TextOut(hdc,100,100, cpText, strlen(cpText)); //在桌面上显示字符串
hBitmapImag=(HBITMAP)LoadImage(NULL,TEXT("c:\\pic.bmp"),IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);
if(!hBitmapImag) MessageBox(NULL,TEXT("LoadImage() fail"),NULL,0);
GetObject( hBitmapImag, sizeof( BITMAP), (LPVOID)&bm);
hdcmem=CreateCompatibleDC(hdc);
hOldBmp =(HBITMAP)SelectObject(hdcmem,hBitmapImag);
BitBlt(hdc,100,100,bm.bmWidth,bm.bmHeight,hdcmem,0,0,SRCCOPY);
SelectObject(hdc, hOldBmp);
DeleteObject(hPen);
ReleaseDC(hWndDesk, hdc);
return 0;
}