您尚未登录。

楼主 #1 2018-04-04 13:44:55

awfans
会员
注册时间: 2018-04-03
已发帖子: 264
积分: 264

这个回调函数 MybuttonWindowProc 中的句柄hWnd是谁的句柄啊?

static int MybuttonWindowProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)

这个回调函数 MybuttonWindowProc  中的句柄hWnd是谁的句柄啊?

离线

楼主 #2 2018-04-04 13:47:19

awfans
会员
注册时间: 2018-04-03
已发帖子: 264
积分: 264

Re: 这个回调函数 MybuttonWindowProc 中的句柄hWnd是谁的句柄啊?

#include <minigui/common.h>  
#include <minigui/minigui.h>  
#include <minigui/gdi.h>  
#include <minigui/window.h>  
#include <minigui/control.h>  
  
#define IDC_MYBUTTON    100  
#define IDC_MYBUTTON2    110  
  
int (*old_button_proc) (hWnd, message, wParam, lParam);     
static int MybuttonWindowProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)  
{  
   int temp;  
   temp = (*old_button_proc) (hWnd, message, wParam, lParam);           
   switch(message)
   {  
        case MSG_CREATE:
{   
              SetWindowBkColor(hWnd, COLOR_red);  
        }
break;
        case MSG_SETFOCUS:{  
               SetWindowBkColor(hWnd, COLOR_red); 
        }break;
         
case MSG_KILLFOCUS:
{  
                SetWindowBkColor(hWnd, COLOR_darkgray); 
          }break; 
    }  
     return(temp); 
}  
  
        
//注册自定义控件  
BOOL RegisterMybutton (void)  
{  
    WNDCLASS WndClass;  
WndClass.spClassName = CTRL_BUTTON;  
   
GetWindowClassInfo(&WndClass); 
     old_button_proc = WndClass.WinProc;  
    WndClass.spClassName = "mybutton";  
    WndClass.dwStyle     = 0;  
    WndClass.dwExStyle   = 0;  
    WndClass.hCursor     = GetSystemCursor(0);  
    WndClass.iBkColor    = PIXEL_lightgray;  
    WndClass.WinProc     = MybuttonWindowProc;  
  
    return RegisterWindowClass (&WndClass);  
}  
  
/* main windoww proc */  
static int CaptureWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)  
{  
    switch (message) {  
    case MSG_CREATE:  
        RegisterMybutton();//使用前,注册自定义控件  
  
         //创建自定义按钮控件  
        CreateWindow ("mybutton", "", WS_VISIBLE | WS_CHILD, IDC_MYBUTTON,   
                10, 95, 200, 20, hWnd, 0);  
     break;  
    
  
    case MSG_CLOSE:  
        DestroyAllControls (hWnd);  
        DestroyMainWindow (hWnd);  
        PostQuitMessage (hWnd);  
        return 0;  
    }  
  
    return DefaultMainWinProc(hWnd, message, wParam, lParam);  
}  
  
int MiniGUIMain (int args, const char* arg[])  
{  
    MSG Msg;  
    HWND hMainWnd;  
    MAINWINCREATE CreateInfo;  
  
#ifdef _MGRM_PROCESSES  
    JoinLayer(NAME_DEF_LAYER , "capture" , 0 , 0);  
#endif  
      
    CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;  
    CreateInfo.dwExStyle = WS_EX_NONE;  
    CreateInfo.spCaption = "using mouse capture demo";  
    CreateInfo.hMenu = 0;  
    CreateInfo.hCursor = GetSystemCursor(0);  
    CreateInfo.hIcon = 0;  
    CreateInfo.MainWindowProc = CaptureWinProc;  
    CreateInfo.lx = 0;  
    CreateInfo.ty = 0;  
    CreateInfo.rx = 320;  
    CreateInfo.by = 240;  
    CreateInfo.iBkColor = COLOR_lightwhite;  
    CreateInfo.dwAddData = 0;  
    CreateInfo.hHosting = HWND_DESKTOP;  
      
    hMainWnd = CreateMainWindow (&CreateInfo);  
      
    if (hMainWnd == HWND_INVALID)  
        return -1;  
  
    ShowWindow(hMainWnd, SW_SHOWNORMAL);  
  
    while (GetMessage(&Msg, hMainWnd)) {  
        TranslateMessage(&Msg);  
        DispatchMessage(&Msg);  
    }  
  
    MainWindowThreadCleanup (hMainWnd);  
  
    return 0;  
}  
  
