home *** CD-ROM | disk | FTP | other *** search
- /* ====================================================== */
- /* FILE.C */
- /* Hilfsroutinen für den Dateizugriff und Dialogbox- */
- /* funktionen zum Öffnen und Speichern von Dateien */
- /* (C) 1993 Kay Glahn & DMV-Verlag */
- /* (Teile dieser Routinen wurden aus Beispielen des */
- /* Microsoft Windows SDK-Handbuches übernommen.) */
- /* ====================================================== */
-
- #include <windows.h>
- #include <string.h>
- #include "icocon.h"
-
-
- char DefExt[]=".ico",
- OpenName[128],
- DefPath[128];
-
- BOOL bSaveEnabled = FALSE;
-
- extern char FileName[2][128],
- DefSpec[2][13],
- str[255];
-
- extern OFSTRUCT OfStruct;
-
- extern BOOL change[2];
-
- extern HANDLE hInst;
-
- extern WORD WinOS2[2];
-
- extern int CurrFile;
-
- HANDLE FAR PASCAL OpenDlg(hDlg, message, wParam, lParam)
- HWND hDlg;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
-
- HANDLE hFile=1;
-
- switch (message)
- {
- case WM_COMMAND:
- switch (wParam)
- {
- case IDC_LISTBOX:
- switch (HIWORD(lParam))
- {
- case LBN_SELCHANGE:
- if (DlgDirSelect(hDlg, str, IDC_LISTBOX))
- strcat(str, DefSpec[CurrFile]);
- SetDlgItemText(hDlg, IDC_EDIT, str);
- SendDlgItemMessage(hDlg,
- IDC_EDIT,
- EM_SETSEL,
- NULL,
- MAKELONG(0, 0x7fff));
- break;
- case LBN_DBLCLK:
- goto openfile;
- }
- return (TRUE);
- case IDOK:
- openfile:
- GetDlgItemText(hDlg, IDC_EDIT, OpenName, 128);
-
- if (strchr(OpenName, '*') || strchr(OpenName, '?'))
- {
- SeparateFile(hDlg, (LPSTR) str, (LPSTR) DefSpec[CurrFile],(LPSTR) OpenName);
-
- if (str[0])
- strcpy(DefPath, str);
-
- ChangeDefExt(DefExt, DefSpec[CurrFile]);
- UpdateListBox(hDlg);
- return (TRUE);
- }
-
- if (!OpenName[0])
- {
- MessageBox(hDlg, "No filename specified.", NULL, MB_OK | MB_ICONHAND);
- return (TRUE);
- }
-
- AddExt(OpenName, DefExt);
-
- if ((hFile = OpenFile(OpenName,(LPOFSTRUCT) &OfStruct, OF_READ))<0)
- {
- wsprintf((LPSTR)str,"Fehler %d beim Öffnen von %s.",OfStruct.nErrCode, (LPSTR)OpenName);
- MessageBox(hDlg,str,NULL,MB_OK |MB_ICONHAND);
- }
-
- strcpy(FileName[CurrFile], OpenName);
-
- EndDialog(hDlg, hFile);
- return (TRUE);
- case IDCANCEL:
- EndDialog(hDlg, NULL);
- return (FALSE);
- }
- break;
- case WM_INITDIALOG:
- CenterWnd(hDlg, NULL);
- UpdateListBox(hDlg);
- SetDlgItemText(hDlg, IDC_EDIT, DefSpec[CurrFile]);
-
- SendDlgItemMessage(hDlg,
- IDC_EDIT,
- EM_SETSEL,
- NULL,
- MAKELONG(0, 0x7fff));
-
- SetFocus(GetDlgItem(hDlg, IDC_EDIT));
-
- return (FALSE);
- }
-
- return FALSE;
- }
-
-
- void UpdateListBox(hDlg)
- HWND hDlg;
- {
- strcpy(str, DefPath);
- strcat(str, DefSpec[CurrFile]);
- DlgDirList(hDlg, str, IDC_LISTBOX, IDC_PATH, 0x4010);
-
- if (!strchr (DefPath, ':'))
- DlgDirList(hDlg, DefSpec[CurrFile], IDC_LISTBOX, IDC_PATH, 0x4010);
-
- if (strstr (DefPath, ".."))
- DefPath[0] = '\0';
-
- SetDlgItemText(hDlg, IDC_EDIT, DefSpec[CurrFile]);
- }
-
-
- void ChangeDefExt(Ext, Name)
- PSTR Ext, Name;
- {
-
- PSTR pTptr;
-
- pTptr = Name;
-
- while (*pTptr && *pTptr != '.')
- pTptr++;
-
- if (*pTptr)
- if (!strchr(pTptr, '*') && !strchr(pTptr, '?'))
- strcpy(Ext, pTptr);
- }
-
-
- void SeparateFile(hDlg, lpDestPath, lpDestFileName, lpSrcFileName)
- HWND hDlg;
- LPSTR lpDestPath, lpDestFileName, lpSrcFileName;
- {
-
- LPSTR lpTmp;
- char cTmp;
-
- lpTmp = lpSrcFileName + (long) lstrlen(lpSrcFileName);
-
- while (*lpTmp != ':' && *lpTmp != '\\' && lpTmp > lpSrcFileName)
- lpTmp = AnsiPrev(lpSrcFileName, lpTmp);
-
- if (*lpTmp != ':' && *lpTmp != '\\')
- {
- lstrcpy(lpDestFileName, lpSrcFileName);
- lpDestPath[0] = 0;
- return;
- }
-
- lstrcpy(lpDestFileName, lpTmp + 1);
- cTmp = *(lpTmp + 1);
- lstrcpy(lpDestPath, lpSrcFileName);
- *(lpTmp + 1) = cTmp;
- lpDestPath[(lpTmp - lpSrcFileName) + 1] = 0;
- }
-
-
- void AddExt(Name, Ext)
- PSTR Name, Ext;
- {
-
- PSTR pTptr;
-
- pTptr = Name;
-
- while (*pTptr && *pTptr != '.')
- pTptr++;
-
- if (*pTptr != '.')
- strcat(Name, Ext);
- }
-
-
- int FAR PASCAL SaveAsDlg(hDlg, message, wParam, lParam)
- HWND hDlg;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
-
- char TempName[128];
-
- switch (message)
- {
- case WM_INITDIALOG:
- CenterWnd(hDlg, NULL);
-
- CheckDlgButton(hDlg, (WinOS2[CurrFile]==1)?IDC_RADIO1:IDC_RADIO2, 1);
-
- if (!FileName[CurrFile][0])
- bSaveEnabled = FALSE;
- else
- {
- bSaveEnabled = TRUE;
- DlgDirList(hDlg, DefPath, NULL, IDC_PATH, 0x4010);
- SetDlgItemText(hDlg, IDC_EDIT, FileName[CurrFile]);
- SendDlgItemMessage(hDlg, IDC_EDIT, EM_SETSEL, 0, MAKELONG(0, 0x7fff));
- }
-
- EnableWindow(GetDlgItem(hDlg, IDOK), bSaveEnabled);
-
- SetFocus(GetDlgItem(hDlg, IDC_EDIT));
- return (FALSE);
- case WM_COMMAND:
- switch (wParam)
- {
- case IDC_EDIT:
- if (HIWORD(lParam) == EN_CHANGE && !bSaveEnabled)
- EnableWindow(GetDlgItem(hDlg, IDOK), bSaveEnabled = TRUE);
-
- return (TRUE);
- case IDOK:
- GetDlgItemText(hDlg, IDC_EDIT, TempName, 128);
-
- if (CheckFileName(hDlg, FileName[CurrFile], TempName))
- {
- SeparateFile(hDlg, (LPSTR) str, (LPSTR) DefSpec[CurrFile], (LPSTR) FileName[CurrFile]);
-
- WinOS2[CurrFile]=IsDlgButtonChecked(hDlg, IDC_RADIO1);
-
- if (str[0])
- strcpy(DefPath, str);
-
- EndDialog(hDlg, IDOK);
- }
- return (TRUE);
- case IDCANCEL:
- EndDialog(hDlg, IDCANCEL);
- return (TRUE);
- }
- break;
- }
-
- return (FALSE);
- }
-
-
- BOOL CheckFileName(hWnd, pDest, pSrc)
- HWND hWnd;
- PSTR pDest, pSrc;
- {
-
- PSTR pTmp;
-
- if (!pSrc[0])
- return (FALSE);
-
- pTmp = pSrc;
-
- while (*pTmp)
- {
- switch (*pTmp++)
- {
- case '*':
- case '?':
- MessageBox(hWnd, "Wildcards nicht erlaubt !", NULL, MB_OK | MB_ICONEXCLAMATION);
- return (FALSE);
- }
- }
-
- AddExt(pSrc, DefExt);
-
- if (OpenFile(pSrc, (LPOFSTRUCT) &OfStruct, OF_EXIST) >= 0)
- {
- wsprintf((LPSTR)str, "Bestehende Datei %s ersetzen ?", (LPSTR)pSrc);
-
- if (MessageBox(hWnd, str, "Icon Converter",MB_OKCANCEL | MB_ICONHAND) == IDCANCEL)
- return (FALSE);
- }
-
- strcpy(pDest, pSrc);
- return (TRUE);
- }
-
-
- BOOL QuerySaveFile(hWnd, hXORBmpMem, hANDBmpMem, hPalMem, hResDirMem, Quantity, FileName, change)
- HWND hWnd;
- HANDLE hXORBmpMem;
- HANDLE hANDBmpMem;
- HANDLE hPalMem;
- HANDLE hResDirMem;
- int Quantity;
- LPSTR FileName;
- BOOL FAR * change;
- {
- BOOL Result;
- int Response;
- FARPROC lpSaveAsDlg;
- HANDLE hFile;
-
- if(Quantity>0)
- {
- if (*change)
- {
- wsprintf((LPSTR)str, "─nderungen speichern : %s", FileName);
- Response = MessageBox(hWnd, str,"Icon Converter", MB_YESNOCANCEL | MB_ICONEXCLAMATION);
-
- if (Response == IDYES)
- {
-
- lpSaveAsDlg = MakeProcInstance(SaveAsDlg, hInst);
- Response = DialogBox(hInst, "SaveAs",hWnd, lpSaveAsDlg);
- FreeProcInstance(lpSaveAsDlg);
-
- if (Response != IDOK) return (FALSE);
-
- if ((hFile = OpenFile(FileName,(LPOFSTRUCT) &OfStruct, OF_CREATE)) >= 0)
- {
- if(WinOS2[CurrFile])
- Result=SaveIconFile(&hXORBmpMem,&hANDBmpMem,&hPalMem,&hResDirMem,hFile, hWnd, Quantity);
- else
- Result=SaveIconFile2(&hXORBmpMem,&hANDBmpMem,&hPalMem,&hResDirMem,hFile, hWnd, Quantity);
- _lclose(hFile);
-
- if (Result) *change = FALSE;
- }
- }
- else if (Response == IDCANCEL)
- return (FALSE);
- }
- }
- return (TRUE);
- }
-
- WORD CheckFileType(hFile)
- int hFile;
- {
- WORD ID;
- _llseek(hFile, 0, 0);
- _lread(hFile, (LPSTR)&ID, 2);
- if(ID==0x4142) return(0);
- if(ID==0) return(1);
- return(-1);
- }
-
- /* ====================================================== */
- /* Ende von FILE.C */
-