Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

list box response

I have created a dialog box in the client area of a window.
The dialog box contains a list box of names.
I would like to be able to click on one of the names and when I have
received the index number to the name, bring up a new dialog box in the
client area of the window. I'm new to windows programming and have tried
for two days to figure out how this is done.
Thanks for any help.

Comments

  • chick80chick80 Member Posts: 349
    : I have created a dialog box in the client area of a window.
    : The dialog box contains a list box of names.
    : I would like to be able to click on one of the names and when I have
    : received the index number to the name, bring up a new dialog box in the
    : client area of the window. I'm new to windows programming and have tried
    : for two days to figure out how this is done.
    : Thanks for any help.
    :
    You'll have to check for a LBN_SELCHANGE message in the WNDPROC of your dialog. This message is called when a list box selection has changed.
    You can then find the selected item with:
    [code]
    int sel;
    sel = (int) SendDlgItemMessage(hDlg, IDC_LIST, LB_GETCURSEL, 0, 0);
    [/code]
    Hope this helps...
    nICO

    [hr]
    [italic]How beautiful, if sorrow had not made Sorrow more beautiful than Beauty itself.[/italic]
    JOHN KEATS


  • sramensramen Member Posts: 2
    I appreciate the response. I have now tried again for another 2 days.
    I have a sinking feeling the book I'm using is not up to snuff.
    Windows98 Programming by Herbert Schildt.
    There is no reference to LBN_SELCHANGE messages in the entire book.
    I thought I would post some code to make sure my question is stated
    correctly etc.

    case ID_LB1: /* process a list box LBN_DBLCLK */
    if(HIWORD(wParam)==LBN_DBLCLK)
    {
    i= SendDlgItemMessage(hdwnd, ID_LB1, LB_GETCURSEL, 0, 0);
    /* to get the index */
    sprintf(str, "Index in list is: %d", i);
    response=MessageBox(hdwnd, str, "Selection Made", MB_OK);
    no matter what I try here I can't seem to open a second
    dialog box
    }
    return 1;
    This works fine and indeed gives the correct index to the name in the
    list. However; once the name is selected, I would then like to open a
    second Dialog Box.

    I have included two different function prototypes:
    BOOL CALLBACK DialogFunc(HWND, UINT, WPARAM, LPARAM)
    BOOL CALLBACK DialogFunc2(HWND, UINT, WPARAM, LPARAM)
    and two different functions, this is the second
    BOOL CALLBACK DialogFunc2(HWND hdwnd, UINT message, WPARAM wParam, LPARAM lParam)
    and in WinMain in the message loop

    if(!IsDialogMessage(hDlg, &msg))
    {
    if(!IsDialogMessage(hDlg2, &msg))
    {
    etc.

    Boy! I am really confused
    I'm thinking I may need to purchase a different book.
    Steven Amen

  • chick80chick80 Member Posts: 349
    There's something in the code you posted that is not very clear to me... anyhow I'll show how I would do what you're asking!
    If I understood well you have a dialog with a list box and you need to show a new dialog when the user changes the selection.

    So, first of all, you'll have to create the dialog with the list. You do this in WinMain.

    [code]
    int APIENTRY WinMain(....)
    {
    ...
    DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG), hWnd, (DLGPROC)DlgProc);
    }
    [/code]

    Naturally IDD_DIALOG is the ID of your dialog resource.
    Let's say your dialog has a list box with ID IDC_LIST.
    So, you'll declare DlgProc as follows:

    [code]
    LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
    [/code]

    And implement it like this:
    [code]
    LRESULT CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    switch(uMsg)
    {
    case WM_INITDIALOG:
    // Here you can initialize the list box, using LB_ADDSTRING

    SendDlgItemMessage(hDlg, IDC_LIST, LB_ADDSTRING, 0,(LPARAM)"Param1");
    SendDlgItemMessage(hDlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)"Param2");
    break;

    case LBN_SELCHANGE:
    int i;
    i = SendDlgItemMessage(hDlg, IDC_LIST, LB_GETCURSEL, 0, 0);
    if (i!=-1) // if there's something selected...
    DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOGCHILD + i), hWnd, (DLGPROC) ChildDlgProc);
    break;
    }
    return 0L;
    }
    [/code]

    The first *child* dialog will have ID equal to IDD_DIALOGCHILD, the second will have another ID that is IDD_DIALOGCHILD + 1 and so on...(if you're not writing resources manually, you can edit ID values in "resource.h" file that your editor will create).

    ChildDlgProc will be declared exactly as DlgProc.
    You can use the same procedure for every child dialog, you'll have just to determine what dialog owns the message you're processing in ChildDlgProc. You can do this in many ways, for example looking at the list box selection (but you should retrieve the handle of the dialog that owns the list) or looking at the title of the dialog (if they are different) and so on... just find some way to differentiate the various child dialogs...

    Note that, if you use DialogBox function, the window that owns the dialog won't regain control until the dialog is destroyed.
    To avoid this use CreateDialog (the sintax is exactly the same).

    Hope I was sufficiently clear. Sorry for the English but it's not my language...
    nICO

    [hr]
    [italic]How beautiful, if sorrow had not made Sorrow more beautiful than Beauty itself.[/italic]
    JOHN KEATS


  • Shawn CarterShawn Carter Member Posts: 0

    _________ { http://forcoder.org } free video tutorials and ebooks about || C++ C Scratch Java PHP R Perl Go Visual Basic .NET Delphi PL/SQL Visual Basic Objective-C Ruby MATLAB Python C# JavaScript Assembly Swift Transact-SQL SAS Lisp COBOL Apex Scala F# VBScript Crystal FoxPro ABAP Awk Scheme Clojure Dart Kotlin LabVIEW Bash Lua Fortran Logo D Rust Hack Alice Erlang Ada Prolog Julia ML || ________

Sign In or Register to comment.