How do I create an mfc control?

嗷呜的土拨鼠 20 Reputation points
2023-03-24T01:35:38.6633333+00:00

I'm a student and I' learning MFC recently.

I found that some controls cannot be created using toolbox, but I need them. How do I create and use them? Can someone give me an example?

I would Be very grateful if anyone could give advice on learning MFC

Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. YujianYao-MSFT 4,296 Reputation points Microsoft External Staff
    2023-03-24T02:00:49.25+00:00

    Hi 嗷呜的土拨鼠,

    There are many controls in MFC, which are only a part of controls in Toolbox, and many controls need to be manually created by you.

    Here I will show you how to create a control manually:

    CEdit m_edit;
    CRect rect(85, 110, 180, 210);
    
       m_edit.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP |
                         ES_AUTOHSCROLL | WS_BORDER,
                     rect, this, IDC_EXTRA_EDIT);
       m_edit.SetFocus();
    

    The above code can create a CEdit control. You could click on the hyperlink on the left of this document, there are many MFC classes for you to learn.

    Best regards,

    Elya


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Castorix31 90,686 Reputation points
    2023-03-24T02:19:14.4666667+00:00

    I found that some controls cannot be created using toolbox, but I need them.

    Which controls ?

    See MSDN for various controls : https://learn.microsoft.com/en-us/cpp/mfc/controls-mfc?view=msvc-170

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.