Sweden-Number/misc/commdlg.c

1128 lines
33 KiB
C
Raw Normal View History

Release 941030 Sun Oct 30 13:01:18 1994 Alexandre Julliard (julliard@lamisun.epfl.ch) * [controls/static.c] Bug fix for SS_ICON controls. * [if1632/Imakefile] Fixed call.o dependencies. * [objects/clipping.c] [objects/dc.c] Fixed visible region handling. hVisRgn is always non-null now. * [windows/dce.c] Bug fix in GetDCEx for CS_OWNDC windows. * [windows/nonclient.c] [windows/painting.c] Fixes to icon window drawing. * [windows/winpos.c] A few fixes in SetWindowPos(). Sun Oct 30 12:50:24 1994 Michael Patra <micky@marie.physik.tu-berlin.de> * [objects/bitblt.c] BitBlt(): BitBlt is now able to handle any raster operation. If the request can't be passed to XWindows directly, it's quite slow, though. * [*/*.c] [misc/main.c] Improvements of the system for handling debug messages. Options are now also loaded from /usr/lib/X11/app-defaults/Wine (insert *debugoptions: +xxx there if you want to have turn messages xxx on). * [controls/menu.c] DestroyMenu(): The whole window won't be destroyed as a sideeffect any longer. * [misc/file.c] OpenFile(): Fixed bug in searching in system/window-directory. Sun Oct 30 12:25:53 1994 Jimmy Tirtawangsa <j0t2527@tam2000.tamu.edu> * [include/windows.h] Bug fix for window related structures. DCB and COMSTAT are affected. They must be packed. * [misc/comm.c] Bug fix for COM ports: Dial and dialog window in terminal.exe now works. Non sequential COM assignments in wine.conf should not break now. Baudrate can be specified in wine.conf to overcome baudrate limitation in mswindow. See sample wine.ini * [include/comm.h] add baudrate field to DosDeviceStructre * [object/font.c] Bug fix for font assignment. Use pairs of foundry and family fontnames in X11 to correspond with window's fonts. Put font assignment ini wine.ini. * [wine.ini] Adding optional baudrate after port name in "serialports" section Add new section, "fonts". "default" is special key in "fonts" to match any unmatch window font. Oct 29, 94 (new address) wine@trgcorp.mksinfo.qc.ca (Martin Ayotte) * [if1632/relay.c] * [if1632/commdlg.spec] New file. * [misc/commdlg.c] New file. * [include/commdlg.h] New file. Begin of an emulated COMMDLG DLL, built-in for now. (BTW, if you want to switch between built-in & 16bits CommDlg, only thing you need to do is to put the real/dummy name in file relay.c) * [controls/scroll.c] * [controls/combo.c] * [controls/listbox.c] Few bug fixes and/or cosmetic. * [misc/audio.c] * [misc/mmaux.c] bug fixes and flags returned to emulate SB16. * [misc/midi.c] New file. skeleton for 'Midi' MMSYSTEM & MCI driver. * [misc/mcianim.c] New file. skeleton for 'Animation1' MCI driver. * [windows/win.c] Add new stub for GetLastActiveWindow(). Tue Oct 25 09:17:25 1994 Olaf Flebbe (flebbe@tat.physik.uni-tuebingen.de) * [if1632/call.S] [tools/build.c] Support for ELF format. (Not complete) Sun Oct 23 00:51:50 1994 Paul Falstad (pf@zoof) * [if1632/user.spec] Add stubs for ArrangeIconicWindows(), etc. * [if1632/kernel.spec] Add IsBad*Ptr() functions. * [loader/signal.c] Add test_memory(), for use with IsBad*Ptr(). * [windows/winpos.c] Add stubs for TileChildWindows(), etc. * [windows/win.c] IsWindow() shouldn't crash if it's given a bad handle. Add stub for GetLastActivePopup(). * [memory/global.c] Implement the IsBad*Ptr() functions. * [controls/listbox.c] Return the full longword of the item data in LB_GETITEMDATA. * [controls/edit.c] Don't let the user select an area past the end of the text. * [objects/text.c] In DrawText(), the code to delete crlfs also removed multiple consecutive newlines. Also, using DT_CALCRECT didn't return the right height, and the width wasn't returned at all. This caused MessageBoxes to be missing much of their text. * [windows/scroll.c] ScrollWindow[Ex] didn't work right with null LPRECT arguments. Fri Oct 21 21:47:19 1994 Paul Falstad (pf@zoof.cts.com) * [miscemu/int21.c] Fixed int21 0x42 handler to properly assemble 32-bit seek ptr. * [misc/property.c] Fixed inverted logic in EnumProps(), and changed CallBack16() call to use new arg format. * [windows/win.c] Fixed CallBack16() call in Enum[Child]Windows to use new arg format; this fixes crashes in enum procedures. Wed Oct 19 21:30:00 PDT 1994 martin@cs.csufresno.edu * [misc/clipboard.c] [windows/event.c] [windows/message.c] Added cut and paste between Wine and other X clients via the PRIMARY selection. Text only this time. * [controls/edit.c] EDIT_LineLength, EDIT_TextLine return 0 for lines after last one. * [windows/defwnd.c] Send WM_SYSCOMMAND to overlapped ancestor window, not the receiver of WM_SYSKEYDOWN Sat Oct 22 15:01:02 1994 Thomas Sandford <t.d.g.sandford@bradford.ac.uk> * [controls/edit.c] ClientWidth()/ClientHeight() macros: return 0 if size would be negative EDIT_StrLength(): takes unsigned char* instead of char* * [controls/listbox.c] ListBoxWndProc(): in "case WM_MOUSEMOVE" - set lphl at start of case instead of in each place required (it was omitted in some places causing problems!) * [controls/menu.c] MENU_CalcItemSize(): don't try to find size of a text item if the pointer is NULL * [include/heap.h] added definition of HEAP_LocalInit() * [include/msdos.h] removed buggy pointer() macro (use SAFEMAKEPTR() from segmem.h instead) * [loader/selector.c] IPCCopySelector(): added missing flags to shmget() call ? does this break linux - I added these flags in a previous patch but they were missing in the corresponding release ? * [loader/signal.c] win_fault(): added missing definitions of i, dump for those not running NetBSD or linux * [misc/dos_fs.c] DOS_GetCurrentDir(): made temp[] static so it can be safely returned * [miscemu/int21.c,int25.c,int26.c] Changed all invocations of pointer() to SAFEMAKEPTR(). Included segmem.h where necessary. * [windows/dialog.c] CreateDialogIndirectParam(): Changed HEAP_Init() call to HEAP_LocalInit(), removed redundant variables Sat Oct 22 00:29:41 MET 1994 Dag Asheim (dash@ifi.uio.no) * [loader/library.c] [loader/main.c] [loader/ne_image.c] [misc/exec.c] [miscemu/int10.c] [miscemu/int21.c] [objects/bitblt.c] [objects/metafile.c] Rewritten more printf's to use the new debugging system, and made wine less verbose per default. Use "-debugmsg +module" to get (almost) the same behavior as before.
1994-10-30 17:25:19 +01:00
/*
* COMMDLG functions
*
* Copyright 1994 Martin Ayotte
*/
static char Copyright[] = "Copyright Martin Ayotte, 1994";
/*
#define DEBUG_OPENDLG
#define DEBUG_OPENDLG_DRAW
*/
#include "stdio.h"
#include "dialog.h"
#include "win.h"
#include "user.h"
#include "message.h"
#include "heap.h"
#include "commdlg.h"
#include "dlgs.h"
#define OPENFILEDLG2 11
#define SAVEFILEDLG2 12
extern HINSTANCE hSysRes;
static DWORD CommDlgLastError = 0;
static HBITMAP hFolder = 0;
static HBITMAP hFolder2 = 0;
static HBITMAP hFloppy = 0;
static HBITMAP hHDisk = 0;
static HBITMAP hCDRom = 0;
int DOS_GetDefaultDrive(void);
void DOS_SetDefaultDrive(int drive);
char *DOS_GetCurrentDir(int drive);
int DOS_ChangeDir(int drive, char *dirname);
BOOL FileDlg_Init(HWND hWnd, DWORD lParam);
BOOL OpenDlg_ScanFiles(HWND hWnd, WORD nDrive, LPSTR newPath, LPSTR fileSpec);
BOOL OpenDlg_ScanDir(HWND hWnd, WORD nDrive, LPSTR newPath, LPSTR fileSpec);
LPSTR OpenDlg_GetFileType(LPCSTR types, WORD index);
LPSTR OpenDlg_ExtractCurDir(LPSTR FullPath, short MaxLen);
BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
/***********************************************************************
* GetOpenFileName [COMMDLG.1]
*/
BOOL GetOpenFileName(LPOPENFILENAME lpofn)
{
HANDLE hDlgTmpl;
HANDLE hResInfo;
HINSTANCE hInst;
WND *wndPtr;
BOOL bRet;
printf("GetOpenFileName(%08X); !\n", lpofn);
if (lpofn == NULL) return FALSE;
printf("GetOpenFileName // Flags=%08X !\n", lpofn->Flags);
printf("GetOpenFileName // nMaxFile=%d lpstrFile='%s' !\n",
lpofn->nMaxFile, lpofn->lpstrFile);
printf("GetOpenFileName // lpstrInitialDir='%s' !\n", lpofn->lpstrInitialDir);
printf("GetOpenFileName // lpstrFilter=%08X !\n", lpofn->lpstrFilter);
printf("GetOpenFileName // nFilterIndex=%d !\n", lpofn->nFilterIndex);
if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
hDlgTmpl = lpofn->hInstance;
}
else {
if (lpofn->Flags & OFN_ENABLETEMPLATE) {
printf("GetOpenFileName // avant FindResource hInstance=%04X lpTemplateName='%s' !\n",
lpofn->hInstance, lpofn->lpTemplateName);
hInst = lpofn->hInstance;
hResInfo = FindResource(hInst,
(LPSTR)lpofn->lpTemplateName, RT_DIALOG);
}
else {
printf("GetOpenFileName // avant FindResource hSysRes=%04X !\n", hSysRes);
hInst = hSysRes;
hResInfo = FindResource(hInst, MAKEINTRESOURCE(OPENFILEDLG2), RT_DIALOG);
}
if (hResInfo == 0) {
CommDlgLastError = CDERR_FINDRESFAILURE;
return FALSE;
}
printf("GetOpenFileName // apres FindResource hResInfo=%04X!\n", hResInfo);
hDlgTmpl = LoadResource(hInst, hResInfo);
}
if (hDlgTmpl == 0) {
CommDlgLastError = CDERR_LOADRESFAILURE;
return FALSE;
}
printf("GetOpenFileName // apres LoadResource hDlgTmpl=%04X!\n", hDlgTmpl);
wndPtr = WIN_FindWndPtr(lpofn->hwndOwner);
bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
lpofn->hwndOwner, (WNDPROC)FileOpenDlgProc, (DWORD)lpofn);
/* strcpy(lpofn->lpstrFile, "SETUP.TXT"); */
/* strcpy(lpofn->lpstrFileTitle, "SETUP.TXT");*/
/*
lpofn->nFileOffset = 0;
lpofn->nFileExtension = strlen(lpofn->lpstrFile) - 3;
bRet = TRUE;
*/
printf("GetOpenFileName // return lpstrFile='%s' !\n", lpofn->lpstrFile);
return bRet;
}
/***********************************************************************
* GetSaveFileName [COMMDLG.2]
*/
BOOL GetSaveFileName(LPOPENFILENAME lpofn)
{
HANDLE hDlgTmpl;
HANDLE hResInfo;
HINSTANCE hInst;
WND *wndPtr;
BOOL bRet;
printf("GetSaveFileName(%08X); !\n", lpofn);
if (lpofn == NULL) return FALSE;
printf("GetSaveFileName // Flags=%08X !\n", lpofn->Flags);
printf("GetSaveFileName // nMaxFile=%d lpstrFile='%s' !\n",
lpofn->nMaxFile, lpofn->lpstrFile);
printf("GetSaveFileName // lpstrInitialDir='%s' !\n", lpofn->lpstrInitialDir);
printf("GetSaveFileName // lpstrFilter=%08X !\n", lpofn->lpstrFilter);
if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
hDlgTmpl = lpofn->hInstance;
}
else {
if (lpofn->Flags & OFN_ENABLETEMPLATE) {
printf("GetSaveFileName // avant FindResource lpTemplateName='%s' !\n",
lpofn->lpTemplateName);
hInst = lpofn->hInstance;
hResInfo = FindResource(hInst,
(LPSTR)lpofn->lpTemplateName, RT_DIALOG);
}
else {
printf("GetSaveFileName // avant FindResource !\n");
hInst = hSysRes;
hResInfo = FindResource(hInst, MAKEINTRESOURCE(SAVEFILEDLG2), RT_DIALOG);
}
if (hResInfo == 0) {
CommDlgLastError = CDERR_FINDRESFAILURE;
return FALSE;
}
hDlgTmpl = LoadResource(hInst, hResInfo);
}
if (hDlgTmpl == 0) {
CommDlgLastError = CDERR_LOADRESFAILURE;
return FALSE;
}
wndPtr = WIN_FindWndPtr(lpofn->hwndOwner);
bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
lpofn->hwndOwner, (WNDPROC)FileSaveDlgProc, (DWORD)lpofn);
printf("GetSaveFileName // return lpstrFile='%s' !\n", lpofn->lpstrFile);
return bRet;
}
/***********************************************************************
* ChooseColor [COMMDLG.5]
*/
BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
{
HANDLE hDlgTmpl;
HANDLE hResInfo;
WND *wndPtr;
BOOL bRet;
hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(COLORDLG), RT_DIALOG);
hDlgTmpl = LoadResource(hSysRes, hResInfo);
wndPtr = WIN_FindWndPtr(lpChCol->hwndOwner);
bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
lpChCol->hwndOwner, (WNDPROC)ColorDlgProc, (DWORD)lpChCol);
return bRet;
}
/***********************************************************************
* FileOpenDlgProc [COMMDLG.6]
*/
BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
int n;
LPSTR ptr;
LPSTR fspec;
char str[512];
char C2[128];
WORD wRet;
HBRUSH hBrush;
HDC hMemDC;
HBITMAP hBitmap;
BITMAP bm;
WND *wndPtr;
LPMEASUREITEMSTRUCT lpmeasure;
LPDRAWITEMSTRUCT lpdis;
static int nDrive;
static char CurPath[512];
static LPOPENFILENAME lpofn;
switch (wMsg) {
case WM_INITDIALOG:
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
#endif
printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
if (!FileDlg_Init(hWnd, lParam)) return TRUE;
SendDlgItemMessage(hWnd, cmb1, CB_RESETCONTENT, 0, 0L);
lpofn = (LPOPENFILENAME)lParam;
ptr = (LPSTR)lpofn->lpstrFilter;
strcpy(CurPath, lpofn->lpstrInitialDir);
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // lpstrInitialDir='%s' !\n", CurPath);
#endif
while((n = strlen(ptr)) != 0) {
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // file type '%s' !\n", ptr);
#endif
SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (DWORD)ptr);
ptr += ++n;
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // file spec '%s' !\n", ptr);
#endif
n = strlen(ptr);
ptr += ++n;
}
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (DWORD)str);
SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
lpofn->nFilterIndex - 1, 0L);
DlgDirListComboBox(hWnd, "", cmb2, 0, 0xC000);
nDrive = 2; /* Drive 'C:' */
SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, nDrive, 0L);
sprintf(str, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
fspec = OpenDlg_GetFileType(lpofn->lpstrFilter,
lpofn->nFilterIndex);
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // WM_INITDIALOG fspec #%d = '%s' !\n",
lpofn->nFilterIndex, fspec);
#endif
if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
printf("OpenDlg_ScanDir // ChangeDir Error !\n");
}
else {
strcpy(CurPath, str);
}
ShowWindow(hWnd, SW_SHOWNORMAL);
return TRUE;
case WM_SHOWWINDOW:
if (wParam == 0) break;
if (!(lpofn->Flags & OFN_SHOWHELP)) {
ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
}
if (lpofn->Flags & OFN_HIDEREADONLY) {
ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
}
return TRUE;
case WM_MEASUREITEM:
GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
lpmeasure = (LPMEASUREITEMSTRUCT)lParam;
lpmeasure->itemHeight = bm.bmHeight;
#ifdef DEBUG_OPENDLG_DRAW
printf("FileOpenDlgProc WM_MEASUREITEM Height=%d !\n", bm.bmHeight);
#endif
return TRUE;
case WM_DRAWITEM:
#ifdef DEBUG_OPENDLG_DRAW
printf("FileOpenDlgProc // WM_DRAWITEM w=%04X l=%08X\n", wParam, lParam);
#endif
if (lParam == 0L) break;
lpdis = (LPDRAWITEMSTRUCT)lParam;
#ifdef DEBUG_OPENDLG_DRAW
printf("FileOpenDlgProc // WM_DRAWITEM CtlType=%04X CtlID=%04X \n",
lpdis->CtlType, lpdis->CtlID);
#endif
if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst1)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) lpdis->itemData;
if (ptr == NULL) break;
TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
ptr, strlen(ptr));
}
if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst2)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) lpdis->itemData;
if (ptr == NULL) break;
if (strcmp(ptr, "[.]") == 0) {
hBitmap = hFolder2;
/* ptr = OpenDlg_ExtractCurDir(CurPath, -1); */
ptr = CurPath;
}
else
hBitmap = hFolder;
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
lpdis->rcItem.top, ptr, strlen(ptr));
hMemDC = CreateCompatibleDC(lpdis->hDC);
SelectObject(hMemDC, hBitmap);
BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
}
if ((lpdis->CtlType == ODT_COMBOBOX) && (lpdis->CtlID == cmb2)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) lpdis->itemData;
if (ptr == NULL) break;
switch(ptr[2]) {
case 'a':
case 'b':
hBitmap = hFloppy;
break;
default:
hBitmap = hHDisk;
}
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
lpdis->rcItem.top, ptr, strlen(ptr));
hMemDC = CreateCompatibleDC(lpdis->hDC);
SelectObject(hMemDC, hBitmap);
BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
}
if (lpdis->itemState != 0) {
InvertRect(lpdis->hDC, &lpdis->rcItem);
}
break;
case WM_COMMAND:
switch (wParam) {
case lst1:
if (HIWORD(lParam) == LBN_DBLCLK ||
HIWORD(lParam) == LBN_SELCHANGE) {
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // LBN_SELCHANGE on lst1 !\n");
#endif
wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, (DWORD)C2);
}
if (HIWORD(lParam) == LBN_DBLCLK) {
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // LBN_DBLCLK on lst1 !\n");
#endif
return SendMessage(hWnd, WM_COMMAND, IDOK, 0L);
}
break;
case lst2:
if (HIWORD(lParam) == LBN_DBLCLK) {
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // LBN_DBLCLK on lst2 !\n");
#endif
wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
if (wRet == (WORD)LB_ERR) return 0;
fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
C2[0] = '\0';
wRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0L);
if (wRet == (WORD)LB_ERR) return 0;
SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, wRet, (DWORD)C2);
if (C2[0] == '[') {
C2[strlen(C2) - 1] = '\0';
sprintf(str, "%s\\%s", CurPath, &C2[1]);
if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
printf("OpenDlg_ScanDir // ChangeDir Error !\n");
}
else {
strcpy(CurPath, str);
}
}
}
break;
case cmb1:
if (HIWORD(lParam) == CBN_SELCHANGE) {
wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
if (wRet == (WORD)LB_ERR) return 0;
fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
printf("FileOpenDlgProc // new fspec #%d = '%s' !\n", wRet, fspec);
if (!OpenDlg_ScanFiles(hWnd, nDrive, CurPath, fspec)) {
printf("OpenDlg_ScanFiles // Change FileType Error !\n");
}
}
break;
case cmb2:
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // combo #2 changed !\n");
#endif
wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
if (wRet == (WORD)LB_ERR) return 0;
fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
wRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
if (wRet == (WORD)LB_ERR) return 0;
printf("FileOpenDlgProc // combo #2 CB_GETCURSEL=%d !\n", wRet);
SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, wRet, (DWORD)C2);
nDrive = C2[2] - 'a';
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // new drive selected=%d !\n", nDrive);
#endif
sprintf(str, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // new drive , curPath='%s' !\n", str);
#endif
if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
printf("OpenDlg_ScanDir // ChangeDir Error !\n");
}
else {
strcpy(CurPath, str);
}
break;
case chx1:
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // read-only toggled !\n");
#endif
break;
case pshHelp:
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // pshHelp pressed !\n");
#endif
break;
case IDOK:
ShowWindow(hWnd, SW_HIDE);
SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 0, (DWORD)str);
wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, (DWORD)str);
printf("FileOpenDlgProc // IDOK str='%s'\n", str);
strcpy(lpofn->lpstrFile, str);
lpofn->nFileOffset = 0;
lpofn->nFileExtension = strlen(lpofn->lpstrFile) - 3;
if (lpofn->lpstrFileTitle != NULL) {
wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, (DWORD)str);
strcpy(lpofn->lpstrFileTitle, str);
}
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
/*
case WM_CTLCOLOR:
SetBkColor((HDC)wParam, 0x00C0C0C0);
switch (HIWORD(lParam))
{
case CTLCOLOR_BTN:
SetTextColor((HDC)wParam, 0x00000000);
return(hGRAYBrush);
case CTLCOLOR_STATIC:
SetTextColor((HDC)wParam, 0x00000000);
return(hGRAYBrush);
}
return(FALSE);
*/
return FALSE;
}
/***********************************************************************
* FileDlg_Init [internal]
*/
BOOL FileDlg_Init(HWND hWnd, DWORD lParam)
{
LPOPENFILENAME lpofn;
lpofn = (LPOPENFILENAME)lParam;
if (lpofn == NULL) {
fprintf(stderr, "FileDlg_Init // Bad LPOPENFILENAME pointer !");
return FALSE;
}
if (hFolder == (HBITMAP)NULL)
hFolder = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_FOLDER));
if (hFolder2 == (HBITMAP)NULL)
hFolder2 = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_FOLDER2));
if (hFloppy == (HBITMAP)NULL)
hFloppy = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_FLOPPY));
if (hHDisk == (HBITMAP)NULL)
hHDisk = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_HDISK));
if (hCDRom == (HBITMAP)NULL)
hCDRom = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_CDROM));
if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
hHDisk == 0 || hCDRom == 0)
fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
return TRUE;
}
/***********************************************************************
* OpenDlg_ScanFiles [internal]
*/
BOOL OpenDlg_ScanFiles(HWND hWnd, WORD nDrive, LPSTR newPath, LPSTR fileSpec)
{
int OldDrive;
char OldPath[512];
char str[512];
OldDrive = DOS_GetDefaultDrive();
DOS_SetDefaultDrive(nDrive) ;
strcpy(OldPath, DOS_GetCurrentDir(nDrive));
#ifdef DEBUG_OPENDLG
printf("OpenDlg_ScanFiles // OldDrive=%d OldPath='%s'\n", OldDrive, OldPath);
printf("OpenDlg_ScanFiles // wanted newPath='%s'\n", newPath);
#endif
if (newPath[1] == ':')
DOS_ChangeDir(nDrive, &newPath[2]);
else
DOS_ChangeDir(nDrive, newPath);
sprintf(newPath, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
#ifdef DEBUG_OPENDLG
printf("OpenDlg_ScanFiles // actual newPath='%s'\n", newPath);
#endif
if (strlen(newPath) == 3) newPath[2] = '\0';
sprintf(str, "%s\\%s", newPath, fileSpec);
DlgDirList(hWnd, str, lst1, 0, 0x0000);
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (DWORD)str);
DOS_ChangeDir(nDrive, OldPath);
DOS_SetDefaultDrive(OldDrive);
return TRUE;
}
/***********************************************************************
* OpenDlg_ScanDir [internal]
*/
BOOL OpenDlg_ScanDir(HWND hWnd, WORD nDrive, LPSTR newPath, LPSTR fileSpec)
{
int OldDrive;
char OldPath[512];
char str[512];
OldDrive = DOS_GetDefaultDrive();
DOS_SetDefaultDrive(nDrive) ;
strcpy(OldPath, DOS_GetCurrentDir(nDrive));
#ifdef DEBUG_OPENDLG
printf("OpenDlg_ScanDir // OldDrive=%d OldPath='%s'\n", OldDrive, OldPath);
printf("OpenDlg_ScanDir // wanted newPath='%s'\n", newPath);
#endif
if (newPath[1] == ':')
DOS_ChangeDir(nDrive, &newPath[2]);
else
DOS_ChangeDir(nDrive, newPath);
sprintf(newPath, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
#ifdef DEBUG_OPENDLG
printf("OpenDlg_ScanDir // actual newPath='%s'\n", newPath);
#endif
if (strlen(newPath) == 3) newPath[2] = '\0';
sprintf(str, "%s\\%s", newPath, fileSpec);
DlgDirList(hWnd, str, lst1, 0, 0x0000);
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (DWORD)str);
sprintf(str, "%s\\*.*", newPath);
DlgDirList(hWnd, str, lst2, 0, 0x8010);
if (strlen(newPath) == 2) strcat(newPath, "\\");
SendDlgItemMessage(hWnd, stc1, WM_SETTEXT, 0, (DWORD)newPath);
DOS_ChangeDir(nDrive, OldPath);
DOS_SetDefaultDrive(OldDrive);
return TRUE;
}
/***********************************************************************
* OpenDlg_GetFileType [internal]
*/
LPSTR OpenDlg_GetFileType(LPCSTR types, WORD index)
{
int n;
int i = 1;
LPSTR ptr = (LPSTR) types;
if (ptr == NULL) return NULL;
while((n = strlen(ptr)) != 0) {
#ifdef DEBUG_OPENDLG
printf("OpenDlg_GetFileType // file type '%s' !\n", ptr);
#endif
ptr += ++n;
#ifdef DEBUG_OPENDLG
printf("OpenDlg_GetFileType // file spec '%s' !\n", ptr);
#endif
if (i++ == index) return ptr;
n = strlen(ptr);
ptr += ++n;
}
return NULL;
}
/***********************************************************************
* OpenDlg_ExtractCurDir [internal]
*/
LPSTR OpenDlg_ExtractCurDir(LPSTR FullPath, short MaxLen)
{
LPSTR ptr;
if (MaxLen < 0) MaxLen = strlen(FullPath);
ptr = FullPath + MaxLen - 1;
if (*ptr == '\\') return NULL;
while (ptr > FullPath) {
if (*ptr == '\\') return (ptr + 1);
ptr--;
}
return NULL;
}
/***********************************************************************
* FileSaveDlgProc [COMMDLG.7]
*/
BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
int n;
LPSTR ptr;
LPSTR fspec;
char str[512];
char C2[128];
WORD wRet;
HBRUSH hBrush;
HDC hMemDC;
HBITMAP hBitmap;
BITMAP bm;
LPMEASUREITEMSTRUCT lpmeasure;
LPDRAWITEMSTRUCT lpdis;
static int nDrive;
static int OldDrive;
static char OldPath[512];
static char CurPath[512];
static LPOPENFILENAME lpofn;
switch (wMsg) {
case WM_INITDIALOG:
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
#endif
if (!FileDlg_Init(hWnd, lParam)) return TRUE;
SendDlgItemMessage(hWnd, cmb1, CB_RESETCONTENT, 0, 0L);
lpofn = (LPOPENFILENAME)lParam;
ptr = (LPSTR)lpofn->lpstrFilter;
strcpy(CurPath, lpofn->lpstrInitialDir);
while((n = strlen(ptr)) != 0) {
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // file type '%s' !\n", ptr);
#endif
SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (DWORD)ptr);
ptr += ++n;
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // file spec '%s' !\n", ptr);
#endif
n = strlen(ptr);
ptr += ++n;
}
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (DWORD)str);
SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
lpofn->nFilterIndex - 1, 0L);
DlgDirListComboBox(hWnd, "", cmb2, 0, 0xC000);
nDrive = 2; /* Drive 'C:' */
SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, nDrive, 0L);
sprintf(str, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
fspec = OpenDlg_GetFileType(lpofn->lpstrFilter,
lpofn->nFilterIndex);
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // WM_INITDIALOG fspec #%d = '%s' !\n",
lpofn->nFilterIndex, fspec);
#endif
if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
printf("OpenDlg_ScanDir // ChangeDir Error !\n");
}
else {
strcpy(CurPath, str);
}
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_SHOWWINDOW:
if (wParam == 0) break;
if (!(lpofn->Flags & OFN_SHOWHELP)) {
ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
}
if (lpofn->Flags & OFN_HIDEREADONLY) {
ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
}
return TRUE;
case WM_MEASUREITEM:
GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
lpmeasure = (LPMEASUREITEMSTRUCT)lParam;
lpmeasure->itemHeight = bm.bmHeight;
#ifdef DEBUG_OPENDLG_DRAW
printf("FileSaveDlgProc WM_MEASUREITEM Height=%d !\n", bm.bmHeight);
#endif
return TRUE;
case WM_DRAWITEM:
#ifdef DEBUG_OPENDLG_DRAW
printf("FileSaveDlgProc // WM_DRAWITEM w=%04X l=%08X\n", wParam, lParam);
#endif
if (lParam == 0L) break;
lpdis = (LPDRAWITEMSTRUCT)lParam;
#ifdef DEBUG_OPENDLG_DRAW
printf("FileSaveDlgProc // WM_DRAWITEM lpdis->CtlID=%04X\n", lpdis->CtlID);
#endif
if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst1)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) lpdis->itemData;
if (ptr == NULL) break;
TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
ptr, strlen(ptr));
}
if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst2)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) lpdis->itemData;
if (ptr == NULL) break;
if (strcmp(ptr, "[.]") == 0) {
hBitmap = hFolder2;
ptr = CurPath;
}
else
hBitmap = hFolder;
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
lpdis->rcItem.top, ptr, strlen(ptr));
hMemDC = CreateCompatibleDC(lpdis->hDC);
SelectObject(hMemDC, hBitmap);
BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
}
if ((lpdis->CtlType == ODT_COMBOBOX) && (lpdis->CtlID == cmb2)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) lpdis->itemData;
if (ptr == NULL) break;
switch(ptr[2]) {
case 'a':
case 'b':
hBitmap = hFloppy;
break;
default:
hBitmap = hHDisk;
}
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
lpdis->rcItem.top, ptr, strlen(ptr));
hMemDC = CreateCompatibleDC(lpdis->hDC);
SelectObject(hMemDC, hBitmap);
BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
}
break;
case WM_COMMAND:
switch (wParam) {
case lst1:
if (HIWORD(lParam) == LBN_DBLCLK ||
HIWORD(lParam) == LBN_SELCHANGE) {
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // LBN_SELCHANGE on lst1 !\n");
#endif
wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, (DWORD)C2);
}
if (HIWORD(lParam) == LBN_DBLCLK) {
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // LBN_DBLCLK on lst1 !\n");
#endif
return SendMessage(hWnd, WM_COMMAND, IDOK, 0L);
}
break;
case lst2:
if (HIWORD(lParam) == LBN_DBLCLK) {
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // LBN_DBLCLK on lst2 !\n");
#endif
wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
C2[0] = '\0';
wRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, wRet, (DWORD)C2);
if (C2[0] == '[') {
C2[strlen(C2) - 1] = '\0';
sprintf(str, "%s\\%s", CurPath, &C2[1]);
if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
printf("FileSaveDlgProc // ChangeDir Error !\n");
}
else {
strcpy(CurPath, str);
}
}
}
break;
case cmb1:
if (HIWORD(lParam) == CBN_SELCHANGE) {
wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
printf("FileSaveDlgProc // new fspec #%d = '%s' !\n", wRet, fspec);
if (!OpenDlg_ScanFiles(hWnd, nDrive, CurPath, fspec)) {
printf("OpenDlg_ScanFile // Change FileType Error !\n");
}
}
break;
case cmb2:
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // combo #2 changed !\n");
#endif
wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
if (wRet == (WORD)LB_ERR) return 0;
fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
wRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
if (wRet == (WORD)LB_ERR) return 0;
printf("FileSaveDlgProc // combo #2 CB_GETCURSEL=%d !\n", wRet);
SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, wRet, (DWORD)C2);
nDrive = C2[2] - 'a';
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // new drive selected=%d !\n", nDrive);
#endif
sprintf(str, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // new drive , curPath='%s' !\n", str);
#endif
if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
printf("FileSaveDlgProc // Change Drive Error !\n");
}
else {
strcpy(CurPath, str);
}
break;
case chx1:
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // read-only toggled !\n");
#endif
break;
case pshHelp:
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // pshHelp pressed !\n");
#endif
break;
case IDOK:
strcpy(lpofn->lpstrFile, "titi.txt");
if (lpofn->lpstrFileTitle != NULL) {
strcpy(lpofn->lpstrFileTitle, "titi.txt");
}
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* ColorDlgProc [COMMDLG.8]
*/
BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
printf("ColorDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_COMMAND:
switch (wParam) {
case IDOK:
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* FindTextDlg [COMMDLG.11]
*/
BOOL FindText(LPFINDREPLACE lpFind)
{
HANDLE hDlgTmpl;
HANDLE hResInfo;
WND *wndPtr;
BOOL bRet;
hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(FINDDLG), RT_DIALOG);
if (hResInfo == 0) {
CommDlgLastError = CDERR_FINDRESFAILURE;
return FALSE;
}
hDlgTmpl = LoadResource(hSysRes, hResInfo);
if (hDlgTmpl == 0) {
CommDlgLastError = CDERR_LOADRESFAILURE;
return FALSE;
}
wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
lpFind->hwndOwner, (WNDPROC)FindTextDlgProc, (DWORD)lpFind);
return bRet;
}
/***********************************************************************
* ReplaceTextDlg [COMMDLG.12]
*/
BOOL ReplaceText(LPFINDREPLACE lpFind)
{
HANDLE hDlgTmpl;
HANDLE hResInfo;
WND *wndPtr;
BOOL bRet;
hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(REPLACEDLG), RT_DIALOG);
if (hResInfo == 0) {
CommDlgLastError = CDERR_FINDRESFAILURE;
return FALSE;
}
hDlgTmpl = LoadResource(hSysRes, hResInfo);
if (hDlgTmpl == 0) {
CommDlgLastError = CDERR_LOADRESFAILURE;
return FALSE;
}
wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
lpFind->hwndOwner, (WNDPROC)ReplaceTextDlgProc, (DWORD)lpFind);
return bRet;
}
/***********************************************************************
* FindTextDlgProc [COMMDLG.13]
*/
BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
printf("FindTextDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_COMMAND:
switch (wParam) {
case IDOK:
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* ReplaceTextDlgProc [COMMDLG.14]
*/
BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_COMMAND:
switch (wParam) {
case IDOK:
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* PrintDlg [COMMDLG.20]
*/
BOOL PrintDlg(LPPRINTDLG lpPrint)
{
HANDLE hDlgTmpl;
HANDLE hResInfo;
WND *wndPtr;
BOOL bRet;
printf("PrintDlg(%08X) // Flags=%08X\n", lpPrint->Flags);
if (lpPrint->Flags & PD_PRINTSETUP)
hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(PRINTSETUPDLG), RT_DIALOG);
else
hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(PRINTDLG), RT_DIALOG);
if (hResInfo == 0) {
CommDlgLastError = CDERR_FINDRESFAILURE;
return FALSE;
}
hDlgTmpl = LoadResource(hSysRes, hResInfo);
if (hDlgTmpl == 0) {
CommDlgLastError = CDERR_LOADRESFAILURE;
return FALSE;
}
wndPtr = WIN_FindWndPtr(lpPrint->hwndOwner);
if (lpPrint->Flags & PD_PRINTSETUP)
bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
lpPrint->hwndOwner, (WNDPROC)PrintSetupDlgProc, (DWORD)lpPrint);
else
bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
lpPrint->hwndOwner, (WNDPROC)PrintDlgProc, (DWORD)lpPrint);
return bRet;
}
/***********************************************************************
* PrintDlgProc [COMMDLG.21]
*/
BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
printf("PrintDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_COMMAND:
switch (wParam) {
case IDOK:
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* PrintSetupDlgProc [COMMDLG.22]
*/
BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_COMMAND:
switch (wParam) {
case IDOK:
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* CommDlgExtendError [COMMDLG.26]
*/
DWORD CommDlgExtendError(void)
{
return CommDlgLastError;
}
/***********************************************************************
* GetFileTitle [COMMDLG.27]
*/
int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
{
int i, len;
printf("GetFileTitle(%08X %08X %d); \n", lpFile, lpTitle, cbBuf);
if (lpFile == NULL || lpTitle == NULL) return -1;
len = strlen(lpFile);
if (len == 0) return -1;
if (strchr(lpFile, '*') != NULL) return -1;
if (strchr(lpFile, '[') != NULL) return -1;
if (strchr(lpFile, ']') != NULL) return -1;
len--;
if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':') return -1;
for (i = len; i >= 0; i--) {
if (lpFile[i] == '/' ||
lpFile[i] == '\\' ||
lpFile[i] == ':') {
i++;
break;
}
}
printf("\n---> '%s' ", &lpFile[i]);
len = min(cbBuf, strlen(&lpFile[i]) + 1);
strncpy(lpTitle, &lpFile[i], len + 1);
if (len != cbBuf)
return len;
else
return 0;
}