用CFree写的Windows SDK 画线程序
1 新建窗口程序
纯C语言;
2 添加代码
在文件头部加入四个变量,
POINT startPoint;
POINT endPoint;
int m_LineWidth; //线宽
COLORREF m_LineColor;
在WM_PAINT消息处理段中加入;
startPoint.x=100;
startPoint.y=100;
endPoint.x=300;
endPoint.y=300;
m_LineWidth=5;
m_LineColor=RGB(120,250,110);
SelectObject(hdc,CreatePen(PS_SOLID,m_LineWidth,m_LineColor));
MoveToEx(hdc,startPoint.x,startPoint.y,NULL);
LineTo(hdc,endPoint.x,endPoint.y);
效果;
代码:
#include <windows.h>
#include "resource.h"/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);/* Current app instance */
HINSTANCE hInst;
/* Make the class name into a global variable */
TCHAR szClassName[] = TEXT("WindowsApp");POINT startPoint;
POINT endPoint;int m_LineWidth; //线宽
COLORREF m_LineColor;int WINAPI
WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil){HWND hwnd; /* This is the handle for our window */MSG messages; /* Here messages to the application are saved */WNDCLASSEX wincl; /* Data structure for the windowclass *//* Save this instance */hInst = hThisInstance;/* The Window structure */wincl.hInstance = hThisInstance;wincl.lpszClassName = szClassName;wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */wincl.style = CS_DBLCLKS; /* Catch double-clicks */wincl.cbSize = sizeof (WNDCLASSEX);/* Use default icon and mouse-pointer */wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);wincl.hCursor = LoadCursor (NULL, IDC_ARROW);wincl.lpszMenuName = MAKEINTRESOURCE (IDC_SDKDRAW);wincl.cbClsExtra = 0; /* No extra bytes after the window class */wincl.cbWndExtra = 0; /* structure or the window instance *//* Use Windows's default color as the background of the window */wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);/* Register the window class, and if it fails quit the program */if (!RegisterClassEx (&wincl))return 0;/* The class is registered, let's create the program*/hwnd = CreateWindowEx (0, /* Extended possibilites for variation */szClassName, /* Classname */TEXT("sdkdraw"), /* Title Text */WS_OVERLAPPEDWINDOW, /* default window */CW_USEDEFAULT, /* Windows decides the position */0, /* where the window ends up on the screen */CW_USEDEFAULT, /* The programs width */0, /* and height in pixels */HWND_DESKTOP, /* The window is a child-window to desktop */NULL, /* No menu */hThisInstance, /* Program Instance handler */NULL /* No Window Creation data */);/* Make the window visible on the screen */ShowWindow (hwnd, nFunsterStil);/* Run the message loop. It will run until GetMessage() returns 0 */while (GetMessage (&messages, NULL, 0, 0)){/* Translate virtual-key messages into character messages */TranslateMessage(&messages);/* Send message to WindowProcedure */DispatchMessage(&messages);}/* The program return-value is 0 - The value that PostQuitMessage() gave */return messages.wParam;
}/* This function is called by the Windows function DispatchMessage() */LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{PAINTSTRUCT ps;HDC hdc;RECT rt;TCHAR szHello[] = TEXT("Hello, C-Free!");switch (message) /* handle the messages */{case WM_COMMAND:switch (LOWORD(wParam)){case IDM_ABOUT:MessageBox (hwnd, TEXT ("sdkdraw v1.0\nCopyright (C) 2016\n"),TEXT ("About"), MB_OK | MB_ICONINFORMATION);break;case IDM_EXIT:DestroyWindow(hwnd);break;default:return DefWindowProc(hwnd, message, wParam, lParam); }break;case WM_PAINT:hdc = BeginPaint(hwnd, &ps);/* TODO: Add any drawing code here... *///GetClientRect(hwnd, &rt);//DrawText(hdc, szHello, lstrlen(szHello), &rt, DT_CENTER);startPoint.x=100;startPoint.y=100;endPoint.x=300;endPoint.y=300;m_LineWidth=5;m_LineColor=RGB(120,250,110);SelectObject(hdc,CreatePen(PS_SOLID,m_LineWidth,m_LineColor));MoveToEx(hdc,startPoint.x,startPoint.y,NULL);LineTo(hdc,endPoint.x,endPoint.y);EndPaint(hwnd, &ps);break;case WM_DESTROY:PostQuitMessage (0); /* send a WM_QUIT to the message queue */break;default: /* for messages that we don't deal with */return DefWindowProc (hwnd, message, wParam, lParam);}return 0;
}
用CFree写的Windows SDK 画线程序相关推荐
- windows应用(vc++2022)MFC基础到实战(4)-画线程序
目录 CWnd 对象 画图程序 新建MFC项目 鼠标位置成员变量 类向导增加消息处理函数 扩展画线功能 LineTo 函数 (wingdi.h) 两种常用画线方式 移动鼠标擦除和绘制线 继续扩展 CW ...
- Windows DC 画线
好久没搞MFC,复习下知识. CPaintDC .CWindowDC. CClientDC. CDC 关系图: 一句话概括: CPaintDC 无效区dc, 相当于Be ...
- java bresenham画直线_图形学笔记: Bresenham画线算法
图形学课本, 按规矩介绍完矩阵行列式, 第一个算法肯定就是Bresenham画线算法了. 來我们來看看算法 Bresenham是用来画一些不反走样的线段的. 都说了线段肯定有起点和终点, 假设我们: ...
- 计算机图形学学习笔记(4.1)画线算法
前言 现在的显示器都是像素点阵.但是图形在计算机中都用连续的线段或多边形等存储.因此在显示出来之前,要进行光栅化处理. 图形的光栅化(图形的扫描转换)分成两步: 1)根据图形的定义 在点阵单元上确定最 ...
- 【计算机图形学】扫面转换算法(DDA算法 中点画线算法 Bresenham画线算法)
模块1 扫描转换算法 一 实验目的 编写直线.弧线的光栅扫描转换算法,并对线宽与线形的算法加以探讨 用DDA算法.中点画线算法.Bresenham画线算法绘制直线(如果键盘输入数据,给出数据值:如果绘 ...
- VC++ 绘制线条 OnLButtonDown函数(DrawView.cpp) 利用SDK全局函数实现画线功能 利用MFC的CDC类实现画线功能 利用MFC的CClientDC类实现画线功能
目录 绘制线条 OnLButtonDown函数(DrawView.cpp) 利用SDK全局函数实现画线功能 利用MFC的CDC类实现画线功能 利用MFC的CClientDC类实现画线功能 接上:VC+ ...
- Quartz 实现画图片、写文字、画线、椭圆、矩形、棱形等。
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); ...
- IOS Quartz 各种绘制图形用法---实现画图片、写文字、画线、椭圆、矩形、棱形等...
// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affec ...
- IOS Quartz 各种绘制图形用法---实现画图片、写文字、画线、椭圆、矩形、棱形等
// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affec ...
最新文章
- MaxCompute2.0新功能介绍
- lisp xy轴不等比缩放_UV的详细解释,不懂得赶紧看过来!
- 【教程】怎么同时同时ping1000个IP地址?
- Flask基础(03)--创建第一个Flask程序
- celery监控服务器性能,Python:使用celery处理多个服务器上的参数列表
- 802.11无线信道详解
- ubuntu下adb的使用以及开启黑域
- python-科研绘图系列(7)-箱型图(盒型图)
- 第09课:一网打尽神经序列模型之 RNN 及其变种 LSTM、GRU
- nginx: [emerg] unknown directive “锘? in******
- 战略盲区,是看不见,还是不想看见?
- 论文封面摘要正文页码不同 WORD中怎么编辑页码不连续 设置目录和正文页码不同
- 【社区分享】专注移动端机器学习交流,TensorFlow Lite 中文兴趣小组招募中!
- 全球最大多物种水族馆将于5月23日向公众开放,容纳68000多只海洋动物 | 美通社头条...
- 完美修改证件照背景详细步骤,可以消除边界处的白边或者红边
- 万分之二用百分之怎么表示_万分之一符号怎么写
- Android学习之优化美女图片浏览器
- Java Pitfalls读书笔记1(语法)
- HDLC简介及相应hdlc实训
- 人工智能帮你3分钟完成股票抄底
热门文章
- 高数第七章知识点框架
- windows卸载程序提示“请等待当前程序完成卸载或更改“问题解决方法,windows卸载卡进程问题解决方法
- PyQt5 图形界面-基础准备:安装Qt Creater、Qt Designer工具,使用Qt Designer设计界面,安装PyQt5工具库
- cortex M内核优先级设置
- Linux minicom 软件退出方法
- [YTU]_2633( P3 数钱是件愉快的事)
- phpcms发布新闻到数据库_Phpcms V9网站从本地上传到服务器需要修改的地方小结
- mysql中主从_MySQL的主从
- 在vue项目中引入高德地图及其UI组件的方法
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:按钮组