Improved windows Separation Control for wtl

Source: Internet
Author: User

Original visualfc

This document assumes that the reader is familiar with wtl and has learned and used the Windows separated by wtl. Windows separated by wtl are easy to use and can be used in dialog box window programs. However, we also find some problems with Windows separated by wtl, that is, the Panels in Windows separated by wtl must be subwindows, in this way, the tab control of the main dialog box window is unacceptable. In the dialog box application, you must set the parent window of the dialog box control to the wtl separation window, and then add it to the wtl separation window, the Code is as follows:

Cwindow ED1 = getdlgitem (idc_edit1 );
Cwindow ED2 = getdlgitem (idc_edit2 );
Ed1.setparent (m_wndhorsplit );
Ed2.setparent (m_wndhorsplit );
M_wndhorsplit.setsplitterpanes (ED1, ED2 );

We can see that the parent window of the control must be set to wtl split windows. We can modify the source code of the separation window of wtl to fix this. After modification, the control's parent window is still the main dialog box window, so programming is simple. The Code is as follows:

M_wndhorsplit.setsplitterpanes (getdlgitem (idc_edit1), getdlgitem (idc_edit2 ));

Modify the source file atlsplit. h In the wtl separation window. Modify the location in the Void updatesplitterlayout () function of the class csplitterimpl. Modify the location as follows:

Convert the following original code

If (m_hwndpane [npane]! = NULL)
...{
: Setwindowpos (m_hwndpane [npane], null, rect. Left, rect. Top, rect. Right-rect. Left, rect. Bottom-rect. Top, swp_nozorder );
}

Changed to the following modified code

If (m_hwndpane [npane]! = NULL)
...{
// Fix: 2007-12-06
Hwnd hwndparent =: getparent (m_hwndpane [npane]);
If (hwndparent! = Pt-> m_hwnd)
...{
Pt-> clienttoscreen (& rect );
Cwindow (hwndparent). screentoclient (& rect );
}
: Setwindowpos (m_hwndpane [npane], null, rect. Left, rect. Top, rect. Right-rect. Left, rect. Bottom-rect. Top, swp_nozorder );
}

Similarly, the following original code

If (m_hwndpane [m_nsingtransferane]! = NULL)
...{
: Setwindowpos (m_hwndpane [m_nsinglepane], null, rect. Left, rect. Top, rect. Right-rect. Left, rect. Bottom-rect. Top, swp_nozorder );
}

Changed to the following modified code

If (m_hwndpane [m_nsingtransferane]! = NULL)
...{
// Fix: 2007-12-06
Hwnd hwndparent =: getparent (m_hwndpane [m_nsingpolicane]);
If (hwndparent! = Pt-> m_hwnd)
...{
Pt-> clienttoscreen (& rect );
Cwindow (hwndparent). screentoclient (& rect );
}
: Setwindowpos (m_hwndpane [m_nsinglepane], null, rect. Left, rect. Top, rect. Right-rect. Left, rect. Bottom-rect. Top, swp_nozorder );
}

Finally, we have to process the sw_showwindow message to hide the panel window when the wtl separation window is hidden. In order not to make more changes to the atlsplit, and to facilitate the use in the dialog box application, the modified wtl separation window is used to derive a new separation window class. The Code is as follows:

