Results 1 to 5 of 5

Thread: Help removing a combobox string

  1. #1
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default Help removing a combobox string

    I have a dropdown combo box that scans a directory for all XML files and adds it to the list so I can select it from the drop down. This functionality works great.
    The problem I am running in to is if a user makes any changes to the xml file during run time.


    For example... Adding an xml to the path will automatically update the dropdown and all items, however, if a user deleted an xml file, the dropdown doesn't delete the string from the list autmatically.


    I was able to get it to work "partially", but it only deletes after you try selecting the item. I would like for it to be removed without any selection required.


    Here is my code. Any suggestions please?


    here is the portion I'm working with

    x = SendMessage(GetDlgItem(hWnd, IDC_XML), CB_GETCURSEL, NULL, NULL);

    if(x != CB_ERR)
    {
    SendMessage(GetDlgItem(hWnd, IDC_XML), CB_GETLBTEXT, (WPARAM)x, (LPARAM)strBuffer0);


    sprintf_s(removeNonExistantValue, "c:\\windows\\system32\\sysprep\\%s", strBuffer0);


    if(!file_exist(removeNonExistantValue))
    {
    //MessageBox(0, test, "Test1", MB_OK);
    SendMessage(loadXML, CB_DELETESTRING, NULL, (LPARAM)strBuffer0);
    }

    }



    Here is the full source for that section of code

    #include <string>
    #include <sys/stat.h>


    using namespace std;


    //Disable unnecessary warnings
    #pragma warning(disable: 4244)


    //Global Variables
    int x;
    char strBuffer0[128] = "";


    const char * myFileName;
    char file [MAX_PATH] = {0};
    char removeNonExistantValue[MAX_PATH];


    struct file_data
    {
    std::wstring sLastAccessTime;
    __int64 nFileSize;
    };


    int file_exist (char *filename)
    {
    struct stat buffer;
    return (stat (filename, &buffer) == 0);
    }


    BOOL GetXML(HWND hwMain)
    {
    //const char * myFileName;
    WIN32_FIND_DATA FindFileData;
    HANDLE hFind = INVALID_HANDLE_VALUE;
    DWORD dwError;
    string FilePath = "c:\\windows\\system32\\sysprep\\*.*";
    string FileName;
    hFind = FindFirstFile( FilePath.c_str(), &FindFileData);
    char errorCode[128];
    //char file [MAX_PATH] = {0};


    x = SendMessage(GetDlgItem(hWnd, IDC_XML), CB_GETCURSEL, NULL, NULL);


    if(x != CB_ERR)
    {
    SendMessage(GetDlgItem(hWnd, IDC_XML), CB_GETLBTEXT, (WPARAM)x, (LPARAM)strBuffer0);


    sprintf_s(removeNonExistantValue, "c:\\windows\\system32\\sysprep\\%s", strBuffer0);


    if(!file_exist(removeNonExistantValue))
    {
    //MessageBox(0, test, "Test1", MB_OK);
    SendMessage(loadXML, CB_DELETESTRING, NULL, (LPARAM)strBuffer0);
    }

    }


    while (FindNextFile(hFind, &FindFileData) != 0)
    {
    char * path = "c:\\windows\\system32\\sysprep\\";
    wchar_t buff[128];
    file_data filedata;
    filedata.sLastAccessTime = buff;
    filedata.nFileSize = (((__int64)FindFileData.nFileSizeHigh) << 32) + FindFileData.nFileSizeLow;


    FileName = FindFileData.cFileName;
    myFileName = FileName.c_str();


    //Check if the file is an XML extension
    if((FileName.substr(FileName.find_last_of(".") + 1) == "XML") || (FileName.substr(FileName.find_last_of(".") + 1) == "xml"))
    {
    FileName = FindFileData.cFileName;
    // char file [MAX_PATH] = {0};
    strcpy_s(file,path);
    strcat_s(file,myFileName);

    //MessageBox(0, myFileName, "Info2", MB_OK);
    //"file" includes the whole path and filename. If we will be doing anything with the file, we need that variable.
    //For displaying purposes, we don't need to display the entire path, so lets just display the filename
    if(SendMessage(loadXML, CB_FINDSTRING, (WPARAM)-1, (LPARAM)myFileName) == CB_ERR)
    {
    SendMessage(loadXML, CB_ADDSTRING, NULL, (LPARAM)myFileName);
    }
    }
    }


    dwError = GetLastError();

    FindClose(hFind);

    if(dwError != ERROR_NO_MORE_FILES)
    {
    sprintf_s(errorCode,"ERROR: %s",dwError);
    MessageBox(0, errorCode, "Error", MB_ICONWARNING);
    return FALSE;
    }


    return TRUE;
    }

  2. #2
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Ha, after struggling for a while couldn't figure it out, and shortly after posting here I figured it out.
    Basically here is the end result


    char removeNonExistantValue[MAX_PATH];
    char XMLfile [MAX_PATH] = {0};


    if(SendMessage((GetDlgItem( hWnd, IDC_XML )) , CB_GETLBTEXT, (SendMessage( (GetDlgItem( hWnd, IDC_XML )) , CB_GETITEMDATA , 0, 0 )), (LPARAM)XMLfile ) != CB_ERR)
    {
    sprintf_s(removeNonExistantValue, "c:\\windows\\system32\\sysprep\\%s", XMLfile);


    if(!file_exist(removeNonExistantValue))
    {
    SendMessage(loadXML, CB_DELETESTRING, NULL, (LPARAM)XMLfile);
    }
    }

  3. #3
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    u did dig inside didn't u :wanks:

  4. #4
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    dig inside?

  5. #5
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    oh ,sorry about that , i haven't slept for 24 hours , even when i try to i can't :L

Posting Permissions

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