日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

用CFree写的Windows SDK 画线程序

發布時間:2025/4/14 windows 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用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 画线程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。