CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2004
    Posts
    30

    Making buttons & edit/list boxes

    Hello all.
    I have read several tutorials about Windows API but I can't find out how to make simple edit boxes, buttons and list boxes.

    In general I want to do something very similar to this:


    I have seen functions like SetDlgItemText() and GetDlgItem() but in all of this I can't find how to define new edit boxes or buttons.

    Also, I was wondering If it's possible to disabble the "connect" button shown on the .jpg after pressing it once.

    It will be awesome if you will refer me to some tutorials explaining how to make an edit box for example, let the user input text to it and then read this text; make an list box for all the chat messages to be added there and buttons for processing the data.

    Lots of thanks.

  2. #2
    Join Date
    Sep 2002
    Posts
    924
    Check out the following link:
    theForger's Win32 API Tutorial

    As for disabling the Editbox, look at the documentation for EnableWindow (can be used to enable disable windows).

  3. #3
    Join Date
    Aug 2004
    Posts
    30
    Quote Originally Posted by RussG1
    Check out the following link:
    theForger's Win32 API Tutorial

    As for disabling the Editbox, look at the documentation for EnableWindow (can be used to enable disable windows).
    I met this tutorial from before, I saw it but it doesn't explain how to actually make the edit box for example (and also it doesn't work for me as using Dev-c++).

  4. #4
    Join Date
    Sep 2002
    Posts
    924
    hmm, did you check out the section: "App Part 1: Creating controls at runtime" where it shows the following?
    Code:
    hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
                WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 
                0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
    Dev-c++? Not sure what you mean. I use MS Dev 2002 (Visual Studio), and can compile and run examples without probs. Some of the examples create the controls at runtime, and in other examples the controls are added to the dialog in the dialog editor and are included as a resource (at design time).
    Last edited by RussG1; August 23rd, 2004 at 12:09 PM.

  5. #5
    Join Date
    Aug 2004
    Posts
    30
    Thx. I guess that's what I missed.

  6. #6
    Join Date
    Sep 2002
    Posts
    924
    No problem. Make sure you download the source code for the tutorial rather than just trying to figure it out from the code snippets as the snippets do not always show everything. Also, check out the "ctl_one" example as it is similair to what you want to do (uses Editbox, Listbox and Button, etc) accept that the controls are added using dialog editor at desgin time. That combined with the info on creating controls on the fly should give you most of what you need.

  7. #7
    Join Date
    Aug 2004
    Posts
    30
    I need a framework line like shown in with "chat" tag. Is there a function for this ?

  8. #8
    Join Date
    Sep 2002
    Posts
    924
    Quote Originally Posted by aLonBalon
    I need a framework line like shown in with "chat" tag. Is there a function for this ?
    That is a GroupBox control, which is nothing more than a "BUTTON" control with the BS_GROUPBOX, WS_CHILD, and WS_GROUP styles.

    i.e.
    Code:
    CreateWindow("BUTTON", "Text_Displayed", BS_GROUPBOX | WS_CHILD | WS_VISIBLE | WS_GROUP,
                  10, 10, 200, 130, hwnd, NULL, hInst, NULL);

  9. #9
    Join Date
    Aug 2004
    Posts
    30
    Thank you a lot ;\)
    One more little question about resizing window:
    How can I make the window not resizable ?
    I don't want to use Dialogs instead.
    Any way to do so?


    Edit:
    I searched for MSDN but didn't find either list box message to scroll the items down or a style to do so automatically. The problem is about every time I add a new string item the list box doesn't scroll vertically.
    Any solution for this ?


    Thx..
    Last edited by aLonBalon; August 24th, 2004 at 09:51 AM.

  10. #10
    Join Date
    Sep 2002
    Posts
    924

    Re: Making buttons & edit/list boxes

    Whether a window is user sizable or not is controlled by the window styles used when you create the window, etc. It sounds like you do not want a resizing border, and want to disable the maximize box so that the window is not resizable at all (by the user). Use the appriopriate window styles when you create the window and your window will not be user sizable.
    i.e.
    WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX


    As for scrolling the ListBox, you can send the WM_VSCROLL message to the ListBox window to scroll it manually.
    i.e. (scroll ListBox to Bottom)
    Code:
    // where hwnd is HWND of the parent window of the ListBox,
    // and IDC_LIST is the control id of the ListBox
    SendDlgItemMessage(hwnd, IDC_LIST, WM_VSCROLL, (WPARAM)SB_BOTTOM, NULL);
    See the documentation for the WM_VSCROLL message for more info.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured