设计一单文档程序;采用VC++为编程工具,实现鼠标拖动的画图功能;
展开全部
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
POINT pt={0,0};
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
HWND hwnd;
MSG msg;
BOOL bRet;
WNDCLASS wndcls;
wndcls.style=CS_HREDRAW|CS_VREDRAW;
wndcls.lpfnWndProc=WinProc;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.lpszClassName=TEXT("wjbxngx");
wndcls.lpszMenuName=NULL;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hInstance=hInstance;
RegisterClass(&wndcls);
hwnd=CreateWindow(TEXT("wjbxngx"),TEXT("示例"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
while ((bRet=GetMessage(&msg,hwnd,0,0))!=0)
{
if (bRet==-1)
{
return -1;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
TCHAR szChar[20];
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_CHAR:
sprintf(szChar,TEXT("char code is %d"),wParam);
MessageBox(hwnd,szChar,TEXT("char"),0);
break;
case WM_LBUTTONDOWN:
pt.x=LOWORD(lParam);
pt.y=HIWORD(lParam);
break;
case WM_RBUTTONDOWN:
InvalidateRect(hwnd,NULL,TRUE);
break;
case WM_MOUSEMOVE:
if (wParam&MK_LBUTTON)
{
hdc=GetDC(hwnd);
MoveToEx(hdc,pt.x,pt.y,NULL);
LineTo(hdc,LOWORD(lParam),HIWORD(lParam));
pt.x=LOWORD(lParam);
pt.y=HIWORD(lParam);
ReleaseDC(hwnd,hdc);
}
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
//TextOut(hdc,0,0,TEXT("wjbxngx's house"),lstrlen("wjbxngx's house"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if (IDYES==MessageBox(hwnd,TEXT("真的要退出吗?"),TEXT("信息"),MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
#include <stdio.h>
LRESULT CALLBACK WinProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
POINT pt={0,0};
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
HWND hwnd;
MSG msg;
BOOL bRet;
WNDCLASS wndcls;
wndcls.style=CS_HREDRAW|CS_VREDRAW;
wndcls.lpfnWndProc=WinProc;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.lpszClassName=TEXT("wjbxngx");
wndcls.lpszMenuName=NULL;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hInstance=hInstance;
RegisterClass(&wndcls);
hwnd=CreateWindow(TEXT("wjbxngx"),TEXT("示例"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
while ((bRet=GetMessage(&msg,hwnd,0,0))!=0)
{
if (bRet==-1)
{
return -1;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
TCHAR szChar[20];
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_CHAR:
sprintf(szChar,TEXT("char code is %d"),wParam);
MessageBox(hwnd,szChar,TEXT("char"),0);
break;
case WM_LBUTTONDOWN:
pt.x=LOWORD(lParam);
pt.y=HIWORD(lParam);
break;
case WM_RBUTTONDOWN:
InvalidateRect(hwnd,NULL,TRUE);
break;
case WM_MOUSEMOVE:
if (wParam&MK_LBUTTON)
{
hdc=GetDC(hwnd);
MoveToEx(hdc,pt.x,pt.y,NULL);
LineTo(hdc,LOWORD(lParam),HIWORD(lParam));
pt.x=LOWORD(lParam);
pt.y=HIWORD(lParam);
ReleaseDC(hwnd,hdc);
}
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
//TextOut(hdc,0,0,TEXT("wjbxngx's house"),lstrlen("wjbxngx's house"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if (IDYES==MessageBox(hwnd,TEXT("真的要退出吗?"),TEXT("信息"),MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
追问
你有QQ么,我是个新手,不知道怎么运行怎么实现鼠标拖动
追答
QQ当然有.1026434746.加你了.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询