Three Visual C ++ Programming Skills

xiaoxiao2021-03-06  55

17. How to create a word rounded CEDITVIEW

Overload CWnd:: PrecreateWindow and modify the CreateStruct structure, turn off the ES_AUTOHSCROLL and WS_HSCROLL style of the CEDITVIEW object, because the CeditView:: PrecreateWindow Displays Settings CS. Style, call the base class function to modify the CS. Style.

Bool CsampleEditview:: PrecreateWindow (CreateStruct & Cs)

{

// First Call Basse Class Function.

Bool Bresutl = CEDITVIEW:: PrecreateWindow (CS);

// Now Specify The New Window Style.

CS.Style & = ~ (ES_AUTOHSCROLL | WS_HSCROLL);

Return BRESULT;

}

18, the display window of the general control

The MFC provides several CView derived window classes, encapsulating the functionality of universal controls, but still uses

Become document display window architecture: CEDITVIEW encapsulates editing controls, CTREEVIEW keeps tree list

Controls, ClistView encapsulates list display window controls, and cricheditView can handle multiple editing controls.

19, mobile window

Call CWnd:: setWindowPOS and specify the SWP_NOSIZE flag. Purpose location and parent window

Related (top window is related to the screen). Call CWnd:: MoveWindow must be specified in the window

the size of.

//Move window to Positoin 100, 100 of its parent window.

SetwindowPOS (NULL, 100, 100, 0, 0, SWP_NOSize | SWP_NOAORDER);

20, reset the size of the window

Call CWnd:: setWindowPOS and specify the SWP_Nomove flag, or call

CWnd:: MoveWindow But must specify the location of the window.

// Get the size of the window.

CRECT REWINDOW;

GetWindowRect (shutindow);

// Make The Window TWICE AS WIDE AND TWICE AS TALL.

SetwindowPos (NULL, 0, 0, REWINDOW. Width () * 2,

ReWindow. Height () * 2,

SWP_NOMOVE | SWP_NOZORDER);

21. How to click the area other than the window title bar to move the window

When the window needs to determine the mouse position, send WM_NCHITTEST information to the window, which can be handled

This information makes Windows considers the mouse on the window title. For dialogs and dialog-based applications,

To use ClassWizard to process this information and call the base class function, if the function returns htclient, indicate

The mouse is in the room area, returns HTCAPTION to indicate the mouse in the title bar of Windows.

UINT CSAMPLEDIALOG:: Onnchittest (cpoint point)

{

UINT NHITTEST = CDIALOG:: Onnchittest (Point);

Return (nhittest = = htclient)? HTCAPTION: NHITTEST;

}

The above technique has two points of disadvantages, one of which is a large window when the window's customer area is bike;

Second, it is not suitable for the main box window with several windows. There is also a method that when the user presses the left mouse button to think that the mouse is on its window title, use ClassWizard to process WM_LBUTTODOWN in the window

Information and send a WM_NCLBUTTONDOWN information to the main box window and a click to test HTCAPTION.

Void Csampleview:: OnlButtondown (uint nflags, cpoint point)

{

CView:: Onlbuttondow (NFLAGS, PONT);

// Fool Frame Window Into Thinking Somene Clicked ON

ITS Caption Bar.

GetParentFrame () -> PostMessage

WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM (Poitn .x, Point .y);

}

This technology also applies to dialogs and pair-based applications, just do not have to call CWnd:: getParentFrame.

Void Csampledialog:: OnlButtondown (uint nflags, cpoint point)

{

CDIALOG:: ONLBUTTONDOW (NFLAGS, GOIN);

// Fool Dialog Into Thinking Simeone Clicked on Its Caption Bar.

Postmessage (WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARM (POINT.X, POINT. Y))

}

22, how to change the background color of the window

Windows sends a WM_ERASEBKGND message to the window to inform the window erase background, you can use

ClassWizard Reserves the default handler of the message to erase the background (actually painting) and return True to

Prevent Windows Erase Window.

// Paint area there. Needs to be eRerated.

Bool Csampleview:: OneRaseBkGnd (CDC * PDC)

{

// CREATE A Pruple Brush.

Cbrush Brush (RGB (128, 0, 128);

// Select the brush into the device context.

CBRUSH * POLDBRUSH = PDC-> SELCETOBJECT (& Brush);

// Get the area there. Needs to be eRerated.

CRECT RECLIP;

PDC-> GetCILPBOX (& RCLIP);

// Paint the area.

PDC-> Patblt (rcclip.Left, RcClip.top,

Rclip.width (), rcclip.height (), patcopy;

// Unselect Brush Out of Device Context.

PDC-> SELECTOBJECT (POLDBRUSH);

// Return Nonzero to Half Fruther Processing.

Return True;

}

23, how to change the window title

Call CWnd:: SetWindowText can change any window (including controls).

// set Title for Application's Main Frame WINDOW.

AFXGETMAINWND () -> setWindowText (_t ("Application Title");

// set Title for View's MDi Child Frame Window .GetParentFrame () -> setWindowText ("_T ("MDi Child Frame New Title));

// set Title for Dialog's Push Button Control.

GetDigItem (IDC_Button) -> setWindowText ("Button New Title");

If you need to modify the title of the window (Note: Control is also a window), you should consider using half-text file.

Function AfxSetWindowText. This function is described in AfxPriv.h, implemented in Winutil.cpp,

It can't find it in the online help, it is in the middle and half of the AFXPriv.h, and the documentation will be discounted in the MFC issued later.

The implementation of AfxSetWindowText is as follows:

VOIK AFXAPI AFXSETWINDOWTEXT (HWND HWNDCTRL, LPCTSTSTR IPSZNEW)

{

ITN nnewlen = istrlen (iPAZNew);

Tchar Szold [256];

// Fast Check to See if text really changes (Reduces Flash In the Controls)

IF (nnewlen> _contof (szold) ||

::: GetWindowText (hwndcrtl, szold, _countof (szold) = nnewlen ||

Istrcmp (szold, ipsznew) = 0

{

// Change IT

:: SetwindowText (HWndCtrl, Ipsznew);

}

}

24. How to prevent the mainframe window from displaying a document name in its description

Creating the main box window and the MDI sub-window to usually have fws_addtotitle-style bit, if you don't want it

The document name is automatically added in the description, you must disable the style, you can use the ClassWizard reset

CWnd:: PrecreateWindow and close the fws_addtotitle style.

Bool CMAINFRAME:: PrecreateWindow (CreateStruct & Cs)

{

// Turn Off FWS_ADDTTTITITE IN MAIN FRAME.

CS.Styel & = ~ fws_addtotitle;

Return CmdiframeWnd:: PrecreateWindow (CS);

}

Close the FWS _Addtotitle style of the MDI sub-window will create a window with empty titles, which can be adjusted

Set the title with CWnd:: SetWindowText. Remember to set the title guide when you set your title.

转载请注明原文地址:https://www.9cbs.com/read-72084.html

New Post(0)