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(HINSTANCE hInstance, HINSTANCE hPervInstance, PSTR szCmdLine, int iCmdShow)
  9 {
 10     WNDCLASS wndclass;
 11     MSG msg;
 12     HWND hWnd;
 13     TCHAR Name_1[] = TEXT("MyClass"), Name_2[] = TEXT("MyWindows");
 14
 15     wndclass.cbClsExtra = 0;
 16     wndclass.cbWndExtra = 0;
 17     wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
 18     wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
 19     wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
 20     wndclass.hInstance = hInstance;
 21     wndclass.lpfnWndProc = WndProc;
 22     wndclass.lpszClassName = Name_1;
 23     wndclass.lpszMenuName = NULL;
 24     wndclass.style = CS_HREDRAW | CS_VREDRAW;
 25
 26     RegisterClass(&wndclass);
 27
 28     wndclass.lpfnWndProc = ChildWndProc;//同一个类派生的窗口过程
 29     wndclass.cbWndExtra = sizeof(long);//分配额外的 窗口过程空间
 30     wndclass.hIcon = NULL;//图标设置空
 31     wndclass.lpszClassName = szChildClass;//类名设置
 32
 33     RegisterClass(&wndclass);
 34
 35     hWnd = CreateWindow(Name_1, Name_2, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
 36         NULL, NULL, hInstance, NULL);
 37     ShowWindow(hWnd, iCmdShow);
 38     UpdateWindow(hWnd);
 39
 40     while(GetMessage(&msg, NULL, NULL, NULL))
 41     {
 42         TranslateMessage(&msg);
 43         DispatchMessage(&msg);
 44     }
 45     return msg.wParam;
 46 }
 47
 48 LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)//主窗口
 49 {
 50     static HWND hwndChild[DIVISIONS][DIVISIONS],z=0;//数组 [5][5]=25
 51     int cxBlock, cyBlock, x, y;
 52
 53     switch (msg)
 54     {
 55     case WM_CREATE://窗口生成
 56         for (x = 0; x < DIVISIONS; x++)
 57         {
 58             for (y = 0; y < DIVISIONS; y++)
 59             {
 60                 //数组窗口句柄保存
 61                 hwndChild[x][y] = CreateWindow(szChildClass, NULL, WS_CHILDWINDOW | WS_VISIBLE,
 62                     0, 0, 0, 0, hWnd, (HMENU)z++, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
 63                 //窗口风格为 子窗口 并且可视 初始大小位置 全部0 父窗口是主窗口 ,后面的参数为子窗口特有的标记 随意 不同即可 后面的是获取窗口实力句柄
 64             }
 65         }
 66         return 0;
 67     case WM_SIZE:
 68         cxBlock = LOWORD(lParam) / DIVISIONS;
 69         cyBlock = HIWORD(lParam) / DIVISIONS;
 70
 71         for (x = 0; x < DIVISIONS; x++)
 72         {
 73             for (y = 0; y < DIVISIONS; y++)
 74             {
 75                 MoveWindow(hwndChild[x][y], x*cxBlock, y*cyBlock, cxBlock, cyBlock, TRUE);
 76                 //设置窗口位置以及大小。
 77             }
 78         }
 79         return 0;
 80     case WM_LBUTTONDOWN:
 81         MessageBeep(0);
 82         return 0;
 83     case WM_DESTROY:
 84         PostQuitMessage(0);
 85         return 0;
 86     }
 87     return DefWindowProc(hWnd, msg, wParam, lParam);
 88 }
 89
 90 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)//子窗口过程 25个全部调用这个
 91 {
 92     HDC hdc;
 93     PAINTSTRUCT ps;
 94     RECT rect;
 95
 96     switch (msg)
 97     {
 98     case WM_CREATE:
 99         SetWindowLong(hWnd, 0, 0);//设置额外 内存为 0
100         return 0;
101     case WM_LBUTTONDOWN:
102         SetWindowLong(hWnd, 0, 1 ^ GetWindowLong(hWnd, 0));//设置额外 内存 为 0或1
103         InvalidateRect(hWnd, NULL, FALSE);//立即重绘
104         return 0;
105     case WM_PAINT:
106         hdc = BeginPaint(hWnd, &ps);
107
108         GetClientRect(hWnd, &rect);//获取窗口矩形大小
109         Rectangle(hdc, 0, 0, rect.right, rect.bottom);//重新绘制矩形
110         if (GetWindowLong(hWnd, 0))//如果标记了 就画XX
111         {
112             MoveToEx(hdc, 0, 0, NULL);
113             LineTo(hdc, rect.right, rect.bottom);
114             MoveToEx(hdc, 0, rect.bottom, NULL);
115             LineTo(hdc, rect.right, 0);
116         }
117
118         EndPaint(hWnd, &ps);
119         return 0;
120     }
121     return DefWindowProc(hWnd, msg, wParam, lParam);
122 }
时间: 2024-10-12 20:01:45

SDK源码分析 5的相关文章

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源码分析 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

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源码分析 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