64,639
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
HINSTANCE _hInstance;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Connect") ;
HWND hwnd ;
MSG msg ;
_hInstance=hInstance;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;//NULL;//
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow ( szAppName, TEXT ("Connect-the-Points Mouse Demo"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
HDC hdc,bgHdc,tHdc;
HBITMAP bgHmap;
LRESULT CALLBACK WndProc ( HWND hwnd, UINT message, WPARAM wParam,LPARAM
lParam)
{ static PAINTSTRUCT ps;
switch (message)
{
case WM_CREATE:
SetTimer (hwnd, 1, 20, NULL) ;
return 0;
case WM_LBUTTONDOWN:
return 0 ;
case WM_MOUSEMOVE:
InvalidateRgn(hwnd,0,TRUE);
hdc = BeginPaint(hwnd,&ps);
LineTo(hdc,LOWORD (lParam),HIWORD (lParam));
EndPaint(hwnd,&ps);
InvalidateRgn(hwnd,0,FALSE);
DeleteDC(hdc);
return 0 ;
case WM_LBUTTONUP:
return 0 ;
case WM_PAINT:
BeginPaint(hwnd,&ps);
EndPaint (hwnd, &ps);
return 0 ;
case WM_TIMER:
hdc = GetDC(hwnd);
bgHdc = CreateCompatibleDC(NULL);//GetDC(hwnd); //
bgHmap = (HBITMAP)LoadImage(_hInstance,"C:\\test.bmp",IMAGE_BITMAP,0,0,LR_DEFAULTCOLOR|LR_LOADFROMFILE);
SelectObject(bgHdc,bgHmap);
//bgHmap = CreateCompatibleBitmap(bgHdc,
// GetDeviceCaps(hdc, HORZRES),
// GetDeviceCaps(hdc, VERTRES));
//SelectObject(bgHdc, bgHmap);
BeginPaint(hwnd,&ps);
LineTo(bgHdc,300,100);
LineTo(bgHdc,100,100);
LineTo(bgHdc,200,100);
LineTo(bgHdc,400,100);
LineTo(bgHdc,500,100);
LineTo(bgHdc,100,200);
LineTo(bgHdc,300,100);
LineTo(bgHdc,100,500);
EndPaint (hwnd, &ps) ;
BitBlt(hdc,0,0,600,400,bgHdc,0,0,SRCCOPY);
DeleteDC(hdc);
DeleteDC(bgHdc);
DeleteObject(bgHmap);
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}