利用MoveToEx和LineTo画横线
来源:互联网 发布:淘宝售后客服消差评 编辑:程序博客网 时间:2024/05/29 02:00
MoveToEx
The MoveToEx function updates the current position to the specified point and optionally returns the previous position.
BOOL MoveToEx( HDC hdc, // handle to device context int X, // x-coordinate of new current position int Y, // y-coordinate of new current position LPPOINT lpPoint // old current position);
Parameters
- hdc
- [in] Handle to a device context.
- X
- [in] Specifies the x-coordinate, in logical units, of the new position, in logical units.
- Y
- [in] Specifies the y-coordinate, in logical units, of the new position, in logical units.
- lpPoint
- [out] Pointer to a POINT structure that receives the previous current position. If this parameter is a NULL pointer, the previous position is not returned.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Windows NT/2000/XP: To get extended error information, call GetLastError.
LineTo
The LineTo function draws a line from the current position up to, but not including, the specified point.
BOOL LineTo( HDC hdc, // device context handle int nXEnd, // x-coordinate of ending point int nYEnd // y-coordinate of ending point);
Parameters
- hdc
- [in] Handle to a device context.
- nXEnd
- [in] Specifies the x-coordinate, in logical units, of the line's ending point.
- nYEnd
- [in] Specifies the y-coordinate, in logical units, of the line's ending point.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Windows NT/2000/XP: To get extended error information, call GetLastError.
Remarks
LineTo.c
/* -------------------------------------------------------------------Author:邱于涵Time:2016年11月26日23:29:05--------------------------------------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[] = TEXT("MyWindows");HWND hwnd;MSG msg;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);wndclass.lpszMenuName = NULL;wndclass.lpszClassName = szAppName;if (!RegisterClass(&wndclass)){MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);return 0;}hwnd = CreateWindow(szAppName,TEXT("涵涵工作室"),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;}LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){HDC hdc;PAINTSTRUCT ps;RECT rect;switch (message){case WM_PAINT:hdc = GetDC(hwnd);MoveToEx(hdc, 100, 100, NULL);//MoveToEx的最后一个参数可以存放 上次的 坐标,//GetCurrentPositionEx 获得当前坐标LineTo(hdc, 600, 100);//LineTo画完后 坐标会跟着改变LineTo(hdc, 300, 300);ReleaseDC(hwnd, hdc);return 0;case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, message, wParam, lParam);}
DrawGrid.c
/* -------------------------------------------------------------------Author:邱于涵Time:2016年11月27日00:01:25课后作业:要求绘制一个网格要求线与线之间距离 50px--------------------------------------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[] = TEXT("MyWindows");HWND hwnd;MSG msg;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);wndclass.lpszMenuName = NULL;wndclass.lpszClassName = szAppName;if (!RegisterClass(&wndclass)){MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);return 0;}hwnd = CreateWindow(szAppName,TEXT("涵涵工作室"),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;}LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){HDC hdc;PAINTSTRUCT ps;static RECT rect;int i;switch (message){case WM_SIZE://当窗体大小发生改变时候 这个WM_SIZE消息被发出hdc = GetDC(hwnd);GetClientRect(hwnd,&rect);ReleaseDC(hwnd, hdc);break;case WM_PAINT:hdc = GetDC(hwnd);//纵向线条for (i = 0; i < rect.right; i += 50){MoveToEx(hdc, i, 0, NULL);LineTo(hdc, i, rect.bottom);}//横向线条for (i = 0; i < rect.bottom; i += 50){MoveToEx(hdc, 0, i, NULL);LineTo(hdc, rect.right, i);}ReleaseDC(hwnd, hdc);break;case WM_DESTROY:PostQuitMessage(0);break;}return DefWindowProc(hwnd, message, wParam, lParam);}
0 0
- 利用MoveToEx和LineTo画横线
- MoveToEx和LineTo函数
- MoveToEx和LineTo函数
- MoveToEx和LineTo函数
- (31)MoveToEx和LineTo函数
- MFC中MoveToEx函数和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- Windows API一日一练(31)MoveToEx和LineTo函数
- 记android学习之路----android多媒体使用之短信的收发
- 进程与线程的同步机制
- 【JavaScript】操作符
- opencv将Mat数据输出到xls中
- JAVA- DBUtil 封装数据库工具类
- 利用MoveToEx和LineTo画横线
- The Tomcat server configuration at\Servers\Tomcat v5.5 Server@ localhost-config is missing.
- 基于 OpenCV 的 LBP + SVM 人脸识别
- 记android学习之路----android传感器的使用
- 类初始化顺序执行结果
- spring Ioc的理解
- STM32F429——GPIO
- 系统开发生命周期
- 搭建私有的PyPI仓库源