SDK源码分析 3

  1 #include <windows.h>
  2 #define MAXPOINTS 1000
  3
  4 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//窗口过程
  5
  6 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  7 {
  8     WNDCLASS wndclass;
  9     MSG msg;
 10     HWND hWnd;
 11     TCHAR Name_1[] = TEXT("MyClass"), Name_2[] = TEXT("MyWindows");
 12
 13     //设置类风格
 14     wndclass.cbClsExtra = 0;
 15     wndclass.cbWndExtra = 0;
 16     wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
 17     wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
 18     wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
 19     wndclass.hInstance = hInstance;
 20     wndclass.lpfnWndProc = WndProc;
 21     wndclass.lpszClassName = Name_1;
 22     wndclass.lpszMenuName = NULL;
 23     wndclass.style = CS_HREDRAW | CS_VREDRAW;
 24
 25     RegisterClass(&wndclass);
 26
 27     hWnd = CreateWindow(Name_1, Name_2, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
 28         NULL, hInstance, NULL);
 29
 30     UpdateWindow(hWnd);
 31     ShowWindow(hWnd, iCmdShow);
 32
 33     //消息循环
 34     while (GetMessage(&msg, NULL, NULL, NULL))
 35     {
 36         TranslateMessage(&msg);//翻译键盘消息
 37         DispatchMessage(&msg);//转发消息给 WndProc
 38     }
 39     return msg.wParam;
 40 }
 41
 42 LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 43 {
 44     static POINT pt[MAXPOINTS];//定义 POINT 坐标类型 数组大小1000
 45     static int  iCound;//记录变量
 46     int i, j;
 47     PAINTSTRUCT ps;
 48     HDC hdc;
 49
 50     switch (msg)
 51     {
 52     case WM_LBUTTONDOWN://当鼠标按下之后 记录归零 重画窗口 背景清除
 53         iCound = 0;
 54         InvalidateRect(hWnd, NULL, TRUE);
 55         return 0;
 56     case WM_MOUSEMOVE://当鼠标移动的时候
 57         //消息 & MK_LBUTTON 并且 记录小于 1000
 58         // 如果现在是按下状态 并且 记录 <1000
 59         if (wParam & MK_LBUTTON && iCound < 1000)
 60         {
 61             //每次保存 记录 并且累加记录
 62             pt[iCound].x = LOWORD(lParam);
 63             pt[iCound++].y = HIWORD(lParam);
 64
 65             hdc = GetDC(hWnd);
 66             SetPixel(hdc, LOWORD(lParam), HIWORD(lParam), 0);//画出一个个像素点
 67             ReleaseDC(hWnd, hdc);
 68         }
 69         return 0;
 70     case WM_LBUTTONUP:
 71         InvalidateRect(hWnd, NULL, FALSE);//当鼠标松开 重绘窗口 不擦除 背景
 72         return 0;
 73     case WM_PAINT:
 74         hdc=BeginPaint(hWnd, &ps);
 75
 76         //显示忙碌鼠标
 77         SetCursor(LoadCursor(NULL, IDC_WAIT));
 78         ShowCursor(TRUE);
 79
 80         //i=0;i<999;i++
 81         //j=i+1;j<1000;j++
 82         //画出 点.
 83         /*
 84         比如 当前 循环一次 i=0;i<999;
 85         j=1;j<1000;
 86         画: pt[0].x pt[0].y
 87         到: pt[1].x pt[1].y
 88
 89         当前 循环 7次 i=6;i<999;
 90         j=7;j<1000;
 91         画: pt[6].x pt[6].y
 92         到: pt[7].x pt[7].y
 93         */
 94         for (i = 0; i < iCound - 1; i++)
 95         {
 96             for (j = i + 1; j < iCound; j++)
 97             {
 98                 MoveToEx(hdc, pt[i].x, pt[i].y, NULL);
 99                 LineTo(hdc, pt[j].x, pt[j].y);
100             }
101         }
102         //更换鼠标.
103         ShowCursor(FALSE);
104         SetCursor(LoadCursor(NULL, IDC_ARROW));
105         EndPaint(hWnd, &ps);
106         return 0;
107     case WM_DESTROY:
108         PostQuitMessage(0);//程序结束
109         return 0;
110
111     }
112     return DefWindowProc(hWnd, msg, wParam, lParam);//默认给Windows 处理 多余的消息
113 }

时间: 2025-01-13 15:20:13

SDK源码分析 3的相关文章

SDK源码分析 10

1 #include <windows.h> 2 3 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 4 5 //定义结构体 一个是 int 一个是字符串 6 struct 7 { 8 int iStyle; 9 TCHAR *szText; 10 } 11 button[] = 12 { 13 BS_PUSHBUTTON, TEXT("PUSHBUTTON"), 14 BS_DEFPUSHBUTTON, TEXT

SDK源码分析 4

栗子1: 1 #include <windows.h> 2 3 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//回调函数 4 5 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) 6 { 7 WNDCLASS wndclass; 8 MSG msg; 9 HWND hWnd; 10 TCHAR

SDK源码分析 2

1 #include <windows.h> 2 3 //此处宏定义了一个函数.计算里面的东西 我也不是很懂在计算什么. 4 //观看到第90行 知道这句宏定义的意义 5 //意思是 容量+当前列*一行最大容量+当前位置 6 //例如有 100个 格子. 当前在 第5列 第3个位置 每行10个 有10列 7 //100+5*10+3=153 那么最大是100 为什么有153? 其实很简单. 8 #define BUFFER( x , y ) * (pBuffer + y * cxBuffer

SDK源码分析 5

1 #include <windows.h> 2 #define DIVISIONS 5 3 4 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 5 LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM); 6 TCHAR szChildClass[] = TEXT("Checker3_Child"); 7 8 int WINAPI WinMain(HIN

SDK源码分析 6

1 #include <windows.h> 2 #define DIVISIONS 5 3 4 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 5 LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM); 6 TCHAR szChildClass[] = TEXT("Checker3_Child"); 7 int idFocus = 0;//窗口ID 8

SDK源码分析 7

1 #include <windows.h> 2 3 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 4 5 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPervInstance, PSTR szCmdLine, int iCmdShow) 6 { 7 WNDCLASS wndclass; 8 MSG msg; 9 HWND hWnd; 10 TCHAR Name_1[] =

SDK源码分析 15

1 #include <windows.h> 2 #define ID_LIST 1 3 #define ID_TEXT 2 4 #define MAXREAD 8192 5 #define DIRATTR (DDL_READWRITE|DDL_READONLY|DDL_HIDDEN|DDL_SYSTEM| 6 DDL_DIRECTORY|DDL_ARCHIVE|DDL_DRIVES) 7 #define DTFLAGS (DT_WORDBREAK|DT_EXPANDTABS|DT_NOCLI

SDK源码分析 1

1 #include <windows.h> 2 3 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//回调函数 WndProc; 4 5 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) 6 { 7 8 WNDCLASS wndclass;//窗口类 9 static TCHAR szWindo

Weex Android SDK源码分析之Module(animation)

前言 module 怎能少得了动画呢~ 代码解读 weex code API 接口 transition(node, options, callback) Arguments 参数 node(Node):将要动画的元素. options(object):操作选项 styles(object):指定要应用的过渡效果的样式的名称和值. color(string):色彩的元素时,animaiton完成. transform(object):变换函数被应用到元素.支持下列值. translate/ tr