MFC advanced course in layman's language version. Notes Day 3

 

Usually have no access to the MFC code, this is the project dictates, the project involves hands MFC, feeling a bit mean, so looking at the video to learn b station, had not started operating, just fly, a general understanding of this flow of the code, now offer video link station b: MFC advanced course in layman's language version of the
following is the course notes:

On the third day (dialog common control):
    1, making dynamic icons (timer)
    2, dialog box (modal and modeless)
    3, based on the programming dialog
    4, the use of common control
----- --------------------------------------------
work
inside the structure variables Do not initialize
initialized in the constructor at.

Invalidate (); // indirect call OnDraw ()


resource view -> Menu -> New menu -> [restart] -> right click -> add an event handler

-------------- -----------------------------------

A dialog

1) Modal Dialog
  a) resource view -> Dialog -> right click -> Insert Dialog
  B) to create the dialog object the CDialog
  C) run in the DoModal :: modal the CDialog

2) modeless dialog box
  a) resource view -> dialog -> right click -> insert dialog
  b) create a dialog object, where the need to declare member variables .h for CDialog
  c) create the dialog box (or in the constructor OnCreate (), aim to create only once) CDialog: : the Create
  d) :: ShowWindow display window CWnd
 
3) custom dialog class (important)
  A) resource view -> dialog -> right click -> insert dialog
  b) click on the dialog template -> right click -> Add class
  c ) more out of a custom class, .h there is a class and enumeration associated dialog enum {IDD = IDD_DIALOG2};
 

Second, based on the dialog (Control) Programming

New construction -> [Select] dialog based on
1) the frame dialog based applications
  a) application classes: inherits the CWinApp
    the InitInstance (): entry address of the program
  b) dialog class: inherited CDialogEx
    the OnPaint ()
    the OnInitDialog () : initialization dialog
    DoDataExchange (): variables and the associated control and exchange
  

Third, the common controls

1) Static Control CStatic (label QLabel Qt in) text / image can be put

  Display some text information
  a) Caption: modify the content displayed
  b) ID: XXX_STATIC, static ID, does not respond to any messages (events)
 

2) announcement message button CButton

  a) Caption: modifying the display of the content
  b) treating the BN_CLICKED message, the user clicks the button Auto:
     1) attribute -> Control Events -> select the Event
     2) Double-click the button to automatically generate a message handler
======= =======================================   
custom class:
class view -> class view -> Add class -> MFC class -> MyButton-> base class CButton
associated variable -> right-click the button to add the variables -> MyButton m_button (control type)

control on a dialog -> right click class Wizard, associate members can see variable distribution

// bitmap handle acquired by the route, and set the width, height
#define hBMP (filepath, width, height)
(HBITMAP) the LoadImage (AfxGetInstanceHandle (), filepath, IMAGE_BITMAP, width, height, LR_LOADFROMFILE | LR_CREATEDIBSECTION)
// ico get a handle through a path, the default size
#define HICO (filepath) (HICON) LoadImage (AfxGetInstanceHandle (), filepath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE
================ ==============================  

3) escape button (similar to Qt upgrade)

 a) custom button class inherits CButton
  file selection class view of the beginning clip -> right click -> Add Class -> MFC-> MFC class
    1) treated mouse move message the WM_MOUSEMOVE
    2) to get the parent window pointer CWnd :: GetParent
    3) capture range of the parent window client area :: the GetClientRect the CWnd
    . 4) capture range button :: the GetWindowRect the CWnd
    . 5) generates a random coordinate rand ()% w
    position 6) moving the MoveWindow :: button the CWnd
 B) associated variables
  selected a button > Right-click a> Add a variable> variable type: MyButton a> variable: button
  finally, button and the selected button associated with our success, operating button, button equivalent (Qt lift) on the operation ui
    
 c) set the button bitmap
    1) button properties: bitmap a> True
    2) in dialog class OnlnitDialog () process as follows
     a) a template to create a bitmap
     b) to create a bitmap object the CBitmap
     C) loading the LoadBitmap :: bitmap resource the CBitmap
     b) button the bitmap :: a SetBitmap CButton
     E) obtaining the size of the bitmap :: GetBitmap the CBitmap
     F) reset button size (the same size, pictures and buttons) CWnd :: MoveWindow
 

4) edit box CEdit

 a) association categories: the Value, Control
  . 1) the Value: Standard common data type CString str;
     context variables and data control interactive update
   a) the contents of the editing area is updated to the in str UpdateData (TRUE);
   B) the contents of str updates the editing area UpdateData (FALSE);
   
  2) control: control type
   Object is the control type of control on the UI

 B) common property
  1) number -> True only numeric
  2) password -> True Cipher mode
  3) Want return -> True receiving the Enter key, word wrap, only in multiline mode, in order to wrap
  4) multiline -> True multi-line mode
  5) Auto VScroll -> True
     vertical Number of the Scroll -> True when the vertical way too many characters, scroll bars automatically appear
  6) Read only -> True read-only

 c) copy small cases
 associated control: control type, only one association
  1) to obtain the GetWindowText :: edit area content CWnd
  2) set content editing area :: SetWindowText CWnd
  3) Close the dialog window
     CDialog :: OnOK ();
     CDialog :: OnCance1 ();

