C++ 禁用窗口大小调整Win32

C++ 禁用窗口大小调整Win32,c++,winapi,resize,C++,Winapi,Resize,如何通过拖动窗口边缘来禁用调整大小 这是我的窗口创建代码 bool CreateGLWindow(char* title, int width, int height) { GLuint PixelFormat; // Holds The Results After Searching For A Match WNDCLASS wc; // Windows Class Structure DWORD dwE

如何通过拖动窗口边缘来禁用调整大小

这是我的窗口创建代码

bool CreateGLWindow(char* title, int width, int height)
{
GLuint      PixelFormat;            // Holds The Results After Searching For A Match
WNDCLASS    wc;                     // Windows Class Structure
DWORD       dwExStyle;              // Window Extended Style
DWORD       dwStyle;                // Window Style
RECT        WindowRect;             // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0;            // Set Left Value To 0
WindowRect.right=(long)width;       // Set Right Value To Requested Width
WindowRect.top=(long)0;             // Set Top Value To 0
WindowRect.bottom=(long)height;     // Set Bottom Value To Requested Height

hInstance           = GetModuleHandle(NULL);                // Grab An Instance For Our Window
wc.style            = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;   // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc      = (WNDPROC) WndProc;                    // WndProc Handles Messages
wc.cbClsExtra       = 0;                                    // No Extra Window Data
wc.cbWndExtra       = 0;                                    // No Extra Window Data
wc.hInstance        = hInstance;                            // Set The Instance
wc.hIcon            = LoadIcon(NULL, IDI_WINLOGO);          // Load The Default Icon
wc.hCursor          = LoadCursor(NULL, IDC_ARROW);          // Load The Arrow Pointer
wc.hbrBackground    = NULL;                                 // No Background Required For GL
wc.lpszMenuName     = NULL;                                 // We Don't Want A Menu
wc.lpszClassName    = "OpenGL";                             // Set The Class Name

if (!RegisterClass(&wc))                                    // Attempt To Register The Window Class
{
    MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    return false;                                           // Return FALSE
}

dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;           // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW;                            // Windows Style

AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);     // Adjust Window To True Requested Size

// Create The Window
if (!(hWnd=CreateWindowEx(  dwExStyle,                          // Extended Style For The Window
                            "OpenGL",                           // Class Name
                            title,                              // Window Title
                            dwStyle |                           // Defined Window Style
                            WS_CLIPSIBLINGS |                   // Required Window Style
                            WS_CLIPCHILDREN,                    // Required Window Style
                            0, 0,                               // Window Position
                            WindowRect.right-WindowRect.left,   // Calculate Window Width
                            WindowRect.bottom-WindowRect.top,   // Calculate Window Height
                            NULL,                               // No Parent Window
                            NULL,                               // No Menu
                            hInstance,                          // Instance
                            NULL)))                             // Dont Pass Anything To WM_CREATE
{
    KillGLWindow();                             // Reset The Display
    MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    return false;                               // Return FALSE
}

static  PIXELFORMATDESCRIPTOR pfd=              // pfd Tells Windows How We Want Things To Be
{
    sizeof(PIXELFORMATDESCRIPTOR),              // Size Of This Pixel Format Descriptor
    1,                                          // Version Number
    PFD_DRAW_TO_WINDOW |                        // Format Must Support Window
    PFD_SUPPORT_OPENGL |                        // Format Must Support OpenGL
    PFD_DOUBLEBUFFER,                           // Must Support Double Buffering
    PFD_TYPE_RGBA,                              // Request An RGBA Format
    24,                                     // Select Our Color Depth
    0, 0, 0, 0, 0, 0,                           // Color Bits Ignored
    0,                                          // No Alpha Buffer
    0,                                          // Shift Bit Ignored
    0,                                          // No Accumulation Buffer
    0, 0, 0, 0,                                 // Accumulation Bits Ignored
    24,                                         // 24Bit Z-Buffer (Depth Buffer)  
    0,                                          // No Stencil Buffer
    0,                                          // No Auxiliary Buffer
    PFD_MAIN_PLANE,                             // Main Drawing Layer
    0,                                          // Reserved
    0, 0, 0                                     // Layer Masks Ignored
};

if (!(hDC=GetDC(hWnd)))                         // Did We Get A Device Context?
{
    KillGLWindow();                             // Reset The Display
    MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    return false;                               // Return FALSE
}

if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
{
    KillGLWindow();                             // Reset The Display
    MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    return false;                               // Return FALSE
}

if(!SetPixelFormat(hDC,PixelFormat,&pfd))       // Are We Able To Set The Pixel Format?
{
    KillGLWindow();                             // Reset The Display
    MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    return false;                               // Return FALSE
}

if (!(hRC=wglCreateContext(hDC)))               // Are We Able To Get A Rendering Context?
{
    KillGLWindow();                             // Reset The Display
    MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    return false;                               // Return FALSE
}

if(!wglMakeCurrent(hDC,hRC))                    // Try To Activate The Rendering Context
{
    KillGLWindow();                             // Reset The Display
    MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    return false;                               // Return FALSE
}

ShowWindow(hWnd,SW_SHOW);                       // Show The Window
SetForegroundWindow(hWnd);                      // Slightly Higher Priority
SetFocus(hWnd);                                 // Sets Keyboard Focus To The Window
reshape(width, height);                 // Set Up Our Perspective GL Screen

init();

return true;                                    // Success
}

WS\u OVERLAPPEDWINDOW
样式包括
WS\u THICKFRAME
样式,我认为它负责调整窗口的大小

考虑一下

dwStyle=(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);

将窗口样式从WS_OVERLAPPEDWINDOW更改为WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX。换言之,它是重叠窗口减去thickframe(可调整大小的边框)和maxbox。

处理WM_Size消息并覆盖所有更改窗口矩形的尝试。

对我有效,但不使用

WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME
仅使用

WS_OVERLAPPEDWINDOW

您可以使用WS\u重叠窗口^WS\u THICKFRAME


XOR将在WS_OVERLAPPED窗口中保留除WS_THICKFRAME之外的所有内容。如果您使用
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_系统菜单
,它将禁用最大化和调整大小。

您可以尝试以下操作:

::SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE)&~WS_SIZEBOX);
它仅通过拖动窗口边缘来禁用调整大小。 顺便说一下,WS_SIZEBOX与WS_THICKFRAME相同,因为

#define WS_SIZEBOX WS_THICKFRAME
对于MFC, 转到属性>边框并设置为“对话框框架”
这对我来说是有效的,因为之前的边框设置被设置为“调整大小”

,这不会禁用调整大小。要禁用调整大小,请按照@thatsdisgusting的答案进行操作。使用
WS\u OperappedWindow^WS\u THICKFRAME
@DanielkVista谁是令人兴奋的?但是,如果
WS\u THICKFRAME
不是样式的一部分,则
AdjustWindowRectEx
似乎无法正常工作。不确定为什么会将此标记为答案,因为它不适用于我(Windows 10)。另一个答案很有魅力,但代码如下:
:SetWindowLong(hWnd,GWL_风格,GetWindowLong(hWnd,GWL_风格)和~WS_SIZEBOX
@YePhIcK嗯,我差不多7年前就给出了这个答案,在NT 5.1-6.1上试用过,在考虑OP是如何提出这个问题时效果很好。从未在新版本上试用过,从那以后我就不再在Windows上工作了,所以很有可能一些位同时发生了变化。这并不妨碍最大化。但Windows试图调整大小,而调整光标的大小看起来很奇怪。