#ifndef _LITE_VERSION  
#include <minigui/dti.c>  
#endif  #include <minigui/common.h>  
#include <minigui/minigui.h>  
#include <minigui/gdi.h>  
#include <minigui/window.h>  
#include <minigui/control.h>  
  
#define IDC_MYBUTTON    100  
#define IDC_MYBUTTON2    110  
  
int (*old_button_proc) (hWnd, message, wParam, lParam);     
static int MybuttonWindowProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)  
{  
   int temp;  
   temp = (*old_button_proc) (hWnd, message, wParam, lParam);           
   switch(message)
   {  
        case MSG_CREATE:
{   
              SetWindowBkColor(hWnd, COLOR_red);  
        }
break;
        case MSG_SETFOCUS:{  
               SetWindowBkColor(hWnd, COLOR_red); 
        }break;
         
case MSG_KILLFOCUS:
{  
                SetWindowBkColor(hWnd, COLOR_darkgray); 
          }break; 
    }  
     return(temp); 
}  
  
        
//注册自定义控件  
BOOL RegisterMybutton (void)  
{  
    WNDCLASS WndClass;  
WndClass.spClassName = CTRL_BUTTON;  
   
GetWindowClassInfo(&WndClass); 
     old_button_proc = WndClass.WinProc;  
    WndClass.spClassName = "mybutton";  
    WndClass.dwStyle     = 0;  
    WndClass.dwExStyle   = 0;  
    WndClass.hCursor     = GetSystemCursor(0);  
    WndClass.iBkColor    = PIXEL_lightgray;  
    WndClass.WinProc     = MybuttonWindowProc;  
  
    return RegisterWindowClass (&WndClass);  
}  
  
/* main windoww proc */  
static int CaptureWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)  
{  
    switch (message) {  
    case MSG_CREATE:  
        RegisterMybutton();//使用前,注册自定义控件  
  
         //创建自定义按钮控件  
        CreateWindow ("mybutton", "", WS_VISIBLE | WS_CHILD, IDC_MYBUTTON,   
                10, 95, 200, 20, hWnd, 0);  
     break;  
    
  
    case MSG_CLOSE:  
        DestroyAllControls (hWnd);  
        DestroyMainWindow (hWnd);  
        PostQuitMessage (hWnd);  
        return 0;  
    }  
  
    return DefaultMainWinProc(hWnd, message, wParam, lParam);  
}  
  
int MiniGUIMain (int args, const char* arg[])  
{  
    MSG Msg;  
    HWND hMainWnd;  
    MAINWINCREATE CreateInfo;  
  
#ifdef _MGRM_PROCESSES  
    JoinLayer(NAME_DEF_LAYER , "capture" , 0 , 0);  
#endif  
      
    CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;  
    CreateInfo.dwExStyle = WS_EX_NONE;  
    CreateInfo.spCaption = "using mouse capture demo";  
    CreateInfo.hMenu = 0;  
    CreateInfo.hCursor = GetSystemCursor(0);  
    CreateInfo.hIcon = 0;  
    CreateInfo.MainWindowProc = CaptureWinProc;  
    CreateInfo.lx = 0;  
    CreateInfo.ty = 0;  
    CreateInfo.rx = 320;  
    CreateInfo.by = 240;  
    CreateInfo.iBkColor = COLOR_lightwhite;  
    CreateInfo.dwAddData = 0;  
    CreateInfo.hHosting = HWND_DESKTOP;  
      
    hMainWnd = CreateMainWindow (&CreateInfo);  
      
    if (hMainWnd == HWND_INVALID)  
        return -1;  
  
    ShowWindow(hMainWnd, SW_SHOWNORMAL);  
  
    while (GetMessage(&Msg, hMainWnd)) {  
        TranslateMessage(&Msg);  
        DispatchMessage(&Msg);  
    }  
  
    MainWindowThreadCleanup (hMainWnd);  
  
    return 0;  
}  
  
#ifndef _LITE_VERSION  
#include <minigui/dti.c>  
#endif  

代码是这个, MiniGUI的自定义button代码

离线

#3 2018-04-04 13:52:02

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,245
积分: 9197

Re: 这个回调函数 MybuttonWindowProc 中的句柄hWnd是谁的句柄啊?

这个hWnd是当前这个自定义 button的句柄.
在MiniGUI内部用来查找控件数据结构的唯一Id





离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn