How to throw (throw) is derived from CUSEREXCEPTION?
When an exception I try to capture (catch) a derived class, I get the following error "error C2039: 'classCMyException': is not a member of 'CMyException' 'classCMyException': undeclared identifier 'IsKindOf': can not parameter from 1 convert 'int * 'to' const struct cruntimeclass * "
You must make your CMYEXCEPTION class dynamically by using declare_dynamic () and import_dynamic () macro. The Catch Macro hopes to obtain runtime information about being thrown.
Is an exception class be derived from CUSEREXCEPTION?
No, "User" in CUSEREXCEPTION refers only to the exception generated by the user. The only anomalies you can derive are common misunderstandings.
How to build a CDC class from HDC?
Sometimes the Windows API will give you a DC handle, you can build a CDC class through it. For example: a drop-down list, a combo box, and a button. You will receive a drawing message via HDC. Below is a block that converts HDC to your more familiar CDC. You can also use this trick to use any other MFC class and Windows handle.
Void myodlist :: DrawItem (LPDRAWITEMSTRUCT LPDRAWITEM) {cdc mydc; mydc.attach (lpdrawitem-> HDC); file: // Insert other required code here.
File: // If you don't separate your handle, it will be deleted, resulting in a problem. Mydc.detach ();
Another way is to call the FromHandle method of the CDC class: CDC * PDC = CDC: fromHandle (LPDRAWITEM-> HDC);
It is still unclear that which method is more preferred - the use of fromHandle () errors may be less, because it does not require you à
耄 耄etach) handle.
How to read 256 color bitmap files from disk?
Currently, MFC does not support direct reading and display DIB files and BMP files. However, there are many sample applications to explain how to complete this task. The first example is the MFC sample program DIBlook. Sample MultDocs reads and displays DIB files and BMP files with the same source code provided by Diblook. Examples included in the other two VC are DibView programs and showDIB programs in the SDK package.
How to change the size of a view?
Typically, you can call function moveWindow () to change the size of the window. In applications developed with MFC libraries, the view is a sub-window surrounded by the frame window. To change the size of a view, you can get the pointer of the Frame Window by calling the function getParentFrame (), then call the function moveWindow () to change the size of the parent window. When the parent frame window changes the size, the view will automatically change the size to adapt to the parent window.
How to change the size of a CFormView?
To learn more about, you can see the article about Visual C basics Q98598 "Using CFormView In SDI and MDI Applications". Basically, in the class derived from the CFormView class, you must overwrite the function onInitialupdate (). Other details of CFORMVIEW can be obtained from this article. Declare the following functions in class CLIKETHISVIEW: Virtual void OnInitialupdate ();
In the code of the CLIKETHISVIEW, the function is as follows:
Void CLIKETHISVIEW :: OnInitialUpdate () {file: // Make the window with the main dialog Sizes CFORMVIEW :: OnInitialUpdate (); getParentFrame () -> recalclayout (); resizeParentToft (/ * false * /);} How to use a document New view of the template?
In applications created with AppWizard, you have two options: changing the derived relationship of the current view or create a new view and use a new view and the original view at the same time in your MDI program.
In order to create a new view, you can derive a new class with ClassWizard by CVIEW. When the new class is created, the steps of the two are the same as the view provided by AppWizard after the new class or modified.
Modify the header file of the view class to rename all references to the CView class for the name you want. The class in this example is derived from CScrollView. Typically, this step includes changes to the class, and the viewing class will be derived from the following way: Class CMYVIEW: Public CscrollView
Modify the implementation file of the view class to rename all references to CVIEW for the name you want. This includes change the statement of the line of IMPLEMENT_DYNCREATE: Implement_DyncReate (CMYVIEW, CSCROLLVIEW)
Change the statement of the line of begin_message_map to: begin_Message_Map (CMYVIEW, CSCROLLVIEW)
And all other CVIEWs are changed to CScrollView.
If your modified view is generated by AppWizard, you don't need to make more changes. And if you create a new view, first find the call to the AddDDOCTemplate () function in the cwinapp :: initInstance () function. The third parameter of the addDoCtemplate () function is Runtime_Class (CsomeView), with CMYVIEW instead of CsomeView, can change the current view to a new view. In the MDI application, you can increase the second addDoctemplate () function call to use the multi-view type to change the runtime_class (cmyView).
To get more information, please refer to Q99562 Related Articles "Switch Views In A Single Document Interface Program".
How to change the background color of the view?
You can change the background color of CView, CFrameWnd, or CWND object by handling WM_ERASEBKGND messages. Please see the following block:
Bool Csampleview :: OneRaseBkgnd (CDC * PDC) {// Set the desired background color brush CBRUSH backbrush (RGB (255, 128, 128)); // Save Old Brush CBRUSH * POLDBRUSH = PDC-> SelectObject (& BackBrush); CRECT RECT; PDC-> getClipbox (& Rect); // Erase the required area PDC-> Patblt (Rect.Left, Rect.top, Rect.width (), Rect.Height (), PATCopy; PDC-> SelectObject (Poldbrush); Return True;} and I use the following method to solve this problem:
HBRUSH dlgtest :: OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor) {switch (nCtlColor) {case CTLCOLOR_BTN: case CTLCOLOR_STATIC: {pDC-> SetBkMode (TRANSPARENT);} case CTLCOLOR_DLG: {CBrush * back_brush; COLORREF color; color = (COLORREF) GetSysColor (COLOR_BTNFACE); back_brush = new CBrush (color); return (HBRUSH) (back_brush-> m_hObject);}} return (CFormView :: OnCtlColor (pDC, pWnd, nCtlColor));}
How to get the current view?
The best way is to pass the view as a parameter. If you can't do this, you are confident that it is currently activating the document and the current activation view, you can also get this view. For details, see Visual C Articles Q108587 "Get Current Cdocument Or CView from Anywhere".
Simply mention, use:
((Cframewnd *) AFXGETAPP () -> m_pmainwnd) -> getActiveDocument ()
with:
((CframeWnd *) (AFXGetApp () -> m_pmainwnd) -> getActiveView ()
Come get documents and views. A good way is to package them in the static function of your CMYDoc and CMYVIEW class, and check if they belong to the correct russime_class. However, if this view is not the current activation view or you activate the OLE locally, this will not succeed.
How to build multiple views in a document?
CDOCTemplate :: CreateNewFrame () Function Creates an additional view of the document in the MFC MDI application. In order to call this function, you want to specify a pointer to the CDocument object (a document that will be established to establish a view) and a pointer to the frame window that can be copied from it. In general, the second parameter of the function is NULL.
When the application calls the function creageNewFrame (), the function creates a frame window and the view within the window. The type of frame window and its view is determined by the document tangent (CDOCTemplate) associated with the CreateNewFrame () function calls the specified document. The CHKBOOK MFC sample program in Visual C also demonstrates how to establish an additional framework and view for documents. Check the cchkbookapp :: OpenDocumentFile () function in the chkbook.cpp file.
Another example of using a function createNewFrame () is a MultView sample program.
The CreateNewWFrame () function creates a framework and a view, not just a view. If the CreateNewFrame () function does not fully meet your needs, you can refer to the steps necessary to establish a structure and view for the source engine of the CreateNewWFrame () function.
How do I get all the views in the MDI program?
You must use the functions not recorded in some documents:
CDocument :: GetFirstViewPosition (); // DOCCORE.CPP CDocument :: GetNextView (); // DOCCORE.CPP CMultiDocTemplate :: GetFirstDocPosition (); // DOCMULTI.CPP CMultiDocTemplate :: GetNextDoc (); // DOCMULTI.CPP
You also need to deal with CWINAPP members M_TemplateList. Note: Changes in MFC version 4.0. There is now a class called CDOCManager to help you show all views and documents. Please refer to "MFC INTERNALS" to get more detailed information.
How to build a CScrollView class that can be pulled with a mouse
Download autosv.lz from the MSMFC library on CIS. This program tells you how to implement an auxiliary message loop to manage the mouse activity, and provide hook to customize the code. This is a free software.
Do you have to use a view / document structure?
The MFC does not necessarily require you to use the document / view structure. View Hello, MDI and HelloApp example - they are useless?
The intrusion 峁埂 4 蠖嗍 齅 fc features can be applied in non-document / view applications. But when you don't have documentation / ê
油 冀 峁 峁 ヒ ヒ. 崾 崾 崾.... ヒ. ヒ ヒ ヒ ヒ.. ヒ ヒ ヒ ヒ ヒ だ だ ヒ ヒ だ だ...
How to get the current document?
Please refer to "How to get the current view?" Chapter.
When is the documentation?
In the SDI program, the program is deleted after the program exits. In the MDI program, the document is deleted when the last view associated with this document is turned off. In order to use this document simultaneously in SDI and MDI, you should delete the data of the document in the virtual function deleteContents () function, not in the destructor.
How to build multi-document?
To join the support of the additional document type, you can create and register additional CMULTIDECTEMPLATE objects in the CWINAPP derived class. This method has been explained in the MultDocs sample program. The general steps to add an additional document type to the MFC program are as follows:
Use AppWizard to create a new document class and view class. Add new resource strings to support new document classes with resource editor. To know more about the document model string format, see "How to understand the document sample string".
Add additional application icons and menu resources with resource editing. Note that each of these resources must be the same as the ID of the document template string created in step 2. This ID is used by the CMULTIDEMPLATE class to identify resources related to the attached document type.
In the initInstance () function of the application, another CMULTIDEMPLATE object is created and registered with the cwinapp :: adddhemplate () function. E.g:
CMultiDocTemplate * pDocTemplate2 = new CMultiDocTemplate (IDR_DOC2TYPE, RUNTIME_CLASS (CDoc2), RUNTIME_CLASS (CMDIChildWnd), RUNTIME_CLASS (CView2)); AddDocTemplate (pDocTemplate2); and finally, the custom serialization and mapping code into your new document and the view class .
How to get a list of open documents?
The following program segment indicates how to get the pointer list of all documents established with the CDOCTemplate object. In the following block, CMYAPP is derived from CWINAPP. Variable M_TemplateList is a cptrlist object that is a member variable of CWINAPP, which contains a list of all document template pointers. Document Template Functions getFirstDocPosition () and getNextdoc () are used to get iteratively to get every document template in the document template list.
void CMyApp :: GetDocumentList (CObList * pDocList) {ASSERT (pDocList-> IsEmpty ()); POSITION pos = m_templateList.GetHeadPosition (); while (pos) {CDocTemplate * pTemplate = (CDocTemplate *) m_templateList.GetNext (pos); Position POS2 = PTEMPLATE-> getFirstDocPosition (); while (pOS2) {cdocument * pdocument; if (pDocument = ptemplate-> getnextdoc (POS2))! = Null) PDOCLIST-> addhead (pdocument);}}}}
In the reference manual or online help, there is no explanation of the public member functions of two CDOCTemplate classes. However, these public member functions are defined in the CDOCTemplate class and provide simple support for the front and rear searches before and after opening the document.
These functions are as follows:
Function Virtual Position getFirstDocPosition () const; call this function to get the location of the first document associated with the template in the open document list. The value returned Position can be repeatedly used by the GetNextDoc member function.
Function Virtual CDocument * getnextdoc (position & rposition) const; rpost is the position value returned by the getNextDoc or getFirstDocPosition member function. This value cannot be NULL. This function is called to be iterated in all open documents. This function returns the position value of the document identified by the RPosition and sets the rposition to the next document in the list. If the retrieved is the last document in the list, rposition will be set to null.
Note that this is only valid for the MFC3.2 version or lower version, please refer to the MFC4.0 version:
void CMyApp :: DoSomethingToAllDocs () {CObList pDocList; POSITION pos = GetFirstDocTemplatePosition (); while (pos) {CDocTemplate * pTemplate = GetNextDocTemplate (pos); POSITION pos2 = pTemplate-> GetFirstDocPosition (); while (pos2) {CDocument * pDocument ; If (pDocument = pTemplate-> getNextdoc (POS2)) pdoclist.addhead (pDocument);}}}}}}}}}}}}}}}}}}}}}}}}}}}} (! PDoclist.Itempty ()) {POS = pdoclist.getHeadPosition (); while (pOS) {file: // Each document calls the cDocument function (cDocument *) PDOCLIST.GETNEXT (POS)) -> UpdateAllViews (null);}} How to make my program do not create a new document when starting?
Add: cmdinfo.m_nshellcommand = ccommandlineinfo :: filenothing
I have forgotten the original, where is it coming, only published into original, if there is a problem, please inform me in time.
I will correct it for the first time. Thank you