Create a window in VC that cannot be changed and how to limit the window size

Source: Internet
Author: User

In fact, there are many methods. Here we will list several common methods,
The following is an example of the SDI Framework Window.

1. Create a maximum window and do not change its size.

First,

Initinstance of app
In the original pmainframe-> showwindow (m_ncmdshow );
Add

DWORD dwstyle = getwindowlongm_pmainwnd-> m_hwnd, gwl_style );
// Dwstyle & = ~ (Ws_sizebox );
Dwstyle & = ~ (Ws_maximizebox );
Dwstyle & = ~ (Ws_minimizebox );
Setwindowlong (m_pmainwnd-> m_hwnd, gwl_style, dwstyle );

M_pmainwnd-> showwindow (sw_showmaximized );

Then delete m_pmainwnd-> showwindow (m_ncmdshow );

In this example, dwstyle & = ~ (Ws_sizebox); the annotation is called, because removing this attribute will cause trouble, that is, when I display the largest words in this window,
It will also hide the taskbar. It's really depressing
However, if you do not remove this attribute, you can drag it to change the size of the window. What should you do,
It's really a headache. Let's change your mind.

Generally, the window size is changed because you drag the window border. Therefore, we can intercept the message wm_nchittest in the main window and determine in its response function whether the return value of cwnd: onnchittest () is htright, htleft, httop, or htbottom. If yes, it indicates that the user has already clicked one of the four borders. At this time, we should return htclient. then, the shape of the mouse will not change to a horizontal or vertical bidirectional arrow, and you will not be able to change the window size by dragging the border.

After reading the following with Class Wizard, the message wm_nchittest was not found. I was depressed and had to manually add message ing.

Add it to begin_message_map (cmainframe, cmdiframewnd ).
On_wm_nchittest ()

Under the header file of the framework class
Statement
Afx_msg uint onnchittest (cpoint point );

Implementation

Uint cmainframe: onnchittest (cpoint point)
{
If (cwnd: onnchittest (point) = htright | cwnd: onnchittest (point) = htleft | cwnd: onnchittest (point) = httop | cwnd:: onnchittest (point) = htbottom)
Return htclient;

Return cwnd: onnchittest (point );
}
Is that all right? No.
This only limits the four sides. Although we can't drag the four sides, it's depressing and troublesome.

In addition
Httopleft
Httopright
Htbottomleft
Htbottomright

In this way, the four sides and four corners depend on how you play.

Is it successful ??
No, it's a little missing. What's missing?
Double-click the top of the window, that is, the window will become smaller when the caption area is clicked, and there is no way to reply.
What should I do ??
Cool ..................

There's a solution.

Add on_wm_nclbuttondblclk message

Void cmainframe: onnclbuttondblclk (uint nflags, cpoint point)
{
If (nflags! = Htcaption)
Cframewnd: onnclbuttondblclk (nflags, point );
}

Manually add
Wm_nclbuttondblclk
Processing of this message

Remember begin_message_map
Add
On_wm_nclbuttondblclk

This also adds the message ing manually, and processes the following, OK, done, and manual

2. Create a window that cannot be changed,
Oh, yeah, that's easy.

Initinstance of app
In the original pmainframe-> showwindow (m_ncmdshow );
Add

DWORD dwstyle = getwindowlongm_pmainwnd-> m_hwnd, gwl_style );
Dwstyle & = ~ (Ws_sizebox );

Setwindowlong (m_pmainwnd-> m_hwnd, gwl_style, dwstyle );

M_pmainwnd-> showwindow (sw_show );

If you want to remove the maximum and minimum Windows, add this
Dwstyle & = ~ (Ws_maximizebox );
Dwstyle & = ~ (Ws_minimizebox );
After ws_sizebox is removed, the window size cannot be changed,

Of course, you can also use the wm_nchittest method.

3. Restrict the window size range

Response Message of wm_getmaxmininfo

Processing
Void cmainframe: ongetminmaxinfo (minmaxinfo far * lpmmi)
{
// Todo: add your message handler code here and/or call default
 
Lpmmi-> ptmintracksize. x = 100;
Lpmmi-> ptmintracksize. Y = 100;
Lpmmi-> ptmaxtracksize. x = 200;
Lpmmi-> ptmaxtracksize. Y = 200;

Cframewnd: ongetminmaxinfo (lpmmi );
}

In this case, the window will be framed by me.
The length and width ranges from 100 to 200.

Of course
The structure of minmaxinfo is also very rich in content, and there are many things to do. You can check msdn for details.

Now, we have sorted it out today ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.