Mercurial > dwindows
comparison win/dw.c @ 1765:15414cbe857f
Fix warnings with Visual C largely in debug mode.
Switched to using _sntprintf() and pointer arithmetic in dw_file_browse().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 30 Jun 2012 19:53:18 +0000 |
parents | d894f87387b2 |
children | 47e503ecc812 |
comparison
equal
deleted
inserted
replaced
1764:5ffeea4a2a4b | 1765:15414cbe857f |
---|---|
11714 x++; | 11714 x++; |
11715 } | 11715 } |
11716 dst[x] = 0; | 11716 dst[x] = 0; |
11717 } | 11717 } |
11718 | 11718 |
11719 #define BROWSEBUFSIZE 1000 | |
11720 | |
11719 /* | 11721 /* |
11720 * Opens a file dialog and queries user selection. | 11722 * Opens a file dialog and queries user selection. |
11721 * Parameters: | 11723 * Parameters: |
11722 * title: Title bar text for dialog. | 11724 * title: Title bar text for dialog. |
11723 * defpath: The default path of the open dialog. | 11725 * defpath: The default path of the open dialog. |
11729 * | 11731 * |
11730 */ | 11732 */ |
11731 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) | 11733 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) |
11732 { | 11734 { |
11733 OPENFILENAME of = {0}; | 11735 OPENFILENAME of = {0}; |
11734 TCHAR filenamebuf[1001] = {0}, *fbuf = filenamebuf; | 11736 TCHAR filenamebuf[BROWSEBUFSIZE+1] = {0}, *fbuf = filenamebuf; |
11735 TCHAR filterbuf[1001] = {0}; | 11737 TCHAR filterbuf[BROWSEBUFSIZE+1] = {0}; |
11736 TCHAR *exten = UTF8toWide(ext); | 11738 TCHAR *exten = UTF8toWide(ext); |
11737 TCHAR *dpath = UTF8toWide(defpath); | 11739 TCHAR *dpath = UTF8toWide(defpath); |
11738 int rc; | 11740 int rc; |
11739 | 11741 |
11740 if ( flags == DW_DIRECTORY_OPEN ) | 11742 if ( flags == DW_DIRECTORY_OPEN ) |
11758 pidl = SHBrowseForFolder(&bi); | 11760 pidl = SHBrowseForFolder(&bi); |
11759 if (pidl) | 11761 if (pidl) |
11760 { | 11762 { |
11761 if (SHGetPathFromIDList(pidl,szDir)) | 11763 if (SHGetPathFromIDList(pidl,szDir)) |
11762 { | 11764 { |
11763 _tcsncpy(filenamebuf,szDir,1000); | 11765 _tcsncpy(filenamebuf,szDir,BROWSEBUFSIZE); |
11764 } | 11766 } |
11765 | 11767 |
11766 /* In C++: pMalloc->Free(pidl); pMalloc->Release(); */ | 11768 /* In C++: pMalloc->Free(pidl); pMalloc->Release(); */ |
11767 pMalloc->lpVtbl->Free(pMalloc,pidl); | 11769 pMalloc->lpVtbl->Free(pMalloc,pidl); |
11768 pMalloc->lpVtbl->Release(pMalloc); | 11770 pMalloc->lpVtbl->Release(pMalloc); |
11773 if ( XBrowseForFolder( NULL, | 11775 if ( XBrowseForFolder( NULL, |
11774 (LPCTSTR)dpath, | 11776 (LPCTSTR)dpath, |
11775 -1, | 11777 -1, |
11776 (LPCTSTR)UTF8toWide(title), | 11778 (LPCTSTR)UTF8toWide(title), |
11777 (LPTSTR)filenamebuf, | 11779 (LPTSTR)filenamebuf, |
11778 1000, | 11780 BROWSEBUFSIZE, |
11779 FALSE ) ) | 11781 FALSE ) ) |
11780 { | 11782 { |
11781 return _strdup( WideToUTF8(fbuf) ); | 11783 return _strdup( WideToUTF8(fbuf) ); |
11782 } | 11784 } |
11783 #endif | 11785 #endif |
11792 * The following mess is because sprintf() trunates at first \0 | 11794 * The following mess is because sprintf() trunates at first \0 |
11793 * and format of filter is eg: "c files (*.c)\0*.c\0All Files\0*.*\0\0" | 11795 * and format of filter is eg: "c files (*.c)\0*.c\0All Files\0*.*\0\0" |
11794 */ | 11796 */ |
11795 int len; | 11797 int len; |
11796 TCHAR *ptr = filterbuf; | 11798 TCHAR *ptr = filterbuf; |
11797 len = _stprintf( ptr, TEXT("%s Files (*.%s)"), exten, exten ); | 11799 TCHAR *start = filterbuf; |
11800 | |
11801 len = _sntprintf( ptr, BROWSEBUFSIZE - (ptr - start), TEXT("%s Files (*.%s)"), exten, exten ); | |
11798 ptr = ptr + len + 1; /* past first \0 */ | 11802 ptr = ptr + len + 1; /* past first \0 */ |
11799 len = _stprintf( ptr, TEXT("*.%s"), exten ); | 11803 len = _sntprintf( ptr, BROWSEBUFSIZE - (ptr - start), TEXT("*.%s"), exten ); |
11800 ptr = ptr + len + 1; /* past next \0 */ | 11804 ptr = ptr + len + 1; /* past next \0 */ |
11801 len = _stprintf( ptr, TEXT("All Files") ); | 11805 len = _sntprintf( ptr, BROWSEBUFSIZE - (ptr - start), TEXT("All Files") ); |
11802 ptr = ptr + len + 1; /* past next \0 */ | 11806 ptr = ptr + len + 1; /* past next \0 */ |
11803 len = _stprintf( ptr, TEXT("*.*") ); | 11807 len = _sntprintf( ptr, BROWSEBUFSIZE - (ptr - start), TEXT("*.*") ); |
11804 } | 11808 } |
11805 | 11809 |
11806 memset( &of, 0, sizeof(OPENFILENAME) ); | 11810 memset( &of, 0, sizeof(OPENFILENAME) ); |
11807 | 11811 |
11808 of.lStructSize = sizeof(OPENFILENAME); | 11812 of.lStructSize = sizeof(OPENFILENAME); |
11815 else if(defpath) | 11819 else if(defpath) |
11816 _to_dos(filenamebuf, dpath); | 11820 _to_dos(filenamebuf, dpath); |
11817 of.lpstrFile = filenamebuf; | 11821 of.lpstrFile = filenamebuf; |
11818 of.lpstrFilter = filterbuf; | 11822 of.lpstrFilter = filterbuf; |
11819 of.nFilterIndex = 1; | 11823 of.nFilterIndex = 1; |
11820 of.nMaxFile = 1000; | 11824 of.nMaxFile = BROWSEBUFSIZE; |
11821 /*of.lpstrDefExt = ext;*/ | 11825 /*of.lpstrDefExt = ext;*/ |
11822 of.Flags = OFN_NOCHANGEDIR; | 11826 of.Flags = OFN_NOCHANGEDIR; |
11823 | 11827 |
11824 if (flags & DW_FILE_SAVE) | 11828 if (flags & DW_FILE_SAVE) |
11825 { | 11829 { |