程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何对组合框编译错误进行子类化大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何对组合框编译错误进行子类化?

开发过程中遇到如何对组合框编译错误进行子类化的问题如何解决?下面主要结合日常开发的经验,给出你关于如何对组合框编译错误进行子类化的解决方法建议,希望对你解决如何对组合框编译错误进行子类化有所启发或帮助;

我正在验证来自 Microsoft 开发站点的代码。 https://docs.microsoft.com/en-us/windows/win32/controls/subclass-a-combo-box 这项工作是为了帮助我了解在不久的将来构建 GUI 的组件。我不知道为什么编译时会出现错误,因为这是直接来自 Microsoft 网站的代码。

#define WM_TAB (WM_USER) 
#define WM_ESC (WM_USER + 1) 
#define WM_ENTER (WM_USER + 2) 

//  Global variables
HWND    hwndMain;
WNDPROC lpfnEditWndProc; //  Original wndproc for the combo Box 

//  Prototypes
LRESulT CALLBACK SubClassproc(HWND,UINT,WParaM,LParaM);

/********************************************************

    FUNCTION:   ToolbarWindowProc

    PURPOSE:    Window procedure for the toolbar window

*********************************************************/

LRESulT CALLBACK ToolbarWindowProc(HWND hwnd,UINT msg,WParaM wParam,LParaM lParam)
{
    static HWND   hwndEdit1;
    static HWND   hwndEdit2;
    static HWND   hwndCombo1;
    static HWND   hwndCombo2;
    POINT       pt;
    DWORD       DWBaseUnits;
    HWND        hwndCombo;
    DWORD       DWIndex;
    char achTemp[256];       //  Temporary buffer 

    switch (msg)
    {
    case WM_CREATE:
        //  Create two combo Box child windows. 
        DWBaseUnits = GetDialogBaseUnits();

        hwndCombo1 = CreateWindow(L"COMBOBox",L"",CBS_DROPDOWN | WS_CHILD | WS_VISIBLE,(6 * LOWORD(DWBaseUnits)) / 4,(2 * HIWORD(DWBaseUnits)) / 8,(100 * LOWORD(DWBaseUnits)) / 4,(50 * HIWORD(DWBaseUnits)) / 8,hwnd,NulL,null);

        hwndCombo2 = CreateWindow(L"COMBOBox",(112 * LOWORD(DWBaseUnits)) / 4,hInst,null);

        //  Get the edit window handle to each combo Box. 
        pt.x = 1;
        pt.y = 1;
        hwndEdit1 = ChilDWindowFromPoint(hwndCombo1,pt);
        hwndEdit2 = ChilDWindowFromPoint(hwndCombo2,pt);

        //  Change the window procedure for both edit windows 
        //  to the subclass procedure. 
        lpfnEditWndProc = (WNDPROC)SetwindowLongPtr(hwndEdit1,GWLP_WNDPROC,(LONG_PTR)SubClassproc);

        SetwindowLongPtr(hwndEdit2,(LONG_PTR)SubClassproc);

        break;

    case WM_SETFOCUS:
        SetFocus(hwndCombo1);
        break;

    case WM_TAB:
        if (GetFocus() == hwndEdit1)
            SetFocus(hwndCombo2);
        else
            SetFocus(hwndCombo1);
        break;

    case WM_ESC:
        hwndCombo = GetFocus() == hwndEdit1 ? hwndCombo1 : hwndCombo2;

        // Clear the current SELEction. 
        Sendmessage(hwndCombo,CB_SETcursEL,(WParaM)(-1),0);

        //  Set the focus to the main window. 
        SetFocus(hwndMain);
        break;

    case WM_ENTER:
        hwndCombo = GetFocus() == hwndEdit1 ? hwndCombo1 : hwndCombo2;
        SetFocus(hwndMain);

        //  If there is no current SELEction,set one. 
        if (Sendmessage(hwndCombo,CB_GETcursEL,0)
            == CB_ERR)
        {
            if (Sendmessage(hwndCombo,WM_GETTEXT,sizeof(achTemp),(LParaM)achTemp) == 0)
                break;      //  Empty SELEction fIEld 
            DWIndex = Sendmessage(hwndCombo,CB_FINDStriNGEXACT,(LParaM)achTemp);

            //  Add the String,if necessary,and SELEct it. 
            if (DWIndex == CB_ERR)
                DWIndex = Sendmessage(hwndCombo,CB_ADDStriNG,(LParaM)achTemp);
            if (DWIndex != CB_ERR)
                Sendmessage(hwndCombo,DWIndex,0);
        }
        break;

        // . 
        // .  Process additional messages. 
        // . 

    default:
        return DefWindowProc(hwnd,msg,wParam,lParam);
    }
    return 0;
}


/********************************************************

    FUNCTION:   SubClassproc

    PURPOSE:    Process TAB and ESCAPE keys,and pass all
                other messages to the class window
                procedure.

*********************************************************/
LRESulT CALLBACK SubClassproc(HWND hwnd,LParaM lParam)
{
    switch (msg)
    {
    case WM_KEYDOWN:
        switch (wParam)
        {
        case VK_TAB:
            Sendmessage(hwndMain,WM_TAB,0);
            return 0;
        case VK_ESCAPE:
            Sendmessage(hwndMain,WM_ESC,0);
            return 0;
        case VK_RETURN:
            Sendmessage(hwndMain,WM_ENTER,0);
            return 0;
        }
        break;

    case WM_KEYUP:
    case WM_CHAR:
        switch (wParam)
        {
        case VK_TAB:
        case VK_ESCAPE:
        case VK_RETURN:
            return 0;
        }
    }

    //  Call the original window procedure for default processing. 
    return CallWindowProc(lpfnEditWndProc,lParam);
}

Visual studio 2019 产生的错误是:

E0020   IDentifIEr "hInst" is undefined ComboBox
Error   C2065   'hInst': undeclared IDentifIEr  ComboBox    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的如何对组合框编译错误进行子类化全部内容,希望文章能够帮你解决如何对组合框编译错误进行子类化所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: