gimpel@bevsun.bev.lbl.gov (Tom Gimpel) (03/19/90)
Mike Morris sez: >I want the About item to bring up a window which has ... "<application name>" >Version NN.NN, dated MM/DD/YY, at HH:MM" Here's what I did: In AboutDlgProc, which is the proc for the About... box put BOOL FAR PASCAL AboutDlgProc (hDlg, message, wParam, lParam) HWND hDlg; unsigned message; WORD wParam; LONG lParam; { struct stat stFileInfo; struct tm *npstFileTime; char *szAmPm; char *szTemp [81]; switch (message) { case WM_INITDIALOG: stat ("vers.exe", &stFileInfo); npstFileTime = localtime (&stFileInfo.st_atime); if (npstFileTime->tm_hour < 12) szAmPm = "am"; else szAmPm = "pm"; if (npstFileTime->tm_hour > 12) npstFileTime->tm_hour -= 12; if (npstFileTime->tm_hour < 1) npstFileTime->tm_hour = 12; sprintf (szTemp, "%2d/%02d/%02d", npstFileTime->tm_mon + 1, npstFileTime->tm_mday, npstFileTime->tm_year); SetDlgItemText (hDlg, ID_FILEDATE, (LPSTR)szTemp); sprintf (szTemp, "%2d:%02d%2s", npstFileTime->tm_hour, npstFileTime->tm_min, szAmPm); SetDlgItemText (hDlg, ID_FILEDATE, (LPSTR)szTemp); return FALSE; . . . (rest of dialog box code) } } Don't forget to export AboutDlgProc in the .DEF file. (I always do) vers.exe is the name of the program and will have a system date & time of the latest compile. No path is specified here, so stat will look in the current working directory. Experiment to see if there may be a problem with this. Use the name of your program in place here. stat and localtime are standard C library functions. For the declarations of these and the typedefs put these includes at the top of your program #include <stdlib.h> #include <time.h> #include <dos.h> #include <\include\sys\types.h> #include <\include\sys\stat.h> Note the use of the nefarious sprintf function. You may want to do it right and use simpler library functions, the undocumented windows long pointer string functions, or the recommended method of making your own long pointer functions with the assembler. The dialog box template in the .RC file contains ABOUTBOX DIALOG 60, 30, 117, 110 STYLE WS_DLGFRAME | WS_POPUP BEGIN CONTROL "Vers version 1.00", -1, "static", SS_CENTER | WS_CHILD, 15, 11, 80, 8 CONTROL "File date:", -1, "static", SS_CENTER | WS_CHILD, 12, 27, 48, 10 CONTROL "File time:", -1, "static", SS_CENTER | WS_CHILD, 13, 42, 46, 10 CONTROL "", ID_FILEDATE, "static", SS_LEFT | WS_CHILD, 64, 27, 37, 12 CONTROL "", ID_FILETIME, "static", SS_LEFT | WS_CHILD, 64, 42, 37, 12 CONTROL "Ok", ID_OK, "button", BS_DEFPUSHBUTTON | WS_TABSTOP WS_CHILD 39, 67, 41, 23 . . . (rest of template) END Note the two controls identified by ID_FILEDATE and ID_FILETIME. Unlike other controls of the static class, these will need unique identifiers because you will be writing text to them with the SetDlgItemText function. The values assigned to these will be up to you and will be in your program's header file. Hope this helps. Tom Gimpel -- Tom Gimpel gimpel@bevsun.bev.lbl.gov
matts@microsoft.UUCP (Matt SAETTLER) (03/21/90)
In article <5135@helios.ee.lbl.gov> gimpel@bevsun.bev.lbl.gov (Tom Gimpel) writes: > > Mike Morris sez: >>I want the About item to bring up a window which has ... "<application name>" >>Version NN.NN, dated MM/DD/YY, at HH:MM" > >Here's what I did: In AboutDlgProc, which is the proc for the About... box put > >BOOL FAR PASCAL AboutDlgProc (hDlg, message, wParam, lParam) [Some code deleted] > stat ("vers.exe", &stFileInfo); > npstFileTime = localtime (&stFileInfo.st_atime); > if (npstFileTime->tm_hour < 12) > szAmPm = "am"; > else > szAmPm = "pm"; > if (npstFileTime->tm_hour > 12) > npstFileTime->tm_hour -= 12; > if (npstFileTime->tm_hour < 1) > npstFileTime->tm_hour = 12; > sprintf (szTemp, "%2d/%02d/%02d", npstFileTime->tm_mon + 1, > npstFileTime->tm_mday, npstFileTime->tm_year); > SetDlgItemText (hDlg, ID_FILEDATE, (LPSTR)szTemp); > sprintf (szTemp, "%2d:%02d%2s", npstFileTime->tm_hour, > npstFileTime->tm_min, > szAmPm); > SetDlgItemText (hDlg, ID_FILEDATE, (LPSTR)szTemp); ^^^^^^^^ Should be FILETIME Under Microsoft C (5.1), just do: SetDlgItemText (hDlg, ID_FILEDATE, (LPSTR)__DATE__); SetDlgItemText (hDlg, ID_FILETIME, (LPSTR)__TIME__); This will give the time of the compile. This much more useful (and more reliable) than the date of the EXE. This is also not dependent on the finding location of the program. (as Tom said, the code depends on the EXE being in the current directory; not really a good limitation) The __xxx__ are defined by the C compiler. Other useful items are __LINE__ and __FILE__ which give the current source line and file. (useful in doing Asserts ). These are documented somewhere. (I know that they are mentioned on page 31 of the Quick Ref Guide.) [...] >Don't forget to export AboutDlgProc in the .DEF file. (I always do) [...] Ya, me too. A good rule of thumb is if "strange things are happening" then you forgot to export the function. ------------------------------------------------------------------------------ These opinions are my own, or so I'm told....