Condividi tramite


CLinkCtrl::Create

Creates a link control and attaches it to a CLinkCtrl object.

virtual BOOL Create(
   LPCTSTR lpszLinkMarkup, 
   DWORD dwStyle, 
   const RECT& rect, 
   CWnd* pParentWnd, 
   UINT nID
);
virtual BOOL Create(
   DWORD dwStyle,
   const RECT& rect,
   CWnd* pParentWnd,
   UINT nID 
);

Parameters

  • lpszLinkMarkup
    Pointer to a zero-terminated string that contains the marked up text to display. For more information, see the section "Markup and Link Access" in the topic Overview of SysLink Controls in the MSDN Library.

  • dwStyle
    Specifies the link control's style. Apply any combination of control styles. See Common Control Styles in the Windows SDK for more information.

  • rect
    Specifies the link control's size and position. It can be either a CRect object or a RECT structure.

  • pParentWnd
    Specifies the link control's parent window. It must not be NULL.

  • nID
    Specifies the link control's ID.

Return Value

true if initialization was successful; otherwise false.

Remarks

You construct a CLinkCtrl object in two steps. First, call the constructor and then call Create, which creates the link control and attaches it to the CLinkCtrl object. If you want to use extended windows styles with your control, call CLinkCtrl::CreateEx instead of Create.

The second form of the Create method is deprecated. Use the first form that specifies the lpszLinkMarkup parameter.

Example

The following code example defines two variables, named m_Link1 and m_Link2, that are used to access two link controls.

    afx_msg void OnNMClickSyslink1(NMHDR *pNMHDR, LRESULT *pResult);
    afx_msg void OnNMClickSyslink2(NMHDR *pNMHDR, LRESULT *pResult);
    // Link variable associated with resource editor CLinkCtrl control.
    CLinkCtrl m_Link1;
    // Link variable associated with programmatic CLinkCtrl control.
    CLinkCtrl m_Link2;

The following code example creates one link control based on the location of another link control. The resource loader creates the first link control when your application starts. When your application enters the OnInitDialog method, you create the second link control relative to the position of the first link control. Then you resize the second link control to fit the text that it displays.

    CRect rect1, rect2;
    int height = 0;
    SIZE sz = {0};
    PTCHAR url = 
        _T("Link 2)  ")
        _T("<A HREF=\"https://msdn2.microsoft.com/en-us/visualc/default.aspx\">")
        _T("Microsoft VC++ Home")
        _T("</A>");
    m_Link1.GetWindowRect( &rect1 );
    m_Link2.Create(url,
        (WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_BORDER),
        CRect(
        rect1.left, rect1.bottom + rect1.Height(), 
        rect1.right, rect1.bottom + (2*rect1.Height())),
        this,
        IDC_SYSLINK2);
    m_Link2.GetClientRect( &rect2 );
    // The return value of GetIdealSize() is the same as sz.cy
    height = m_Link2.GetIdealSize( 
        rect2.Width(), &sz);
    if ((sz.cx != 0) && (sz.cy != 0)) {
        int rc = m_Link2.SetWindowPos(
            this, 
            0, 0, sz.cx, sz.cy,
            (SWP_NOMOVE | SWP_NOZORDER | SWP_NOREPOSITION | SWP_NOACTIVATE));
    }

Requirements

Header: afxcmn.h

See Also

Reference

CLinkCtrl Class

Hierarchy Chart

CLinkCtrl::CreateEx

Other Resources

CLinkCtrl Members