home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / metafile / gtmpfnam.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.0 KB  |  65 lines

  1. /*
  2.  *
  3.  * GetTempFileName
  4.  *
  5.  * This program demonstrates the use of the GetTempFileName function
  6.  *  by creating a filename called "temp####" in the directory pointed
  7.  *  to by the TEMP environment varible.  The #### stands for a four
  8.  *  digit number based upon the current system time (Windows generates
  9.  *  this number).  The file is created and then closes the file.
  10.  *
  11.  */
  12.  
  13. #include "windows.h"
  14.  
  15. /* WINMAIN */
  16. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  17. HANDLE hInstance, hPrevInstance;
  18. LPSTR lpszCmdLine;
  19. int cmdShow;
  20. {
  21.    char szTmpFle[80];                  /* Buffer for Temp file name.      */
  22.    char szOutBufr[80];                 /* Output Buffer.                  */
  23.    int iFNumb;                         /* Unique number Windows provides. */
  24.  
  25.    MessageBox(NULL,                    /* Prep the user with a message.   */
  26.               (LPSTR)"About to create Temporary File.",
  27.               (LPSTR)"GetTempFileName Test",
  28.               MB_OK);
  29.  
  30.     /* Get the new Temporary File Name, create, then close the file. */
  31.  
  32.    iFNumb = GetTempFileName((BYTE)'D',
  33.                             (LPSTR)"TMP",
  34.                             (WORD)0,
  35.                             (LPSTR)szTmpFle);
  36.  
  37.     /* Place the unique number (last four characters of filename)    */
  38.     /* into an output buffer for display in a message box.           */
  39.  
  40.    sprintf(szOutBufr,
  41.            "%s%4i\0",
  42.            "The file number is: ",
  43.            iFNumb);
  44.  
  45.     /* Output the unique file number in a message box for clarity.   */
  46.  
  47.    MessageBox(NULL,
  48.               (LPSTR)szOutBufr,
  49.               (LPSTR)"Allocated File Number.",
  50.               MB_OK);
  51.  
  52.     /* Put the complete path and file name into an output buffer.    */
  53.  
  54.    sprintf(szOutBufr, "%s%s%s\0",
  55.            "The temporary filename is ",
  56.            szTmpFle, ".");
  57.  
  58.     /* Output the complete file name in a message box for clarity.   */
  59.  
  60.    MessageBox(NULL, (LPSTR)szOutBufr,
  61.               (LPSTR)"GetTempFileName",
  62.               MB_OK);
  63.  
  64. } /* WinMain */
  65.