5) radio buttons, check boxes (the CButton particular, no single box, box type)

 a) single box
  1) property: Ctrl + D sequentially discharged view numeral
  2) with a button group Group set TRUE
  . 3) are initialized at box :: CheckRadioButton the CWnd
  . 4) button is pressed CWnd :: IsDlgButtonChecked

 b) box

  1), is frequently associated variable UpdateData BOOL (TRUE), UpdateData (FALSE);
  2) is provided to select the status :: SetCheck the CButton
  . 3) acquisition button selected state :: The GetCheck the CButton
UpdateData (TRUE) // Get content editing area
UpdateData (FALSE) // update the content to the editor

6) list box CListBox

 a) add a string to the list box CListBox :: AddString
 an item b) a list of the selected list box, automatically triggering events: LBN_SELCHANGE
    1) to obtain the currently selected item :: GetCurSel CListBox
    2) to obtain the contents of the specified location :: GetText CListBox
 c ) remove the specified position of the deletestring :: string the CListBox
 D) at a specified position of the insertion string CListBox :: InsertString

7) combo box (drop-down box) the CComboBox

    a) obtaining content: CComboBox :: GetLBText
        other interface and almost the same usage CListBox
    b) property
      1) data: set contents, contents of different English semicolon ";" partition
      2) type: dropdown editable, only droplist display

8) scroll bar CScrollBar (Horizontal Scroll Bar)

 a) providing a scroll bar for a given minimum and maximum positions: the SetScrollRange CScrollBar ::
 B) acquires a current position of the scroll box: CScrollBar :: GetScrollPos
 C) setting a current position of the scroll box: the SetScrollPos CScrollBar ::
 D) treatment scrollbar event, the scroll bar control itself is not processed, the processing is the parent window (dialog class) in the scroll bar belongs
  processed signal: the WM_HSCROLL
 E) the positional relationship between the scroll bar
  switch (nSBCode) // determines which part of the scroll bar
  {
  Case the SB_THUMBPOSITION : // slider position
     BREAK;
  Case SB_LINELEFT: // left arrow
     BREAK;
  Case SB_LINERIGHT: // left arrow
     BREAK;
  Case SB_PAGELEFT: // arrows between the left and the slider
     BREAK;
  Case SB_PAGERIGHT: // arrow between the slider and right
     BREAK; 
  default:
     BREAK;
  }

Use 9) spinner (rotation) of the button SpinControl

 a) property is set to
   Auto Buddy -> True
   the Set Buddy Integer -> True
 b) fine-tuning (rotation) order of the buttons than the partner big one, and can not be 0 appear (Ctrl + D view)
     
10) list view control CListCtrl
 a) property to view -> report (report mode)
 B) common Interface
  1) provided a list of style CListCtrl :: SetExtendedStyle
   LVS_EX_FULLROWSELECT: select an entire row
   LVS_EX_GRIDLINES: grid manner
   what specific style, can be viewed through the MSDN

  2) Get a list style CListCtrl :: SetExtendedStyle
   specifically the style which can be viewed through the MSDN
  
  . 3) is inserted into a column :: InsertColumn the CListCtrl
  
  . 4) format string
   CString STR
   str.format (T ( "John Doe _% d"), i)
   
  after 5) insert a new item, can be set sub items
   a) insert a new entry (determined several lines) the InsertItem the CListCtrl ::
   B) subkey set contents (set of columns) CListCtrl :: SetItemText

11) TreeView control CTreeCtrl

 a) Common property
  has buttons a> to true
  has Lines a> to true
  Lines AT the root a> to true
 B) writing code Process
  1) load custom icons
   a) obtaining the application object pointer AfxGetApp ()
   B) loading a custom icon CWinApp: : Loadlcon
  2) to create an image list
   a) .h file pattern defined in the class list (CIsmageList) Object
   b) creates the Create image list :: ClmageList
   C) adding the image list :: the Add icon ClmageList
  . 4) disposed graphics state list CTreeCtrl :: SetImageList
  5) insert node :: InsertItem CTreeCtrl
  6) to set the default selected item CTreeCtrl :: SelectItem


12) Label controls CTabCtrl

 1) in the toolbox and drop ui Control the Tab
 2) the TabSheet.h and TabSheet.cpp in the project file at the same level directory, and added to the project directory
 3) related to the ui Tab Control Control type (CTabSheet)
 4) CTabSheet dialog object is added
  a) a resource view> dialog a> a right click> insert dialog
  B) setting the appropriate properties:
   Style a> child (sub-window)
   border a> None (borderless)
  C) custom categories: click dialog a template> a right click> Add class
  d) the main dialog class, the class object define a custom
  e) the main dialog class the OnInitDialog () for initialization
  f) CTabSheet the AddPage :: Add dialog CTabSheet ()
   tmp.AddPage (_T ( "system management"), & TL, tab1):
    tmp: is CTabSheet objects
    tl: need to add a dialog object
    tab1: dialog ID
  G) display window: CTabSheet :: show ()

Guess you like

Origin www.cnblogs.com/yeyeye123/p/11032297.html