SDK源码分析 5

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }

 

以上是关于SDK源码分析 5的主要内容,如果未能解决你的问题,请参考以下文章

Android 插件化VirtualApp 源码分析 ( 目前的 API 现状 | 安装应用源码分析 | 安装按钮执行的操作 | 返回到 HomeActivity 执行的操作 )(代码片段

Android 逆向整体加固脱壳 ( DEX 优化流程分析 | DexPrepare.cpp 中 dvmOptimizeDexFile() 方法分析 | /bin/dexopt 源码分析 )(代码片段

Android 事件分发事件分发源码分析 ( Activity 中各层级的事件传递 | Activity -> PhoneWindow -> DecorView -> ViewGroup )(代码片段

Weex Android SDK源码分析之界面渲染(下)

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

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