Namespace wtl
...{
Template <bool t_bvertical = true>
Class csplitter=wext: Public csplitter=wimpl <csplitter=wt <t_bvertical>, t_bvertical>
...{
Public:
Declare_wnd_class_ex (_ T ("wtl_splitterwindowex"), cs_dblclks, color_window)

Typedef csplitter=wimpl <csplitter=wt <t_bvertical>, t_bvertical> _ baseclass;

Hwnd createfromid (hwnd hwndparent, uint ndlgitemid)
...{
Return createfromwindow (: getdlgitem (hwndparent, ndlgitemid ));
}

Hwnd createfromwindow (hwnd)
...{
Cwindow WND = hwnd;
Cwindow parent = WND. getparent ();
Uint nid = WND. getdlgctrlid ();
Rect RC;
WND. getwindowrect (& rc );

DWORD dwstyle = WND. getstyle ();
Dwstyle | = (ws_child | ws_visible );
DWORD dwexstyle = WND. getexstyle ();

Parent. screentoclient (& rc );

Hwnd hthiswnd = create (parent, RC, null, dwstyle, dwexstyle, NID, null );
If (hthiswnd)
...{
WND. destroywindow ();
}
Return hthiswnd;
}

Public:
Begin_msg_map (csplitterwindowext)
Message_handler (wm_showwindow, onshowwindow)
Chain_msg_map (_ baseclass)
End_msg_map ()

Lresult onshowwindow (uint umsg, wparam, lparam, bool & bhandled)
...{
If (m_nsingpolicane = split_pane_none)
...{
If (m_hwndpane [split_pane_left])
: Showwindow (m_hwndpane [split_pane_left], (bool) wparam );
If (m_hwndpane [split_pane_right])
: Showwindow (m_hwndpane [split_pane_right], (bool) wparam );
}
Else
...{
If (m_hwndpane [m_nsingtransferane])
: Showwindow (m_hwndpane [m_nsinglepane], (bool) wparam );
}
Bhandled = false;
Return 0;
}
};

Typedef csplitterwindowext <true> csplitterwindowex;
Typedef csplitter1_wext <false> chorsplitter1_wex;


}; // Namespace wtl

We can see that csplitterjavaswex contains a new function createfromid and createfromwindow. The two functions aim to generate extended window separation objects from a placeholder in the dialog box window using a static window, and inherit the window attributes. In this way, we can use the vs60 Resource Designer to design the positions and Properties of window separation.

Resource Editor:

We use the idc_pane2_static and idc_pane_static picture controls to implement placeholder operations. Objective 3: To generate a separation window control from the two placeholder controls, and to control the window properties of the generated separation window by changing the window properties of the picure control in the resource editor. Third, you can use cdialogresize to directly control the scaling layout of the separated windows. The Code is as follows:

Csplitterappswex m_wndsplit;
Chorsplitterappswex m_wndhorsplit;

The code for initializing the separation window control is stored in the oninitdialog function.

M_wndhorsplit.createfromwindow (getdlgitem (idc_panel2_static ));
M_wndhorsplit.setsplitterpanes (getdlgitem (idc_edit1), getdlgitem (idc_edit2 ));
M_wndhorsplit.setsplitterpos ();

M_wndsplit.createfromid (m_hwnd, idc_panel_static );
M_wndsplit.setsplitterpanes (getdlgitem (idc_list1), m_wndhorsplit );
M_wndsplit.setsplitterpos (100 );

How about it? It's much easier to use the wtl separation window before modification. Try the running effect and support tab sequence switching. Compared with the vs60 resource editor design, what you see is what you get. :)

Run

For cdialogresize layout control, we can use the wtl Wizard of visualfc to automatically generate the layout control. The generated code is as follows:

Begin_dlgresize_map (cmaindlg)
Dlgresize_control (idc_button1, dlsz_move_x)
Dlgresize_control (id_app_about, dlsz_move_x | dlsz_move_y)
Dlgresize_control (idok, dlsz_move_x)
Dlgresize_control (idcancel, dlsz_move_x)
Dlgresize_control (idc_panel_static, dlsz_size_x | dlsz_size_y)
End_dlgresize_map ()

Note that do not add idc_edit1, idc_edit2, idc_list1, and idc_panel2_static to the dlgresize. Although these controls still belong to the main window, they are managed by the wtl separation window.

Finally, let's review the atlsplit of wtl. the H file is modified, and the wtl separation window class is improved. The parent window of the control in the dialog box program can be added to the wtl separation window without being changed, we use a derived separator window class atlsplitex. h implements direct control of the dialog box separation window, including the WYSIWYG design using the vs60 resource editor and support for scaling layout.

Download the code in this article: wtlsplitex.zip

The Code includes the modified atlsplit. H and atlsplitex. h file, you can split atlsplit. replace the hfile with atlsplit in wtl80. h file, which is similar to the original atlsplit. H files are completely consistent.

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.