设计一单文档程序;采用VC++为编程工具,实现鼠标拖动的画图功能;
答案:1 悬赏:30 手机版
解决时间 2021-03-03 13:26
- 提问者网友:容嬷嬷拿针来
- 2021-03-02 12:35
设计一单文档程序;采用VC++为编程工具,实现鼠标拖动的画图功能;
最佳答案
- 五星知识达人网友:毛毛
- 2019-09-20 10:50
#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;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