MFC - Static Text control common operations

1, Add Variable

When selected space, the right mouse button and select "Add Variable" modify access on demand, you can name.

Note: The name here is that we are going to uniquely identify the control operation.

2, Caption property to dynamically set control

For example, set the Caption "ha ha", as follows:

m_txtMsg.SetWindowTextW(TEXT("哈哈哈哈"));

3, dynamic access to the Caption property of a control

// for receiving information acquired Caption 
CString str;

// get m_txtMsg Caption property of 
m_txtMsg.GetWindowTextW (str);

// display what 
MessageBox (str);

4, BMP picture display

Add a Static Text control, and add a property to m_pic.

    // 1, styling static control, it can use a bitmap, and show that the test indexer center   
    m_pic.ModifyStyle ( 0x0F , SS_BITMAP | with SS_CENTERIMAGE);
     // 2, the handle through a path acquired bitmap 
#define hBMP (filepath, width, height) (HBITMAP) LoadImage (AfxGetInstanceHandle (), filepath, IMAGE_BITMAP, width, height, LR_LOADFROMFILE | LR_LOADFROMFILE)

    // 3, the width and height provided 
    CRect rect;
    m_pic.GetWindowRect (RECT); // get the image width and height

    // 4, static controls set Bitmap 
    m_pic.SetBitmap (hBMP (TEXT ( " ./1.bmp " ), rect.width (), rect.height ()));

 

  Author: Jeremy.Wu
  Source: https://www.cnblogs.com/jeremywucnblog/
  This article belongs to the author and blog Park total, welcome to reprint, but without the author's consent declared by this section must be retained, and given the apparent position of the article page the original connection, otherwise the right to pursue legal responsibilities.

Guess you like

Origin www.cnblogs.com/jeremywucnblog/p/12565147.html