Menu

a bit of help with this source (GUI)

2002-08-22
2012-09-26
  • Nobody/Anonymous

    //cmd_id is the ID of A cmd used to edit text inside a non modal dialog box (handled by //NonModal_h)
    //len is the lenght of the text inside the cmd. I've previously cheked that len!=0.
    BOOL PutFileName(int cmd_id, DWORD len)
    {
        char name[256];
        char tmpfilter[40];
        int i = 0;

        for(i=0; i<256; i++)
            name[i]=0;
        i=0;

        OPENFILENAME ofn;

        memset(&ofn,0,sizeof(ofn));
        ofn.lStructSize = sizeof(ofn);
        ofn.hInstance = GetModuleHandle(NULL);
        ofn.hwndOwner = GetActiveWindow();
        ofn.lpstrFile = name;
        ofn.nMaxFile = 256;
        ofn.lpstrTitle = "Save";
        ofn.nFilterIndex = 2;
        ofn.lpstrDefExt = "txt";
        strcpy(name,"*.txt");
        strcpy(tmpfilter,"All files,*.*,Text Files,*.txt");
        while(tmpfilter[i]) {
            if (tmpfilter[i] == ',')
                tmpfilter[i] = 0;
            i++;
        }
        tmpfilter[i++] = 0; tmpfilter[i++] = 0;
        ofn.Flags = 539678;
        ofn.lpstrFilter = tmpfilter;

        BOOL res= GetSaveFileName(&ofn);

        if(res!=0)
            {
            char* buffer;
            buffer = (char*)GlobalAlloc(GPTR, len + 1);

            UINT ta=GetDlgItemText(NonModal_h, cmd_id, buffer, len + 1);

            //modifica il create_always!
            HANDLE file= CreateFile(ofn.lpstrFile, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ,
                NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);

            LPDWORD NumOfBytes;
            /*OVERLAPPED data;
            data.Offset=0;
            data.OffsetHigh=0;
            data.hEvent=NULL;*/
            BOOL err=WriteFile(file, buffer, len+1, NumOfBytes, NULL);
            if(err==0)
                                                                    ErrorBox();

            err=CloseHandle(file);

            HGLOBAL fre=GlobalFree((HGLOBAL)buffer);
            }

    return 0;
    }

    so... ErroBox() is a part of code that returns the messageBox with the extended error string. I've try a lot and finally seems that the error is inside the WriteFile function: "there is a wrong parameter...

    plz help!
    Matteo

     
    • Nobody/Anonymous

      Send your source to bj_4paws@yahoo.com and I'll have look. Give me the lot, not just a sample. With a Windows program life is harder than usual!

      BlakJak :]

       
    • Nobody/Anonymous

      thanx,

      but I've found bug this morning; simply I'm still making a lot of chaos with new types, DWORD and Co.: I'm used to the old turbo c++ and to long, int... what's hell a LPDWROD!?:)

      now no problem:)

      thanx,
      Matteo

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.