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

 

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:

The next day (graphics, text-based programming, menu):
    1, simple drawing
    2, using brush and the brush
    3, using the caret
    4, fonts operation
    5, the operation menu associated
------------ -------------------------------------

0, simple graphics

1, draw a straight line
  a) mouse down and lift
  b) create an object painter CClientDC
  c) starting and ending
   CDC :: MoveTo
   CDC :: LineTo
  d) select your class a> a right-click> Add to add private variables A // General was added to complete the constructor automatically initialized at a

 the CClientDC DC (the this);
 
2, pen, brush, using
 a) defining artist
 b) custom brush (brush) a CPen, the CBrush
 C) to the brush painters CDC :: SelectObject
 d) brush: color, style, bitmap

under standard bool BOOL (windows with internet)
#include <Resource.h> remove an error line

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

A simple drawing

 a) draw straight lines
 b) the use of the brush CPen
 c) the use of the brush CBrush
 d) writing, CFont use

CPaintDC only onpaint () with
CClientDC can (app, frame generally do not)

important than learning the interface, but how deal with the problem, process / Prerequisites

Second, the text editor

Caret: - Create Show - Mobile
1) Create caret :: CreateSolidCaret the CWnd ()
    A) :: CreateSolidCaret create the CWnd ()
    B) show :: ShowCaret the CWnd ()
    C) caret is determined according to the height of the height of the font
    --------
  | word |
    --------
          acquire font information :: the GetTextMetrics the CDC ()
    D) disposed caret position :: SetCaretPos function, the CWnd ()
 
2) in the character message handler writing
    a ) :: TextOutW writing the CDC ()
    B) obtaining size information of a character string CDC :: GetTextExtent () // rectangular width occupied strlen (); refers to the number of elements
    c) intercepting the character string specified length of the left (CString) // number of elements; - str = str.Left (1 str.GetLength ())
 
 

Third, the gradual change fonts

1) using the timer
    a) set the timer: the CWnd :: the SetTimer ()
    B) Off Timer: the KillTimer the CWnd :: ()
    C) Timer message: the WM_TIMER
2) in the view class the OnDraw (), the writing CDC TextOutW :: ()
. 3) designated writing area: the CDC :: the DrawText ()
. 4) so that failure of the window, the PAINT generating side, the OnDraw indirect call () function: CWnd :: Invalidate
 
 

Fourth, the menu of related operations

1) command menu response function of
    a) playing the menu, ID can not be edited, press down, pop-up menu item
    b) inelastic menu, ID editable
    c) menu responsive to a route (order) command message
    d) message type
      [ Non-standard message]
      the WM_COMMAND, command message, advertisement message, CCmdTarget, CWnd subclass subclass can receive the non-standard message
      [standard message]  
      WM_XXXX the CWnd subclass to receive the standard message      
      [command message]
      the WM_COMMAND: menu select handler
      standard message : properties -> message
      announcement message: click, handler

      CWnd may accept any message
      CCmdTarget unacceptable standard message
  
2) related to static operation menu
corresponding operation in the frame class, implemented in the OnCreate // OnCreate () in dilute constructor there may be handled only after construction finished window
a) Gets the menu bar: CWnd :: GetMenu
B) obtaining sub-menu in the menu bar: CMenu :: GetSubMenu
    a) logo menu: CMenu :: GetSubMenu
      MF_BYPOSITION: by location
      MF_BYCOMMAND: by ID
    b) Set the default menu: CMenu :: SetDefaultItem
      Note: a menu item can only set a default menu
    c) Disable menu: CMenu :: EnableMenuItem
      Note: You need to CFrameWnd :: m_bAutoMenuEnable member variable is set to FALSE
    d) dividing line
C) shift in addition to the menu :: the SetMenu the CWnd
      the SetMenu (NULL);
D) loading the menu
    a) creating a menu :: LoadMenu to CMenu
    B) setting menu :: the SetMenu the CWnd
    D) separated from the Windows menu CMenu :: Detach CMenu object
E) menu command update mechanism

F) the shortcut menu, pop-up menu (menu must be new, can not use the main menu frame and the like)
    because the region is a mouse click in the viewing area, it is necessary to process in the view class
    a) treating a right click event WM_RBUTTONDOWN
    acquires the b) required submenu
    c) popup menu item TrackPopupMenu CMenu ::
    D) client coordinates turn the screen coordinates: the CWnd :: ClientToScreen


. 3) related to the dynamic menu operations
    a) to create an empty menu CreateMenu CMenu ::
    B) an additional elastic menu CMenu :: AppendMenu (MF_POPUP,)
        Each menu has a menu handle: CMenu :: m_hMenu
        redraw the menu bar: the CWnd :: DrawMenuBar

 C) is added AppendMenu normal menu CMenu :: (MF_STRING,)
 D) Insert menu InsertMenu, CMenu ::
 E) delete menu CMenu :: DeleteMenu


Fifth, dynamic icons

1) Timer: the SetTimer the CWnd ::
    A) timer signal: the WM_TIMER
    B) sets the timer should be placed the OnCreate ()
2) loading custom icons (WinAPI): the LoadIcon ()
    A) is converted to a string resource ID MAKEINTRESOURCE ()
    B) Get the application example:
      AfxGetlnstanceHandle ()
      AfxGetApp () -> m_hInstance
. 3) disposed icon (WinAPI) SetClassLong ()
    window handle: CWnd :: m_hWnd

Guess you like

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