How to disable some features?

Hi,

First of all Thank you for all who has helped me previously,

I have a main menu which consists of minimize,maximize and close button.

My question is how to disable the maximize and re-sizing arrow which looks like this <--> so that no one can permanently resize the main window.

Here is my code what should I change here,

1
2
3
4
5
6
7
8
9
10
11
12
 wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATIONEXAMPLE));
    wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
   wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
	
    wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_APPLICATIONEXAMPLE);
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));


or somewhere else.

Thank you in advance.
The WNDCLASSEX struct doesn't control any of the features you described. The key issue are the styles you set in the CreateWindow() or CreateWindowEx() function call. The styles control whether the window has a maximize, minimize or close button, and whether it can be resized or not.
Don't use the WS_OVERLAPPEDWINDOW style in the CreateWindow function. Check MSDN for help or consult your Win32 API reference.
HINT:

If you want to get rid of the maximize box, you can do this...

WS_OVERLAPPEDWINDOW XOR WS_MAXIMIZEBOX

That'll zap the bit to get rid of it.
1
2
 hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW ^ WS_MAXIMIZEBOX,
	   CW_USEDEFAULT, CW_USEDEFAULT,755,525, nullptr, nullptr, hInstance, nullptr);


Yes, This disables the maximize box but one can resize my window using sizens(IDC_SIZENS) or sizenwse(IDC_SIZENWSE \ SIZENESW)

How to disable that feature

I tried something like this

1
2
 hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW ^ WS_MAXIMIZEBOX &!(IDC_SIZENS),
	   CW_USEDEFAULT, CW_USEDEFAULT,755,525, nullptr, nullptr, hInstance, nullptr);


Thank you everyone for helping me
Last edited on
I think your problem V07 is that you need to swear off that WS_OVERLAPPEDWINDOW style! :)

It is useful for most windows in that it combines a pile of window styles. But if you are wanting to create something unusual or strange, i.e., special purpose, then you are better off building up your dwStyle parameter from scratch, so to speak, by just or'ing together the seperate bits you need. That trick with the XOR (^) is only useful if you want pretty much a normal window, but just want to zap one bit out of the picture. If you like, you can zap out more bits, i.e., styles, but at some point it becomes easier to just forgo the WS_OVERLAPPEDWINDOW conglomeration of amalgamated bits, and just build up from what you need. You have searched MSDN for all the style bits, haven't you?

Anyway, here is a complete program with a rather unusual window which has no minimize buitton, no maximize button, no close button, in fact, not even a title bar. And it can't be resized either. Fact is, the only way of closing it is through the [ESC] key...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <windows.h>

LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
 switch(msg)
 {
   case WM_CHAR:
     {
        if(wParam==VK_ESCAPE)
           SendMessage(hwnd,WM_CLOSE,0,0);
        return 0;
     }
   case WM_DESTROY:
     {
        PostQuitMessage(0);
        return 0;
     }
 }

 return (DefWindowProc(hwnd, msg, wParam, lParam));
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
 WNDCLASSEX wc={};
 MSG messages;
 HWND hWnd;

 wc.lpszClassName = "Form1";
 wc.lpfnWndProc   = fnWndProc;
 wc.cbSize        = sizeof(WNDCLASSEX);
 wc.hInstance     = hInstance;
 RegisterClassEx(&wc);
 hWnd=CreateWindowEx(0,"Form1","Form1",WS_VISIBLE,200,100,325,300,HWND_DESKTOP,0,hInstance,0);
 while(GetMessage(&messages,NULL,0,0))
 {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
 }

 return messages.wParam;
}
One other point I might mention to you or any other lurkers just learning Win32 coding, the styles of main windows and child window controls are very important. They alter the behavior of the object profoundly. They correspond to object methods in OOP speak. In other words, if the Win32 Api was C++ based instead of C based, and one wanted a window with no maximize button that couldn'tr be resized, one might have been able to do something like so...

MyWindow.MaxButton = false;
MyWindow.Resizable = false;

...but alas, such is not the case. So you've got to learn to look up and use styles which correspond to bit positions in a 32 bit integer.
@ freddie1,

That seems to be more complicated for a newbie.

Here is my actual problem I have created my main window with a menu, some buttons, bitmaps etc., but when I maximize the window things look ugly(button, bitmap remains same in size )what can I do to solve?

Thank you for your help!

By the way excuse my English :)
Last edited on

..but when I maximize the window things look ugly(button, bitmap remains same in size )


That's much more complicated to fix in Win32 SDK style apps than is adjusting window properties through use of bit styles. So my recommendation to you in just starting out is to follow the path you have already chosen, that is, create your main window of a size that pleases you, and prevent the user from resizing it or maximizing it. Minimizing it would be OK because it'll just be restored to what it was before.

The reason I'm recommending this, is that if you are overwhelmed by the complexity of just adding style bits together to come up with the style you want, then the complexity of doing what needs done to adjust the locations and sizes of bitmaps or child window controls will most certainly do you in, you'll give up with C++ and/or Win32 coding, and end up as a Visual Basic user I fear.
Thank you freddie1
Topic archived. No new replies allowed.