设计一单文档程序;采用VC++为编程工具,实现鼠标拖动的画图功能;

 我来答
七月流光1
2011-12-28 · TA获得超过528个赞
知道小有建树答主
回答量:339
采纳率:100%
帮助的人:190万
展开全部
#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;
}
追问
你有QQ么,我是个新手,不知道怎么运行怎么实现鼠标拖动
追答
QQ当然有.1026434746.加你了.
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式