none
How to change the Caption of SysLink control RRS feed

  • Question

  • I am using LM_SETITEM with LITEM structure to change the caption of syslink control but not able to change the caption of syslink control. Waiting for your valuable suggestions.Thanks
    Wednesday, June 12, 2013 12:51 PM

Answers

  • Ok just figured out how to change the caption. As you know SysLink control can show multiple urls. Here is an example with SetWindowText...

    This will show text like "Nibu Hotmail". Both acting as different links...

    SetWindowTextW(_T("<a href=\"nibu.com\">Nibu</a>    <a href=\"hotmail.com\">hotmail</a>"));

    To set one link call SetWindowText with one URL...

    SetWindowTextW(_T("<a href=\"nibu.com\">Nibu</a>"));

    This will show text like "Nibu".

    This worked for me. Please note that the link indexes will change with this call.


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    • Marked as answer by rmgs123 Friday, June 14, 2013 3:21 PM
    Wednesday, June 12, 2013 4:01 PM
    Moderator

All replies

  • By caption I guess you meant the URL? If that's the case have you set the mask correctly in LITEM structure: LIF_URL? The URL should be passed in via the szUrl member of LITEM struct.

    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    Wednesday, June 12, 2013 12:58 PM
    Moderator
  • Thanks a lot . I need to change the syslink name like szID[MAX_LINKED_TEXT] .I set the name ID but not able to change the SysLink name. 

        for your reference I would like to give the details as follows.

        LITEM *pItem = new LITEM;
        pItem->iLink = 0;     
        pItem->mask = LIF_ITEMINDEX|LIF_STATE;

        pItem->state = LIS_ENABLED|LIS_FOCUSED|LIS_DEFAULTCOLORS|LIS_VISITED;
        pItem->stateMask = LIS_ENABLED|LIS_FOCUSED|LIS_DEFAULTCOLORS|LIS_VISITED;
       strcpy((char*)pItem->szID, "Test");

       SendMessage(GetDlgItem(IDC_MEETING_TIMEZONE), LM_SETITEM, 0, (LPARAM)pItem);

      but I am not able to change the SysLink caption to "Test". 

    Wednesday, June 12, 2013 1:53 PM
  •     pItem->mask = LIF_ITEMINDEX|LIF_STATE;

    -------------------------------------------------------------------------
    MSDN says this for retrieving the id...

    To obtain the item ID you must set both LIF_ITEMINDEX and LIF_ITEMID.
    -------------------------------------------------------------------------

    Does that help? Well that's for obtaining the id I'm not sure if that works for setting as well (you can try), I'm running short on time for testing it out in a sample application.


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    Wednesday, June 12, 2013 2:03 PM
    Moderator
  • Thanks a lot Nibu. I will try it out and let you know.
    Wednesday, June 12, 2013 2:09 PM
  •  I tried as per your suggestion still not able to get it work.

     string myStr("Test");
     CA2W unicodeStr(myStr.c_str());
     LPCWSTR szID = unicodeStr;
     LITEM *item = new LITEM;
     item->mask = LIF_ITEMINDEX | LIF_ITEMID;
     item->iLink = 0;
     item->state = LIS_ENABLED|LIS_FOCUSED|LIS_DEFAULTCOLORS|LIS_VISITED;
     item->stateMask = LIS_ENABLED|LIS_FOCUSED|LIS_DEFAULTCOLORS|LIS_VISITED;
     lstrcpyW(item->szID, szID);

     ::SendMessage(GetDlgItem(IDC_MEETING_TIMEZONE), LM_SETITEM, NULL,          (LPARAM)item);



    • Edited by rmgs123 Wednesday, June 12, 2013 2:24 PM
    Wednesday, June 12, 2013 2:21 PM
  • Setting item id is not going to change the caption of the control. You can verify that the item id is successfully set by calling LM_GETITEM.

    From MSDN on id:

    An ID is an optional name, unique within a SysLink control, and it is associated with an individual link.


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    Wednesday, June 12, 2013 3:02 PM
    Moderator
  • Don't you just use SetWindowText to set the caption on a SysLink control?  LM_GETITEM sets the URL that will be activated when the link is clicked isn't it?
    Wednesday, June 12, 2013 3:27 PM
  • Ok just figured out how to change the caption. As you know SysLink control can show multiple urls. Here is an example with SetWindowText...

    This will show text like "Nibu Hotmail". Both acting as different links...

    SetWindowTextW(_T("<a href=\"nibu.com\">Nibu</a>    <a href=\"hotmail.com\">hotmail</a>"));

    To set one link call SetWindowText with one URL...

    SetWindowTextW(_T("<a href=\"nibu.com\">Nibu</a>"));

    This will show text like "Nibu".

    This worked for me. Please note that the link indexes will change with this call.


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    • Marked as answer by rmgs123 Friday, June 14, 2013 3:21 PM
    Wednesday, June 12, 2013 4:01 PM
    Moderator
  • Thanks a lot . It is working fine nw... that was my exact requirement.

    Have a nice time with you Nibu  :)




    • Edited by rmgs123 Thursday, June 13, 2013 5:37 AM Well answered
    Thursday, June 13, 2013 5:32 AM