Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在win32 C++;_C++_Winapi_Visual C++_Graphics - Fatal编程技术网

C++ 如何在win32 C++;

C++ 如何在win32 C++;,c++,winapi,visual-c++,graphics,C++,Winapi,Visual C++,Graphics,我想创建一个具有圆角边的编辑框。我不能使用标准编辑框控件,因为它会绘制矩形编辑框 有什么建议或建议吗?您有几个选择:- 创建父控件,并在其中包含子无边框文本编辑控件 子类a文本编辑控件并重载NC_绘制以绘制边框 更新 在搞乱了一个示例程序后,我逐渐意识到,对编辑控件进行子分类并不能真正起作用,而在线检查证实了这一点(感谢MS如此一致!) 因此,只剩下选项1和选项3(想想看): 创建自己的编辑控件 下面是方法1的一个示例: #include <windows.h> LRESULT _

我想创建一个具有圆角边的编辑框。我不能使用标准编辑框控件,因为它会绘制矩形编辑框


有什么建议或建议吗?

您有几个选择:-

  • 创建父控件,并在其中包含子无边框文本编辑控件
  • 子类a文本编辑控件并重载NC_绘制以绘制边框
  • 更新

    在搞乱了一个示例程序后,我逐渐意识到,对编辑控件进行子分类并不能真正起作用,而在线检查证实了这一点(感谢MS如此一致!)

    因此,只剩下选项1和选项3(想想看):

  • 创建自己的编辑控件
  • 下面是方法1的一个示例:

    #include <windows.h>
    
    LRESULT __stdcall EditboxProc (HWND window, unsigned message, WPARAM w_param, LPARAM l_param)
    {
      bool
        use_default = true;
    
      LRESULT
        result = 0;
    
      switch (message)
      {
      case WM_CREATE:
        {
          RECT
            client;
    
          GetClientRect (window, &client);
    
          HWND
            edit = CreateWindowEx (0,
                                   TEXT ("Edit"),
                                   0,
                                   WS_VISIBLE | WS_CHILD,
                                   10,
                                   10,
                                   client.right - 20,
                                   client.bottom - 20,
                                   window,
                                   0,
                                   GetModuleHandle (0),
                                   0);
    
          SetWindowLongPtr (window, GWLP_USERDATA, static_cast <LONG> (reinterpret_cast <LONG_PTR> (edit)));
        }
        break;
    
      case WM_SIZE:
        {
          RECT
            client;
    
          GetClientRect (window, &client);
          SetWindowPos (reinterpret_cast <HWND> (static_cast <LONG_PTR> (GetWindowLongPtr (window, GWLP_USERDATA))), 0, 10, 10, client.right - 20, client.bottom - 20, SWP_NOZORDER | SWP_NOOWNERZORDER);
    
          use_default = false;
        }
        break;
      }
    
      return use_default ? DefWindowProc (window, message, w_param, l_param) : result;
    }
    
    LRESULT __stdcall WindowProc (HWND window, unsigned message, WPARAM w_param, LPARAM l_param)
    {
      bool
        use_default = true;
    
      LRESULT
        result = 0;
    
      switch (message)
      {
      case WM_CREATE:
        {
          RECT
            client;
    
          GetClientRect (window, &client);
    
          CreateWindowEx (0,
                          TEXT ("EditboxClass"),
                          0,
                          WS_VISIBLE | WS_CHILD,
                          client.right / 4,
                          client.bottom / 2 - 20,
                          client.right / 2,
                          40,
                          window,
                          0,
                          GetModuleHandle (0),
                          0);
        }
        break;
      }
    
      return use_default ? DefWindowProc (window, message, w_param, l_param) : result;
    }
    
    int __stdcall WinMain (HINSTANCE instance, HINSTANCE prev_instance, LPSTR command_line, int show)
    {
      WNDCLASSEX
        window_class = 
        {
          sizeof window_class,
          0,
          WindowProc,
          0,
          0,
          instance,
          0,
          0,
          reinterpret_cast <HBRUSH> (static_cast <int> (COLOR_WINDOW) + 1),
          0,
          TEXT ("WindowClass"),
          0
        },
        editbox_class = 
        {
          sizeof editbox_class,
          0,
          EditboxProc,
          0,
          0,
          instance,
          0,
          0,
          reinterpret_cast <HBRUSH> (static_cast <int> (COLOR_BTNFACE) + 1),
          0,
          TEXT ("EditboxClass"),
          0
        }; 
    
      if (RegisterClassEx (&window_class) && RegisterClassEx (&editbox_class))
      {
        HWND
          window = CreateWindowEx (0,
                                   TEXT ("WindowClass"),
                                   TEXT ("Demo"),
                                   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                                   CW_USEDEFAULT,
                                   CW_USEDEFAULT,
                                   CW_USEDEFAULT,
                                   CW_USEDEFAULT,
                                   0,
                                   0,
                                   instance,
                                   0);
    
        if (window)
        {
          MSG
            message;
    
          bool
            quit = false;
    
          while (!quit)
          {
            switch (GetMessage (&message, window, 0, 0))
            {
            case -1:
            case 0:
              quit = true;
              break;
    
            default:
              TranslateMessage (&message);
              DispatchMessage (&message);
              break;
            }
          }
        }
      }
    
      return 0;
    }
    
    #包括
    LRESULT uu stdcall EditboxProc(HWND窗口、未签名消息、WPARAM w_参数、LPARAM l_参数)
    {
    布尔
    使用默认值=true;
    勒索
    结果=0;
    开关(信息)
    {
    案例WM_创建:
    {
    直肠
    客户
    GetClientRect(窗口和客户端);
    HWND
    编辑=CreateWindowEx(0,
    文本(“编辑”),
    0,
    WS|u可见| WS|u儿童,
    10,
    10,
    右-20,
    client.bottom-20,
    窗口,
    0,
    GetModuleHandle(0),
    0);
    SetWindowLongPtr(窗口、GWLP_用户数据、静态_转换(重新解释转换(编辑));
    }
    打破
    案例WM_大小:
    {
    直肠
    客户
    GetClientRect(窗口和客户端);
    SetWindowPos(重新解释转换(静态转换(GetWindowLongPtr(窗口,GWLP_用户数据))),0,10,10,client.right-20,client.bottom-20,SWP_NOZORDER | SWP_NOOWNERZORDER);
    使用默认值=false;
    }
    打破
    }
    返回use_default?DefWindowProc(窗口、消息、w_参数、l_参数):结果;
    }
    LRESULT\uu stdcall WindowProc(HWND窗口、未签名消息、WPARAM w\u参数、LPARAM l\u参数)
    {
    布尔
    使用默认值=true;
    勒索
    结果=0;
    开关(信息)
    {
    案例WM_创建:
    {
    直肠
    客户
    GetClientRect(窗口和客户端);
    CreateWindowEx(0,
    文本(“EditboxClass”),
    0,
    WS|u可见| WS|u儿童,
    右/4,
    client.bottom/2-20,
    client.right/2,
    40,
    窗口,
    0,
    GetModuleHandle(0),
    0);
    }
    打破
    }
    返回use_default?DefWindowProc(窗口、消息、w_参数、l_参数):结果;
    }
    int\uu stdcall WinMain(HINSTANCE实例、HINSTANCE prev\u实例、LPSTR命令行、int show)
    {
    WNDCLASSEX
    窗口类=
    {
    窗口类的大小,
    0,
    WindowProc,
    0,
    0,
    比如,,
    0,
    0,
    重新解释投影(静态投影(彩色窗口)+1),
    0,
    文本(“WindowClass”),
    0
    },
    editbox_类=
    {
    editbox_类的大小,
    0,
    EditboxProc,
    0,
    0,
    比如,,
    0,
    0,
    重新解释施法(静态施法(颜色面)+1),
    0,
    文本(“EditboxClass”),
    0
    }; 
    if(注册表类(&window类)和注册表类(&editbox类))
    {
    HWND
    window=CreateWindowEx(0,
    文本(“WindowClass”),
    文本(“演示”),
    WS|U重叠窗口| WS|U可见,
    CW_使用默认值,
    CW_使用默认值,
    CW_使用默认值,
    CW_使用默认值,
    0,
    0,
    比如,,
    0);
    如果(窗口)
    {
    味精
    消息
    布尔
    退出=错误;
    而(!退出)
    {
    开关(GetMessage(&消息,窗口,0,0))
    {
    案例1:
    案例0:
    退出=真;
    打破
    违约:
    翻译消息(和消息);
    DispatchMessage(&message);
    打破
    }
    }
    }
    }
    返回0;
    }
    

    这是一个有点赤裸裸,但应该给你一些想法,如何做你想要的。它不适用于使用资源脚本定义的对话框(我想,我已经有一段时间没有手工编写资源代码了),因为它使用一个自定义控件作为编辑框(渲染帧的对象)的父对象。您可能希望向EditboxProc添加处理程序,以处理与编辑控件之间的传递消息(如WM_NOTIFY、WM_COMMAND、WM_GETTEXT等),并渲染圆角(WM_PAINT、WM_ERASEBKGND)。

    您有两个选项:-

  • 创建父控件,并在其中包含子无边框文本编辑控件
  • 子类a文本编辑控件并重载NC_绘制以绘制边框
  • 更新

    在搞乱了一个示例程序后,我逐渐意识到,对编辑控件进行子分类并不能真正起作用,而在线检查证实了这一点(感谢MS如此一致!)

    因此,只剩下选项1和选项3(想想看):

  • 创建自己的编辑控件
  • 下面是方法1的一个示例:

    #include <windows.h>
    
    LRESULT __stdcall EditboxProc (HWND window, unsigned message, WPARAM w_param, LPARAM l_param)
    {
      bool
        use_default = true;
    
      LRESULT
        result = 0;
    
      switch (message)
      {
      case WM_CREATE:
        {
          RECT
            client;
    
          GetClientRect (window, &client);
    
          HWND
            edit = CreateWindowEx (0,
                                   TEXT ("Edit"),
                                   0,
                                   WS_VISIBLE | WS_CHILD,
                                   10,
                                   10,
                                   client.right - 20,
                                   client.bottom - 20,
                                   window,
                                   0,
                                   GetModuleHandle (0),
                                   0);
    
          SetWindowLongPtr (window, GWLP_USERDATA, static_cast <LONG> (reinterpret_cast <LONG_PTR> (edit)));
        }
        break;
    
      case WM_SIZE:
        {
          RECT
            client;
    
          GetClientRect (window, &client);
          SetWindowPos (reinterpret_cast <HWND> (static_cast <LONG_PTR> (GetWindowLongPtr (window, GWLP_USERDATA))), 0, 10, 10, client.right - 20, client.bottom - 20, SWP_NOZORDER | SWP_NOOWNERZORDER);
    
          use_default = false;
        }
        break;
      }
    
      return use_default ? DefWindowProc (window, message, w_param, l_param) : result;
    }
    
    LRESULT __stdcall WindowProc (HWND window, unsigned message, WPARAM w_param, LPARAM l_param)
    {
      bool
        use_default = true;
    
      LRESULT
        result = 0;
    
      switch (message)
      {
      case WM_CREATE:
        {
          RECT
            client;
    
          GetClientRect (window, &client);
    
          CreateWindowEx (0,
                          TEXT ("EditboxClass"),
                          0,
                          WS_VISIBLE | WS_CHILD,
                          client.right / 4,
                          client.bottom / 2 - 20,
                          client.right / 2,
                          40,
                          window,
                          0,
                          GetModuleHandle (0),
                          0);
        }
        break;
      }
    
      return use_default ? DefWindowProc (window, message, w_param, l_param) : result;
    }
    
    int __stdcall WinMain (HINSTANCE instance, HINSTANCE prev_instance, LPSTR command_line, int show)
    {
      WNDCLASSEX
        window_class = 
        {
          sizeof window_class,
          0,
          WindowProc,
          0,
          0,
          instance,
          0,
          0,
          reinterpret_cast <HBRUSH> (static_cast <int> (COLOR_WINDOW) + 1),
          0,
          TEXT ("WindowClass"),
          0
        },
        editbox_class = 
        {
          sizeof editbox_class,
          0,
          EditboxProc,
          0,
          0,
          instance,
          0,
          0,
          reinterpret_cast <HBRUSH> (static_cast <int> (COLOR_BTNFACE) + 1),
          0,
          TEXT ("EditboxClass"),
          0
        }; 
    
      if (RegisterClassEx (&window_class) && RegisterClassEx (&editbox_class))
      {
        HWND
          window = CreateWindowEx (0,
                                   TEXT ("WindowClass"),
                                   TEXT ("Demo"),
                                   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                                   CW_USEDEFAULT,
                                   CW_USEDEFAULT,
                                   CW_USEDEFAULT,
                                   CW_USEDEFAULT,
                                   0,
                                   0,
                                   instance,
                                   0);
    
        if (window)
        {
          MSG
            message;
    
          bool
            quit = false;
    
          while (!quit)
          {
            switch (GetMessage (&message, window, 0, 0))
            {
            case -1:
            case 0:
              quit = true;
              break;
    
            default:
              TranslateMessage (&message);
              DispatchMessage (&message);
              break;
            }
          }
        }
      }
    
      return 0;
    }
    
    #包括
    LRESULT uu stdcall EditboxProc(HWND窗口、未签名消息、WPARAM w_参数、LPARAM l_参数)
    {
    布尔
    使用默认值=true;
    勒索
    结果=0;
    开关(信息)
    {
    案例WM_创建:
    {
    直肠
    客户
    GetClientRect(窗口和客户端);
    HWND
    编辑=CreateWindowEx(0,