Using a button to clear a list box!

This is a discussion on Using a button to clear a list box! within the C++ Programming forums, part of the General Programming Boards category; Hi, Hope someone can help me, ive read all the faqs about the clear function. Ive gone with the windows ...

  1. #1
    Unregistered
    Guest

    Angry Using a button to clear a list box!

    Hi,

    Hope someone can help me, ive read all the faqs about the clear function. Ive gone with the windows option;

    #include <windows.h>



    void clrscr()

    {

    COORD coordScreen = { 0, 0 };

    DWORD cCharsWritten;

    CONSOLE_SCREEN_BUFFER_INFO csbi;

    DWORD dwConSize;

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);



    GetConsoleScreenBufferInfo(hConsole, &csbi);

    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

    FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);

    GetConsoleScreenBufferInfo(hConsole, &csbi);

    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);

    SetConsoleCursorPosition(hConsole, coordScreen);

    }

    ive placed this at the top of my prog.
    Next i want to have a "clear" button (IDC_CLEAR), which ive made, to clear a list box, called IDC_EVENTLOG.

    Heres the code so far, just not sure how to link the pressing of the button to the clear function.


    else if (LOWORD(wParam) == IDC_CLEAR)
    {
    if(MessageBoxW(hDlg, L"Are you sure you want to Clear the Event Log ?", L"Warning", MB_YESNO) == IDYES)
    {
    if(gStarted == TRUE)
    {

    //Call clear function here
    gStarted = FALSE; clrscr(IDC_EVENTLOG); //HELP!!? NOT SURE????
    //exit(0);
    }
    //SetEvent(ghExit);
    //EndDialog(hDlg, LOWORD(wParam));
    }

    //return TRUE;
    }


    Sorry if this is an obvious question, but im fairly new at this!

    Many Thanks for ANY help,



    p

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Just send a LB_RESETCONTENT message to the listbox to clear it.

    This is from MSDN :

    An application sends an LB_RESETCONTENT to remove all items from a list box.

    LB_RESETCONTENT
    wParam = 0; // not used; must be zero
    lParam = 0; // not used; must be zero

    Parameters
    This message has no parameters.

    Return Values
    This message does not return a value.

  3. #3
    Unregistered
    Guest
    so how do i actually use that?

    Not too sure. :-(

    thanks again

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    LONG SendDlgItemMessage(
    HWND hDlg, // handle of dialog box
    int nIDDlgItem, // identifier of control
    UINT Msg, // message to send
    WPARAM wParam, // first message parameter
    LPARAM lParam // second message parameter
    );

    So you'd have to do something like this,
    Code:
    SendDlgItemMessage(hDlg,ID_LISTBOX,LB_RESETCONTENT,0,0);
    Remember that hDlg is the parent window, and ID_LISTBOX is the id of the listbox.

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    What is this drool? Just use C# and the BCL. Even VB would be better.

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Originally posted by Troll_King
    What is this drool? Just use C# and the BCL. Even VB would be better.
    stop it

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Dean, the only panties you steal are your mom's.

  8. #8
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Last edited by Troll_King; 08-22-2002 at 12:01 PM.

  9. #9
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Originally posted by golfinguy4
    Dean, the only panties you steal are your mom's.
    I already got his mom's panties

  10. #10
    Shadow12345
    Guest
    *drool*

  11. #11
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    are you drooling over TK's mom's panties? shame on you!

  12. #12
    Unregistered
    Guest
    Hi,

    Managed to get it to work using the following code,


    else if (LOWORD(wParam) == IDC_CLEAR)
    {
    if(MessageBoxW(hDlg, L"Are you sure you want to Clear the Event Log ?", L"Warning", MB_YESNO) == IDYES)
    {
    if(gStarted == TRUE)
    {

    //Send message to remove contents of list box
    gStarted = FALSE;
    SendDlgItemMessage (hDlg, IDC_EVENTLOG, LB_RESETCONTENT, 0, 0);
    }

    }
    return TRUE;

    }

    However once running it will clear the list box, but when i try to clear it again by pressing the button (IDC_CLEAR) it manages to prompts the message "are you sure" again but doesnt clear the list box again when yes is selected!??

    Please help as this is really bugging me,

    Sorry for interupting the pantie conversation ;-)


    cheers,

  13. #13
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    >> However once running it will clear the list box, but when i try to clear it again by pressing the button (IDC_CLEAR) it manages to prompts the message "are you sure" again but doesnt clear the list box again when yes is selected!??

    Well, is gStarted true or false?

  14. #14
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    what is the gStarted variable for?

    Code:
    else if (LOWORD(wParam) == IDC_CLEAR) 
    {
        if(MessageBoxW(hDlg, L"Are you sure you want to Clear the Event Log ?", L"Warning", MB_YESNO) == IDYES)
        {
            //Send message to remove contents of list box
            SendDlgItemMessage (hDlg, IDC_EVENTLOG, LB_RESETCONTENT, 0, 0);
        }
        return TRUE; // what is this for?
    }
    "There are three kinds of people in the world...
    Those that can count and those that can't."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 02:29 AM
  3. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  4. 1st Class LIST ADT
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-09-2001, 07:29 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

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