SetDlgItemText?

This is a discussion on SetDlgItemText? within the Windows Programming forums, part of the Platform Specific Boards category; Ok. I am making a program. I need to know how to resize a multi-line edit box to fit the ...

  1. #1
    BubbleMan
    Guest

    Question SetDlgItemText?

    Ok. I am making a program. I need to know how to resize a multi-line edit box to fit the program window when it's resized. Also, how would I add text to the edit box? Is it SetDlgItemText?

  2. #2
    Registered User steve_i83's Avatar
    Join Date
    Aug 2001
    Posts
    42
    to set the text in a edit box you use

    BOOL SetDlgItemText(

    HWND hDlg, // handle of dialog box
    int nIDDlgItem, // identifier of control
    LPCTSTR lpString // text to set
    );


    Parameters

    hDlg

    Identifies the dialog box that contains the control.

    nIDDlgItem

    Identifies the control with a title or text that is to be set.

    lpString

    Points to the null-terminated string that contains the text to be copied to the control.

    this info taken from
    Microsoft® Win32® Programmer's Reference
    its very useful ( it has all the WinAPI functions init) , i think i downloaded it from Borland's site, but im not exactly sure ... a search at google will probably do the trick...

    hope this helps
    C Rulz!

  3. #3
    BubbleMan
    Guest

    Post Well, I tried..

    I need to do it only when the user click Insert -> Text. How do I do that. I tried SetDlgItemText(); but it don't work.

  4. #4
    Registered User steve_i83's Avatar
    Join Date
    Aug 2001
    Posts
    42
    post up some code so we can have an idea on what you are trying todo.
    C Rulz!

  5. #5
    Unregistered
    Guest

    Post Ok -> Here it is

    I have:

    case WM_CREATE:
    hMenu = CreateMenu();

    hSubMenu = CreatePopupMenu();
    AppendMenu(hSubMenu, MF_STRING, CM_FILE_NEW, "&New");
    AppendMenu(hMenu, MF_STRING + MF_POPUP, (UINT)hSubMenu, "&File");

    hSubMenu = CreatePopupMenu();
    AppendMenu(hSubMenu, MF_STRING, CM_INSERT_LINK, "&Link");
    AppendMenu(hMenu, MF_STRING + MF_POPUP, (UINT)hSubMenu, "&Insert");

    SetMenu(hwnd, hMenu);
    break;
    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case CM_FILE_NEW:
    HWND html;

    html = CreateWindowEx(
    WS_EX_STATICEDGE | WS_EX_CLIENTEDGE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
    "EDIT",
    "",
    WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_VSCROLL | WS_HSCROLL,
    0, 0,
    540, 330 ,
    hwnd,
    (HMENU) 1,
    hInst,
    NULL
    );
    break;
    case CM_INSERT_LINK:
    SetDlgItemText(html, 0, "<a href=""> </a>");
    break;
    }
    break;

  6. #6
    Registered User steve_i83's Avatar
    Join Date
    Aug 2001
    Posts
    42
    -> SetDlgItemText(html, 0, "<a href=""> </a>");

    this line is wrong ... you need to put inplace of the '0' for parameter two , the name of the edit control ... eg IDC_EDIT1

    the first parameter must be of type hDlg, in other words the handle to your dialog...

    first fix these two things and hopefully it will then work...
    C Rulz!

  7. #7
    BubbleMan
    Guest

    Post The handle

    Ok. Now I used:

    #define IDC_NSRT 1001 at the top.

    And:

    html = CreateWindowEx(
    WS_EX_STATICEDGE | WS_EX_CLIENTEDGE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
    "EDIT",
    "",
    WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_VSCROLL | WS_HSCROLL,
    0, 0,
    540, 330 ,
    hwnd,
    (HMENU) 1,
    hInst,
    NULL
    );
    break;
    case CM_INSERT_LINK:
    SetDlgItemText(html, IDC_NSRT, "<a href=""> </a>");
    break;

    Wouldn't html be the handle? I used HWND html; before it.

  8. #8
    Registered User steve_i83's Avatar
    Join Date
    Aug 2001
    Posts
    42
    case CM_FILE_NEW:
    HWND html;

    html = CreateWindowEx( WS_EX_STATICEDGE | WS_EX_CLIENTEDGE | ES_AUTOHSCROLL ES_AUTOVSCROLL, "EDIT", "", WS_CHILD|WS_VISIBLE|ES_MULTILINE|WS_VSCROLL|WS_HSC ROLL, 0, 0, 540, 330 , hwnd, (HMENU) 1, hInst, NULL );

    break;

    case CM_INSERT_LINK:
    SetDlgItemText(html, 0, "<a href=""> </a>");
    break;
    }
    break;


    the problem is that html might not yet be setup unless the code in CM_FILE_NEW has been run ... try it though ... you might need to use a type cast to get it to work though

    SetDlgItemText((HDLG)html, IDC_NSRT, "<a href=""> </a>");
    C Rulz!

  9. #9
    BubbleMan
    Guest

    Post When I use

    When I use:

    SetDlgItemText((HDLG)html, 0, "<a href=""> </a>");

    I get:

    HDLG undeclared

  10. #10
    Registered User steve_i83's Avatar
    Join Date
    Aug 2001
    Posts
    42
    hehe oops , sorry about that .

    just do
    SetDlgItemText(html, IDC_NSRT, "<a href=""> </a>");
    C Rulz!

  11. #11
    BubbleMan
    Guest

    Unhappy Nothing

    Nothing even happens when I do that.

  12. #12
    Registered User steve_i83's Avatar
    Join Date
    Aug 2001
    Posts
    42
    sorry, i cant be sure whats going on cause i aint got the code ... where is the edit control ?? cause i see you create a new window but no code to make an edit box init...

    i suppose you are making an MDI project where you can open new docs ...
    C Rulz!

  13. #13
    BubbleMan
    Guest

    Post Sort of

    Well, an HTML page maker, actually. You can edit the HTML and save it or if you need shortcuts, that is what my Insert menu is for.

  14. #14
    Registered User steve_i83's Avatar
    Join Date
    Aug 2001
    Posts
    42
    ok so this creates you edit control

    html = CreateWindowEx(
    WS_EX_STATICEDGE | WS_EX_CLIENTEDGE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
    "EDIT",
    "",
    WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_VSCROLL | WS_HSCROLL,
    0, 0,
    540, 330 ,
    hwnd,
    (HMENU) 1,
    hInst,
    NULL
    );

    and it works ? yes ? if it does , i have no idea why the SetDlgItemText dont work ... i leave it upto some one else, sorry..
    C Rulz!

  15. #15
    Registered User steve_i83's Avatar
    Join Date
    Aug 2001
    Posts
    42
    one thought ... the first parameter sound be the hwnd of the window not the control ... use your main windows HWND for first param
    C Rulz!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SetDlgItemText not working
    By viaxd in forum Windows Programming
    Replies: 4
    Last Post: 01-14-2006, 01:55 AM
  2. Dialog doesn't respond to tab key
    By dhaupt in forum Windows Programming
    Replies: 8
    Last Post: 08-11-2004, 12:41 PM
  3. Using the SetDlgItemText function
    By nima_ranjbar in forum Windows Programming
    Replies: 4
    Last Post: 04-25-2002, 02:44 PM
  4. Problem with SetDlgItemText
    By face_master in forum Windows Programming
    Replies: 7
    Last Post: 01-28-2002, 09:24 PM
  5. SetDlgItemText()
    By C_Coder in forum Windows Programming
    Replies: 3
    Last Post: 12-05-2001, 10:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21