BeginPaint 的動作
1.將無效區域 變成有效區域
2.傳送WM_ERASEBACKGROUND訊息,重新繪製背景
3.只能在WM_PAINT中呼叫
4.和EndPaint(hWnd,&ps) 成雙成對
// Message dispatch table for MainWindowProc
WM_PAINT, DoPaintMain,
in ,h 檔
LRESULT DoPaintMain (HWND, UINT, WPARAM, LPARAM);
//設定點的結構
typedef struct tagPOINTS2
{
SHORT x;
SHORT y;
} POINTS2;
LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
//*********************貼圖***********************//
//http://genewince.blogspot.com/2008/03/evc-4-resource.html 如何加入bmp資源擋
DWORD a;
ULONG b;
LPVOID c;
PUCHAR d;
HANDLE e;
PAINTSTRUCT ps;
RECT rect;
HDC hdc;
BITMAP bm;
GetUpdateRect(hWnd,&rect,1);
HBITMAP hBitmap2 = SHLoadDIBitmap(TEXT("//Storage Card//33332.bmp"));
//HBITMAP hBitmap2;
//hBitmap2 = LoadBitmap(hInst,(LPCTSTR)IDB_BITMAP1);
GetClientRect (hWnd, &rect);//取得用戶視窗矩形大小
hdc = BeginPaint(hWnd,&ps);
if (Pressing){ Rectangle(hdc,pt.x,pt.y,cur_pt.x,cur_pt.y); // 繪畫選取矩形
old_pt.x=cur_pt.x;
old_pt.y=cur_pt.y;
}
if(old_pt.x==cur_pt.x && old_pt.y==cur_pt.y){
Rectangle(hdc,pt.x,pt.y,cur_pt.x,cur_pt.y);
}
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hBitmap2);
GetObject(hBitmap2, sizeof(BITMAP), &bm);//取得圖片大小資訊
// BitBlt(hdc , rect.left , rect.top , bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);//SRCCOPY
StretchBlt(hdc , rect.left , rect.top , (bm.bmWidth)/1, (bm.bmHeight)/1, hdcMem, 0, 0, bm.bmWidth,bm.bmHeight, SRCCOPY);//SRCCOPY
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
// EndPaint(hWnd, &ps);
// return 0;
//*********************貼圖***********************//
//*********************畫點***********************//
SetPixel(hdc,400,400,RGB(0x00,0x00,0xFF));
//*********************畫點***********************//
//*********************畫線***********************//
//
POINT pts[2];
pts[0].x=20;
pts[0].y=20;
pts[1].x=200;
pts[1].y=150;
Polyline(hdc, pts ,2);
HPEN hPen = CreatePen(PS_DASH,1,RGB(0xff,0x88,0x0));
SelectObject(hdc, hPen);
MoveToEx(hdc,150,150,NULL);
LineTo(hdc,500,160);
//*********************畫線***********************//
//*********************畫形狀********************//
HBRUSH hBrush;
hBrush = CreateSolidBrush(RGB(0xAA,0x55,0x55));
SelectObject(hdc, hBrush);
Rectangle(hdc,200,200,550,500);//方
hBrush = CreateSolidBrush(RGB(0x22,0xAA,0x33));
SelectObject(hdc, hBrush);
Ellipse(hdc,300,100,500,300);//圓
hBrush = CreateSolidBrush(RGB(0x22,0x2A,0xAA));
SelectObject(hdc, hBrush);
RoundRect(hdc,0,300,200,500,50,30);//圓角方
hBrush = CreateSolidBrush(RGB(0xdd,0x6A,0xAA));
SelectObject(hdc, hBrush);
POINT ppt[3];
ppt[0].x=60;
ppt[0].y=60;
ppt[1].x=20;
ppt[1].y=100;
ppt[2].x=100;
ppt[2].y=100;
Polygon(hdc,ppt,3);//多邊三角形
TRIVERTEX vert[2];
GRADIENT_RECT gRect;
RECT prect = {100 , 300 , 300 ,500};
vert[0].x=prect.left;
vert[0].y=prect.top;
vert[0].Red=0xAC00;
vert[0].Green=0xF300;
vert[0].Blue=0x8100;
vert[0].Alpha=0x0000;
vert[1].x=prect.right;
vert[1].y=prect.bottom;
vert[1].Red=0xA300;
vert[1].Green=0x5700;
vert[1].Blue=0xD500;
vert[1].Alpha=0x0000;
gRect.UpperLeft=1;
gRect.LowerRight=0;
GradientFill(hdc,vert,2,&gRect,1,GRADIENT_FILL_RECT_H);
//*********************畫形狀********************//
//****************顯示有變數的文字**************//
TCHAR szOut[256];
a=sizeof(DOUBLE);
wsprintf(szOut,TEXT("a=%d"),a);
ExtTextOut(hdc,200,200,0,NULL,szOut,lstrlen(szOut),NULL);
//****************顯示有變數的文字***************//
// PAINTSTRUCT ps;
// RECT rect;
// HDC hdc;
RECT rectText = rect;
rectText.left=0;
rectText.top=0;
// Get the size of the client rectangle
GetClientRect (hWnd, &rect);
SetBkMode (hdc, TRANSPARENT);
hdc = BeginPaint (hWnd, &ps);
DrawText (hdc, TEXT ("馬"), -1, &rectText, DT_SINGLELINE);
EndPaint (hWnd, &ps);
return 0;
}