首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >禁用窗口大小调整Win32

禁用窗口大小调整Win32
EN

Stack Overflow用户
提问于 2010-07-18 22:55:33
回答 8查看 61.7K关注 0票数 22

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

下面是我的窗口创建代码

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
}
EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2010-07-18 23:02:39

WS_OVERLAPPEDWINDOW样式包括WS_THICKFRAME样式,我认为,它负责使您的窗口可调整大小。

考虑一下像这样的事情

dwStyle=(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
票数 59
EN

Stack Overflow用户

发布于 2013-11-19 09:04:45

您可以使用WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME

异或运算将把除WS_THICKFRAME之外的所有内容保存在WS_OVERLAPPEDWINDOW中

票数 24
EN

Stack Overflow用户

发布于 2014-11-20 18:26:09

您可以尝试如下所示:

::SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE)&~WS_SIZEBOX);

它仅通过拖动窗口的边缘来禁用大小调整。顺便说一句,WS_SIZEBOX和WS_THICKFRAME是一样的,因为

#define WS_SIZEBOX WS_THICKFRAME
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3275989

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档