Getstyle,modifystyle,getexstyle,modifystyleex

Source: Internet
Author: User

To add or remove the Normal style of a window, you can use the GetStyle () and ModifyStyle () methods to implement
To set or remove the extended style of the window, you can use the Getexstyle () and ModifyStyleEx () methods to implement


1. Cwnd::getexstyle and Cwnd::modifystyle

(1) Getexstyle
Prototype: DWORD GetStyle () const;
function: Get window style parameters
Returns: Returns the current window style
For example:
DWORD dwstyle = GetStyle ();

:: SetWindowLong (GetSafeHwnd (), Gwl_style, Dwstyle | Ss_notify);

(2) ModifyStyle
Prototype:
BOOL ModifyStyle
(
DWORD Dwremove,//Specifies the style of the window to be deleted when modifying
DWORD Dwadd,//Specifies the window style that will be added when modifying
UINT nflags=0//This parameter will be passed to SetWindowPos, otherwise 0, if SetWindowPos is not called, the default value of this parameter is generally
);
BOOL ModifyStyleEx (
DWORD Dwremove,//Specifies the style to remove when the style modification is extended
DWORD Dwadd,//Specifies the style to add when the style modification is extended
UINT nflags = 0//flag will be in SetWindowPos or 0 if SetWindowPos should not be called. The default value is zero
);

Function: Modify the style of the window
Returns: If the function successfully called returns a value other than 0, 0 is returned;
Note: If nflags is not 0,modifystyle will call SetWindowPos and redraw the window with nflags and the following four pre-arranged flags:
Swp_nosize Keep Current size
Swp_nomove keep the current position.
Swp_nozorder Maintain current Z-order
Swp_noactivate do not activate this window


2. Cwnd::getexstyle and Cwnd::modifystyleex

Extended style for changing windows, declaring and


Some examples in C + +:
ModifyStyle (ws_caption, 0, 0); Remove title bar
ModifyStyle (ws_maximizebox, 0, 0); Go to maximize button
ModifyStyle (0, ws_thickframe, 0); Add Ws_thickframe Style
ModifyStyle (0, Ws_ex_toolwindow, 0); Setting Toolbar window Styles
ModifyStyleEx (0, ws_ex_acceptfiles, 0); Set the Accept Files property

Hide the taskbar icon
ModifyStyleEx (Ws_ex_appwindow, Ws_ex_toolwindow);


3. GetWindowLong and SetWindowLong

Prototype: Longgetwindowlong (Hwndhwnd, Intnlndex);
Function: Get information about a specified window
Prototype: Longsetwindowlong (HWND hwnd,int nlndex,long dwnewlong);
Function: Used to change the properties of a specified window


For example:

Go to border (including title bar) void Cwebbrushdlg::removeborder () {DWORD dwstyle = GetStyle ();D word dwnewstyle = ws_overlapped | ws_visible | Ws_sysmenu | Ws_minimizebox | Ws_maximizebox | Ws_clipchildren | Ws_clipsiblings;dwnewstyle &= dwstyle; SetWindowLong (M_hwnd, Gwl_style, Dwnewstyle);D word dwexstyle = Getexstyle ();D word dwnewexstyle = Ws_ex_left | ws_ex_ltrreading | Ws_ex_rightscrollbar;dwnewexstyle &= dwExStyle; SetWindowLong (M_hwnd, Gwl_exstyle, Dwnewexstyle);}

4. The Getexstyle () and GetExtendedStyle () differences between the list views:
Getexstyle is a CWnd class function that gets the extended properties that are common to CWnd windows.
GetExtendedStyle is the member function of the CListCtrl, and the extended attribute of CListCtrl is obtained.


5. Setting the Listctrl property

Load Listctrllong Lstyle;lstyle = GetWindowLong (M_tasklist.m_hwnd, Gwl_style); Gets the current window Stylelstyle &= ~lvs_typemask; Clear display mode Lstyle |= Lvs_report | Lvsil_small | Lvs_aligntop | Lvs_showselalways; Set Stylesetwindowlong (M_tasklist.m_hwnd, Gwl_style, lstyle);D word dwstyle = M_tasklist.getextendedstyle ();d Wstyle | = Lvs_ex_fullrowselect; Select an exercise line highlighting (only applicable with the report style Listctrl) dwstyle |= lvs_ex_subitemimages; Subitem add icon M_tasklist.setextendedstyle (dwstyle);

6. CListCtrl extension Style setting method SetExtendedStyle and ModifyStyleEx comparison

For starters, when he needs to set Listctrl's extended style, he often thinks of using ModifyStyleEx to set the code as follows:

ModifyStyleEx (0,lvs_ex_gridlines)  
This is not true and the correct setting should be:
SetExtendedStyle (Lvs_ex_gridlines)

So, where is the difference between ModifyStyleEx and SetExtendedStyle?
In fact, ModifyStyleEx simply sets the Gwl_exstyle property of the window, which is just the normal extended property of the window, which is prefixed with ws_ex_ such as Ws_ex_clientedge,
In the Listctrl control, its extended-style value is not stored in the Gwl_exstyle property value of the window, but is implemented by sending a Lvm_setextendlistviewstyle message to the Listctrl control. So it can't be set by ModifyStyleEx.

Compared to ModifyStyle, the API can set the style of ordinary windows, such as ws_child,ws_visible. Also, you can set the Normal style of the control, to Listctrl, there is lvs_report,lvs_ownerdrawfixed and so on, which is why we can put the ws_child,ws_ when we create the child control. Visible is the reason for the CREATE function of the control that is being passed together:

M_list. Create (ws_child| ws_visible| Lvs_report,crect (0,0,100,100), this,0);  
But for an extended style, you can't do this:
Why does Microsoft not store the extension style of the control in the Gwl_exstyle attribute, because this property value is a 32-bit long DWORD type, the general extended property of the window is the attribute with ws_ex_ as the prefix, has already occupied it, so the extension style of Listctrl, Microsoft can only put it in other places.


Getstyle,modifystyle,getexstyle,modifystyleex

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.