Mercurial > dwindows
comparison win/dw.c @ 449:787cc1e27897
Add support for directory browsing under Win32. DW_DIRECTORY_OPEN can be
passed as a flag to dw_file_open() and under Windows a folder select
dialog is displayed. No change for GTK; don't know about OS/2 or MAC.
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 17 Jun 2003 01:45:58 +0000 |
parents | e81af9e60697 |
children | 538b529052e0 |
comparison
equal
deleted
inserted
replaced
448:e81af9e60697 | 449:787cc1e27897 |
---|---|
11 #define WINVER 0x400 | 11 #define WINVER 0x400 |
12 #include <windows.h> | 12 #include <windows.h> |
13 #include <windowsx.h> | 13 #include <windowsx.h> |
14 #include <commctrl.h> | 14 #include <commctrl.h> |
15 #include <shlwapi.h> | 15 #include <shlwapi.h> |
16 #include <shlobj.h> | |
16 #include <stdlib.h> | 17 #include <stdlib.h> |
17 #include <string.h> | 18 #include <string.h> |
18 #include <stdio.h> | 19 #include <stdio.h> |
19 #include <process.h> | 20 #include <process.h> |
20 #include <time.h> | 21 #include <time.h> |
4224 cinfo2->combo = cinfo->combo = tmp; | 4225 cinfo2->combo = cinfo->combo = tmp; |
4225 EnumChildWindows(tmp, _subclass_child, (LPARAM)cinfo2); | 4226 EnumChildWindows(tmp, _subclass_child, (LPARAM)cinfo2); |
4226 | 4227 |
4227 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 4228 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
4228 dw_window_set_font(tmp, DefaultFont); | 4229 dw_window_set_font(tmp, DefaultFont); |
4230 SetWindowText(tmp, text); | |
4229 return tmp; | 4231 return tmp; |
4230 } | 4232 } |
4231 | 4233 |
4232 /* | 4234 /* |
4233 * Create a new button window (widget) to be packed. | 4235 * Create a new button window (widget) to be packed. |
7697 * Opens a file dialog and queries user selection. | 7699 * Opens a file dialog and queries user selection. |
7698 * Parameters: | 7700 * Parameters: |
7699 * title: Title bar text for dialog. | 7701 * title: Title bar text for dialog. |
7700 * defpath: The default path of the open dialog. | 7702 * defpath: The default path of the open dialog. |
7701 * ext: Default file extention. | 7703 * ext: Default file extention. |
7702 * flags: DW_FILE_OPEN or DW_FILE_SAVE. | 7704 * flags: DW_FILE_OPEN or DW_FILE_SAVE or DW_DIRECTORY_OPEN. |
7703 * Returns: | 7705 * Returns: |
7704 * NULL on error. A malloced buffer containing | 7706 * NULL on error. A malloced buffer containing |
7705 * the file path on success. | 7707 * the file path on success. |
7706 * | 7708 * |
7707 */ | 7709 */ |
7709 { | 7711 { |
7710 OPENFILENAME of; | 7712 OPENFILENAME of; |
7711 char filenamebuf[1001] = ""; | 7713 char filenamebuf[1001] = ""; |
7712 int rc; | 7714 int rc; |
7713 | 7715 |
7714 if(ext) | 7716 BROWSEINFO bi; |
7715 { | 7717 TCHAR szDir[MAX_PATH]; |
7716 strcpy(filenamebuf, "*."); | 7718 LPITEMIDLIST pidl; |
7717 strcat(filenamebuf, ext); | 7719 LPMALLOC pMalloc; |
7718 } | 7720 |
7719 | 7721 if(flags==DW_DIRECTORY_OPEN) |
7720 memset(&of, 0, sizeof(OPENFILENAME)); | 7722 { |
7721 | 7723 if (SUCCEEDED(SHGetMalloc(&pMalloc))) |
7722 of.lStructSize = sizeof(OPENFILENAME); | 7724 { |
7723 of.hwndOwner = HWND_DESKTOP; | 7725 ZeroMemory(&bi,sizeof(bi)); |
7724 of.hInstance = DWInstance; | 7726 bi.hwndOwner = NULL; |
7725 of.lpstrInitialDir = defpath; | 7727 bi.pszDisplayName = 0; |
7726 of.lpstrTitle = title; | 7728 bi.pidlRoot = 0; |
7727 of.lpstrFile = filenamebuf; | 7729 bi.lpszTitle = title; |
7728 of.nMaxFile = 1000; | 7730 bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; |
7729 of.lpstrDefExt = ext; | 7731 bi.lpfn = NULL; /*BrowseCallbackProc*/ |
7730 of.Flags = 0; | 7732 |
7731 | 7733 pidl = SHBrowseForFolder(&bi); |
7732 if(flags & DW_FILE_SAVE) | 7734 if (pidl) |
7733 rc = GetSaveFileName(&of); | 7735 { |
7736 if (SHGetPathFromIDList(pidl,szDir)) | |
7737 { | |
7738 strcpy(filenamebuf,szDir); | |
7739 } | |
7740 | |
7741 // In C++: pMalloc->Free(pidl); pMalloc->Release(); | |
7742 pMalloc->lpVtbl->Free(pMalloc,pidl); | |
7743 pMalloc->lpVtbl->Release(pMalloc); | |
7744 return strdup(filenamebuf); | |
7745 } | |
7746 } | |
7747 } | |
7734 else | 7748 else |
7735 rc = GetOpenFileName(&of); | 7749 { |
7736 | 7750 if(ext) |
7737 if(rc) | 7751 { |
7738 return strdup(of.lpstrFile); | 7752 strcpy(filenamebuf, "*."); |
7739 | 7753 strcat(filenamebuf, ext); |
7754 } | |
7755 | |
7756 memset(&of, 0, sizeof(OPENFILENAME)); | |
7757 | |
7758 of.lStructSize = sizeof(OPENFILENAME); | |
7759 of.hwndOwner = HWND_DESKTOP; | |
7760 of.hInstance = DWInstance; | |
7761 of.lpstrInitialDir = defpath; | |
7762 of.lpstrTitle = title; | |
7763 of.lpstrFile = filenamebuf; | |
7764 of.nMaxFile = 1000; | |
7765 of.lpstrDefExt = ext; | |
7766 of.Flags = 0; | |
7767 | |
7768 if(flags & DW_FILE_SAVE) | |
7769 rc = GetSaveFileName(&of); | |
7770 else | |
7771 rc = GetOpenFileName(&of); | |
7772 | |
7773 if(rc) | |
7774 return strdup(of.lpstrFile); | |
7775 } | |
7740 return NULL; | 7776 return NULL; |
7741 } | 7777 } |
7742 | 7778 |
7743 /* | 7779 /* |
7744 * Execute and external program in a seperate session. | 7780 * Execute and external program in a seperate session. |