save and save as functions

This is a discussion on save and save as functions within the Windows Programming forums, part of the Platform Specific Boards category; hey, how do i have a save & save as function? or basically, how do i have the 'save' function ...

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    save and save as functions

    hey, how do i have a save & save as function? or basically, how do i have the 'save' function bypass the user choosing the filename? like, i want to check if the current open document has a filename (which i can do) and if it does, then i want the save button to simply save. if not, then it brings up the window to choose which a filename. i can make it bring up the filename prompt, but bypassing that i have not yet accomplished. thanks in advance
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,266
    What people usually do is store the current filename (if there is one) in a global, say:-
    char g_szFilename[MAX_PATH] = '\0';

    Then, in your window procedure's switch mess (or is that just me? ), position your Save and Save As iterations like so:-
    case ID_SAVE:
    case ID_SAVE_AS:

    and then inside the switch, test if either the current case is ID_SAVE_AS or if g_szFilename is empty:-
    if (LOWORD(lParam) == ID_SAVE_AS || !lstrlen(g_szFilename))

    and get the Save As dialog inside that condition. Put your usual save code after it, and voilá.

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    well in my program i have it display the filename in the title bar in the child windows, so in my FileOpenSave function (where it determines whether i want to open a file or save a file), i have it check if the name of the current child window == "[Untitled]" because thats what the titlebar says if its a new file. then, if thats the case then it accesses GetSaveFileName() and then goes on and saves the file. else if the titlebar says something different, i get the current working directory (because for the display of the filename in the titlebar, i remove the directory so instead of it say "C:\programs\filename.sby" it just says "filename.sby" b/c it bugged me ), and then after i get the current working directory i make the full filename. cpy the current working directory, a backslash, and the filename to a temp string and then copy the temp string to the one which will be sent to the SaveFile function. and it works.

    thanks tho
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-17-2008, 01:00 PM
  2. Save vs Save As.... OPENFILENAME flags
    By csonx_p in forum Windows Programming
    Replies: 16
    Last Post: 06-01-2008, 03:42 PM
  3. save webpage? some save some not
    By kryptkat in forum Tech Board
    Replies: 3
    Last Post: 06-07-2005, 10:21 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

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