Visual C ++ programming experience (on)

zhaozj2021-02-11  206

Visual C 5.0 programming experience (on)

Another method of changing the window title, in the article published by the "Visual C 4.0 Programming Experience" published on September 1, 1997, a method of changing the window title, That is, the value of the member variable m_strtitle of the CFrameWnd class is modified in the member function of the CFrameWnd class. The value of the CFrameWnd class. The deficiency of this method is that only the contents of the window title can only be set in one time, and it cannot be modified at any time during the program run. For example, when you need to display the current coordinates of the mouse on the window header, we will use the full function BOOL SETWINDOWTEXT (HWND HWND, LPCTSTSTSTR LPSTRING) provided by Visual C . This function is actually a Win32 function, its first parameter requires a handle of a window frame, and the second parameter requirement is a 32-bit pointer to a constant string, a variable of the LPCTSTR type. Typically, we tend to dynamically change the contents of the window title in the application's document class or view class, so there is no existing handle window framework for us, so we also need to call before using the setWindowText () function. Another Win32 function AFXGETMAINWND () to get a pointer to the framework class of the application, such as using statements: CWnd * m_pcWnd = AFXGETMAINWND (); then, then call setWindowText () functions in the following form: setWindowText (* m_pcwnd, LPCTSTR) m_windowtext); // m_windowText can be a CString class variable to add bitmaps that are more than 256 colors as resources to the application Visual C 5.0 Bitmap editor comes with the bitmap editor to be browsed and edited more than 256 colors Bitmaps, and in the resource files are not allowed to be embedded (IMPORT) 256-color bitmaps as the resource (otherwise, the app is reported when the application is running). This feature allows us to use the Visual C to develop applications to enhance the aestheticity of interface drawings, so there are combination methods of using Visual C to develop application kernels to develop interfaces with Visual Basic. This issue is improved in Visual C 5.0. First, a bitmap editor can create and edit a 256-color bitmap. Second, Visual C 5.0 allows the programmer to embed 256 color or more bitmaps in the resource, but still unable to be browsed in the Visual C bitmap editor, and also requires Win32 Release to generate executable applications as compilation. . Another restriction condition is a bitmap that is 256-color or higher than the resource cannot be automatically opened and closed by the application kernel. For example, in the article named "Visual C 4.0 Programming Experience", a method of adding a bitmogram button for a dialog is mentioned in the article, that is, the program developer creates four bitmaps for each button. , Respectively, the bounce status (Up), Press State (Down), Input Focus Status (FOCUS), and Disable, and must be one of the above four states The combination is a bitmap identifier so that the application automatically finds the corresponding resource (ie, bitmap) when the bitmap button is drawn. However, this automatic mapping is limited to a bitmap that the Visual C bitmap editor can open.

Therefore, if a bitmap of 256 color is selected as the resource of the bitmap button, and it is possible to use the four states to be switched to each other, the following functions must be used to design the reference model. * S Set four constants: Button_up, button_down, button_focus, button_disable, the current state used to identify each button. * S In the corresponding dialog box class for the application, for each bitmap button (which is convenient below, it is possible to assume two) to set an object of the CRECT class: m_rect1 and m_rect2, record each button in the dialog box. Coordinate rectangle. Then set a integer variable for each button in this dialog class: Buton1_status and Button2_status record the current state of each button. The objects and integer variables of these CRECT classes are then initialized in the constructor of the dialog. * S Create a message processing function that responds to various states in the dialog class, such as onMouseMove (), ONLButton (), ONLBUTTONDOWN (), etc. * S At the same time, press CTRL and W to open the ClassWizard dialog box directly on the ClassWizard button on the toolbar. Select the dialog class class in the Class Name list box, select the class name of this class in the Object IDS list box, select the WM_PAINT message in the message list box and double-click it, then ClassWizard will be here An OnPaint () function is added to the dialog class. Then, select the identification name of the newly added toolbar button in the Object IDS list box, double-click the Command message in the Message list box, and the ClassWizard will join the corresponding message processing function in the dialog class. Close the ClassWizard dialog. This article gives some program code for reference only. Editor Note: The source program is published in http://www.computerworld.com.cn/98/skill/default.htm. Welcome! Do not load menu in the application, toolbar and status bars (SDI and MDI) generated by AppWizard, MFC class libraries have loaded menu (including a system menu) , Tool bar and status bar. But sometimes due to special needs, we may want to load menus, toolbar and status bars in advance in our application, then we need to manually delete and modify statements in some classes. The steps are as follows: 1. Open the mainfrm.cpp file, use the function drop-down list box to find the oncreate () function using the function drop-down list box. The statement that creates the toolbar and the status section is commented on the following procedure.

INT CMAINFRAME :: OnCreate (lpcreatestruct lpcreatestruct) {if (cframeWnd :: oncreate (lpcreatestructure) == -1) Return -1; // Start the addition symbol / * if (! m_wndtoolbar.create (this) || ! m_wnd ToolBar.LoadToolBar (IDR_MAINFRAME)) {TRACE0 ( "Failed to create toolbar / n"); return -1; // fail to create}! if (m_wndStatusBar.Create (this)! || m_wndStatus Bar.SetIndicators (indicators , SIZEOF (INDICATORS) / SIZEOF (UINT))) {Trace0 ("Failed to Create Status Bar / N); Return -1; // Fail To Create} // Todo: Remove this if you don't want Tool Tips or a resizeable toolbar m_wndToolBar.SetBarStyle (m_wndToolBar.GetBarStyle () | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC); // TODO: Delete these three lines if you do not want the toolbar to be dockable m_wndToolBar.EnableDocking (CBRS_ALIGN_ANY); EnableDocking (CBRS_ALIGN_ANY ); DockControlbar; // End the comment * / return 0;} 2. In the mainfrm.cpp file, use the function drop-down list box on the toolbar to find the PrecreateWindow () function. Set the cs.style into the following form, that is, the system menu is not loaded. // Create A Window WITHOUT Min / Max Buttons, System Menu, or Sizable Border Cs.Style = WS_OVERLAPPED | WS_BORDER; 3. In the primary application, that is, in a .cpp file with definition theApp full variable, use the function on the toolbar The drop-down list box and find the initInstance () function. In the PDOCTEMPLATE = New CSINGEDOCTEMPLATE, replace IDR_MAINFRAME with NULL. As shown in the following procedure.

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

New Post(0)