VC ++ MFC Common Skills (1)

zhaozj2021-02-16  52

VC MFC Common Skills (1)

I have now learned VC 6.0 MFC for two months, and the pain when I begin school MFC also remembered. These two months learning MFC can be said to be a bumpy course. When I learned SDK in school, I never listened to the teacher's lecture. When I arrived today, I regretted the original behavior, nor did it come to today's so wolf.

During this time, I summed up some techniques that are often used, share with you. Let the bacchier do not have a satisfactory answer to solve a problem everywhere.

(-). The following is a common AFX global function:

AFXFORMATSTRING1: Similar to PrintF a normal string formatted

AFXFORMATSTRING2: Similar to Printf typically formatted strings

AFXMessagebox: Similar to Windows API Functions MessageBox

AFXOUPUTDEBUGSTRING: Transfer string to the extension device

AFXGetApp: Pointer to get Application Object (CWINAPP derived object)

AFXGETMAINWND: Get pointers for program main windows

AFXGETInstance: get the program's Instance Handle

(2) Conversion between CString and CHAR [].

In VC, I am afraid these two are often converted.

Char str [10] = "STR";

CString sstr = "sstr";

SSTR.FORMAT ("% S", STR);

STRCPY (STR, (LPCTSTR) SSTR);

(3). Close procedure:

PostquitMessage; or PostquitMessage (WM_DESTROY);

More absolutely closes all procedures :: EXITWINDOWS ();

(4) When the window is turned off, when saving the file, you can add a function here:

1.) In OnClose () in CMAINFRAME, use MessageBox ("Content", "Title", combined form); combination form can view MSDN's MessageBox () Function

2.) On cxxxdoc :: savemodified (), only AFXMessageBox ("");

Cannot use messagebox () functions

(5) How to modify the title of the form:

1.) Modify the title of the main window: m_pmainwnd-> setWindowText ("Your title");

2.) If you do this in your Document class, call SetTitle ("..."), if you change it in your View class, getDocument () -> setTitle ("...")

3.) If you want to replace the title of the window, use: AFXGETMAINWND () -> setWindowText ("Your title");

(6). Get the title of the form:

1.) AFXGETMAINWND () -> getWindowText ();

2.) First findwindow () to find the HWnd of the window, in getWindowText ();

(7). In multi-document / view: 1. Maximize the child window:

Void cchildframe :: activateframe (int ncmdshow)

{

// Todo: Add Your Specialized Code Here and / or Call The Base Class

Ncmdshow = sw_maximize;

CmdichildWnd :: ActivateFrame (ncmdshow);

}

2.) Shield Sub Dialog: Show these two sentences in the app class

IF (! ProcessShellcommand (cmdinfo))

Return False;

3.) Turning the sub-window:

:: SendMessage (:: AfxgetMainWnd () -> M_HWND, WM_COMMAND, ID_FILE_CLOSE, 0);

(8). After loading the custom cursor, in the process of moving, the shape of the mouse is always swaying between the custom and the default cursor, which can be solved, and add the following in precomreateWindow (). sentence:

Bool CXXXView :: PrecreateWindow (CreateStruct & Cs)

{

// Todo: modify the window class or styles here by modifying

// The createStruct CS

cs.lpszclass = afxRegisterWndClass (cs_hredraw | cs_vredraw, 0,

(Hbrush) :: getStockObject (White_brush), 0);

Return CView :: PrecreateWindow (CS);

}

(Nine). How to ban changes the size of the window and the window that cannot move:

Add the CMAINFRAME on the oncreate function:

CMenu * ptopmenu = getSystemMenu (false);

PtopMenu-> RemoveMenu (4, mf_byposition); // Maximum window is not available

Ptopmenu-> RemoveMenu (2, mf_byposition); // size

Ptopmenu-> RemoveMenu (1, mf_byposition); // Make

(10) Make the window at the forefront:

Just add the following code in the initInstance () function in the App class:

Bool CWindowontopapp :: InitInstance ()

{

// This is slightly downloaded by VC automatically generated code.

m_pmainwnd-> showwindow;

m_pmainwnd-> UpdateWindow ();

m_pmainwnd-> setwindowpos (& CWnd :: Wndtopmost, 0, 0, 0, 0,

SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

Return True;

}

All the above is summarized in the process of learning, but this is only a small part, some is an answer from netizens, and some are taken from the forum, and some are taken from learning books, some are to explore. Thanks here to those who have given me help. After I am going to school, I will sum up and share the fun of programming with you! Welcome everyone to contact me: Citychaser@163.com

to be continued………….

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

New Post(0)