【问题标题】:wxWidgets wxBORDER_NONE and wxRESIZE_BORDER makes white areawxWidgets wxBORDER_NONE 和 wxRESIZE_BORDER 使白色区域
【发布时间】:2017-05-01 22:58:57
【问题描述】:

White Border

如何去除这个白色区域?它破坏了我的 GUI 设计。
我想制作一个由windows生成的阴影和一条蓝线。 所以我找到了一个选项,使蓝线(wxRESIZE_BORDER),但它使一个像图像一样的白色区域。

//MainFrame.h
#pragma once
#define _CRT_SECURE_NO_WARNINGS

#include <wx/frame.h>


class MainFrame : public wxFrame
{
public:

    MainFrame(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(310, 390), long style = wxSUNKEN_BORDER|wxRESIZE_BORDER);

};  


//MainFrame.cpp
#include "MainFrame.h"

MainFrame::MainFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(parent, id, title, pos, size, style)
{
    this->Centre(wxBOTH);
}


//Main.h
#pragma once
#include <wx/wx.h>

class App : public wxApp
{
public:
    virtual bool OnInit();
};


//Main.cpp
#include "Main.h"
#include "MainFrame.h"

IMPLEMENT_APP(App)

bool App::OnInit()
{
    MainFrame *frame = new MainFrame(NULL);
    frame->Show(true);

    return true;
}

【问题讨论】:

  • 你想要它周围的蓝线吗?
  • 提供MCVE并指定库的版本。
  • @SangWanJeon,你能发布你的代码吗?另外,您要在哪个版本的 Windows 上试用此功能?
  • @A.Hue 是的。我想要蓝线和蓝线生成时产生的阴影。
  • @Igor 我会尽快发布代码。我正在使用 Windows 10、Redstone 更新、msvc 14.0(vs 2015) 和 wxWidgets Library 3.1.0

标签: c++ user-interface wxwidgets


【解决方案1】:

使用wxSUNKEN_BORDER 你会得到这样的东西:

那么它不需要wxRESIZE_BORDER 部分。但请注意,这会使十字架消失。

【讨论】:

  • 如果我使用 wxSUNKEN_BORDER,Windows 不会自动生成阴影。我需要并且想要那个影子。
  • 对不起@SangWanJeon,那我不知道该怎么做。
【解决方案2】:

这个白色的上边框是调整大小的边框,它属于窗口的非客户区。因此,要删除它,您应该处理与窗口非客户区的大小调整和激活相关的窗口消息,如下所示:

  WXLRESULT MSWWindowProc( WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam )
  {
    /* When we have a custom titlebar in the window, we don't need the non-client area of a normal window
      * to be painted. In order to acheive this, we handle the "WM_NCCALCSIZE" which is responsible for the
      * size of non-client area of a window and set the return value to 0. Also we have to tell the
      * application to not paint this area on activate and deactivation events so we also handle
      * "WM_NCACTIVATE" message. */
      switch( nMsg )
      {
      case WM_NCACTIVATE:
      {
        /* Returning 0 from this message disable the window from receiving activate events which is not
        desirable. However When a visual style is not active (?) for this window, "lParam" is a handle to an
        optional update region for the nonclient area of the window. If this parameter is set to -1,
        DefWindowProc does not repaint the nonclient area to reflect the state change. */
        lParam = -1;
        break;
      }
      /* To remove the standard window frame, you must handle the WM_NCCALCSIZE message, specifically when
      its wParam value is TRUE and the return value is 0 */
      case WM_NCCALCSIZE:
        if( wParam )
        {
          /* Detect whether window is maximized or not. We don't need to change the resize border when win is
          *  maximized because all resize borders are gone automatically */
          HWND hWnd = ( HWND ) this->GetHandle();
          WINDOWPLACEMENT wPos;
          // GetWindowPlacement fail if this member is not set correctly.
          wPos.length = sizeof( wPos );
          GetWindowPlacement( hWnd, &wPos );
          if( wPos.showCmd != SW_SHOWMAXIMIZED )
          {
            RECT borderThickness;
            SetRectEmpty( &borderThickness );
            AdjustWindowRectEx( &borderThickness,
              GetWindowLongPtr( hWnd, GWL_STYLE ) & ~WS_CAPTION, FALSE, NULL );
            borderThickness.left *= -1;
            borderThickness.top *= -1;
            NCCALCSIZE_PARAMS* sz = reinterpret_cast< NCCALCSIZE_PARAMS* >( lParam );
            // Add 1 pixel to the top border to make the window resizable from the top border
            sz->rgrc[ 0 ].top += 1;
            sz->rgrc[ 0 ].left += borderThickness.left;
            sz->rgrc[ 0 ].right -= borderThickness.right;
            sz->rgrc[ 0 ].bottom -= borderThickness.bottom;
            return 0;
          }
        }
        break;
      }
    return wxFrame::MSWWindowProc( nMsg, wParam, lParam );
  }

【讨论】:

    猜你喜欢
    • 2014-08-30
    • 2013-03-16
    • 2012-09-26
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    • 2018-01-03
    相关资源
    最近更新 更多