zoukankan      html  css  js  c++  java
  • 枚举子窗口EnumChildWindows()的应用

    1、
    EnumChildWindows()函数的作用枚举子窗口(按顺序调用回调函数,并将子窗口的句柄传递给了回调函数)。函数原型:

    BOOL WINAPI EnumChildWindows(
    HWND hWndParent, //父窗口句柄
    WNDENUMPROC lpEnumFunc, //回调函数
    LPARAM lParam //自定义参数
    );
    回调函数的返回值将会影响到这个API函数的行为:如果回调函数返回true,则枚举继续直到枚举完成;如果返回false,则将会中止枚举
    。函数原型如下:

    BOOL CALLBACK EnumChildProc(HWND hwndChild,//子窗口句柄
    LPARAM lParam //参数
    )。

    应用举例1:一个父窗口,当窗口改变大小时它的子窗口也要跟着改变,可以利用EnumChildWindows()。代码如下

    #define ID_FIRSTCHILD  100 
    #define ID_SECONDCHILD 101 
    #define ID_THIRDCHILD  102 
     
    LONG APIENTRY MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
    { 
        RECT rcClient; 
        int i; 
        switch(uMsg) 
        { 
            case WM_CREATE: 
                for (i = 0; i < 3; i++) 
                { 
                    CreateWindowEx(0, 
                                   "ChildWClass", 
                                   (LPCTSTR) NULL, 
                                   WS_CHILD | WS_BORDER, 
                                   0,0,0,0, 
                                   hwnd, 
                                   (HMENU) (int) (ID_FIRSTCHILD + i), 
                                   hinst, 
                                   NULL); 
                }
     
                return 0; 
     
            case WM_SIZE:   
                GetClientRect(hwnd, &rcClient); 
                EnumChildWindows(hwnd, EnumChildProc, (LPARAM) &rcClient); 
                return 0; . 
        } 
        return DefWindowProc(hwnd, uMsg, wParam, lParam); 
    } 
     
    BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam) 
    { 
        LPRECT rcParent; 
        int i, idChild; 
        idChild = GetWindowLong(hwndChild, GWL_ID); 
     
        if (idChild == ID_FIRSTCHILD) 
            i = 0; 
        else if (idChild == ID_SECONDCHILD) 
            i = 1; 
        else 
            i = 2;  
     
        rcParent = (LPRECT) lParam; 
        MoveWindow(hwndChild, 
                   (rcParent->right / 3) * i, 
                   0, 
                   rcParent->right / 3, 
                   rcParent->bottom, 
                   TRUE); 
     
        ShowWindow(hwndChild, SW_SHOW); 
     
        return TRUE;
    }

    MoveWindow()函数不仅能够移动窗口的位置,而且能够改变窗口的大小。

    应用举例2:一个父窗口,当窗口移动时它的子窗口也要跟着移动位置,也可以利用EnumChildWindows()。

    2、
    EnumWindows()函数枚举屏幕上所有的顶层窗口,并将窗口句柄传递给自定义的回调函数。与EnumChildWindows类似,回调函数返回FALSE
    将停止枚举,否则将继续到所有顶层窗口枚举完为止。

  • 相关阅读:
    [转]ASP.NET会话(Session)保存模式
    ASP.NET 2.0 实现伪静态网页方法
    显示带颜色的字符串
    sublime text 3.0使用
    sublime text插件
    cogs1715 动态逆序对
    双网卡bond
    解决CentOS6不能使用yum源
    查看磁盘io占用
    [office] 在word中的小技巧
  • 原文地址:https://www.cnblogs.com/milanleon/p/5623833.html
Copyright © 2011-2022 走看看