home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
pcmagazi
/
1992
/
20
/
ln1120
/
cpptest3.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-05
|
6KB
|
227 lines
/*
Title: CPPTEST3.CPP
Caption: This is the BC++ version of the Test3 program.
*/
#include <windows.h>
#include <commdlg.h>
#include <owl.h>
#include <string.h>
#include <listbox.h>
#include <bwcc.h>
_CLASSDEF(TFileDlg)
class TFileDlg : public TDialog {
public:
OPENFILENAME OFN;
char InitialDir[80];
TFileDlg(PTWindowsObject AParent,
long AFlags,
LPSTR AFileName,
int ANameLength,
PTModule Module = NULL);
virtual BOOL Create()
{ return(0); };
virtual int Execute();
virtual void Ok(TMessage& Msg) = [ID_FIRST + IDOK]
{ Msg.Result = !CanClose(); };
virtual void Cancel(TMessage& Msg) = [ID_FIRST + IDCANCEL]
{ Msg.Result = 0; };
};
TFileDlg::TFileDlg( PTWindowsObject AParent,
long AFlags,
LPSTR AFileName,
int ANameLength,
PTModule Module)
: TDialog(AParent, NULL, Module)
{
char TempName[9];
char TempExt[5];
char Drive[3];
_fmemset(&OFN, 0, sizeof(OFN));
OFN.lStructSize = sizeof(OFN);
OFN.hwndOwner = AParent->HWindow;
(void *)OFN.lpfnHook = (void *)GetInstance();
OFN.Flags = AFlags | OFN_ENABLEHOOK;
OFN.hInstance = GetApplication()->hInstance;
OFN.lpstrFileTitle = NULL;
OFN.nMaxFileTitle = 0;
OFN.lpstrInitialDir = InitialDir;
OFN.lpstrFile = AFileName;
OFN.nMaxFile = ANameLength;
OFN.lpstrTitle = "Open File";
_fullpath(OFN.lpstrFile, AFileName, ANameLength);
_splitpath(OFN.lpstrFile, Drive, InitialDir, TempName, TempExt);
strcat(strcpy(OFN.lpstrFile,TempName),TempExt);
SetFlags(WB_ALIAS, True);
};
static BOOL RegisterFails(void *AWindowsObject, void *)
{
return !((PTWindowsObject)AWindowsObject)->Register();
}
extern PTWindowsObject DlgCreationWindow;
int TFileDlg::Execute()
/* Basically, This is the code from TDialog.Execute with the call to
DialogBoxParam changed to GetOpenFileName */
{
long CDError;
int ReturnValue = -1;
PTWindowsObject OldKBHandler;
IsModal = TRUE;
if ( Status == 0 && Register() )
{
DisableAutoCreate();
EnableKBHandler();
if ( GetApplication() )
OldKBHandler = GetApplication()->KBHandlerWnd;
DlgCreationWindow = this;
/* Register all the dialog's child objects (for custom control
support) */
if ( FirstThat(RegisterFails, NULL) == NULL )
{
if (GetOpenFileName(&OFN))
ReturnValue = IDOK;
else
{
CDError = CommDlgExtendedError();
if (!CDError)
ReturnValue = IDCANCEL;
else
{
Status = -CDError;
ReturnValue = Status;
}
}
}
DlgCreationWindow = NULL;
if ( GetApplication() )
GetApplication()->SetKBHandler(OldKBHandler);
}
if ( Status == 0 )
delete this;
else
if (ReturnValue != -1)
ReturnValue = BAD_DIALOG_STATUS; // dialog ran, but status != 0
return ReturnValue;
};
_CLASSDEF(TCDListBox)
class TCDListBox : public TListBox {
public:
HBRUSH Brush;
TCDListBox(PTWindowsObject AParent,
int ResourceID,
PTModule Module = NULL);
virtual ~TCDListBox()
{ DeleteObject(Brush); };
virtual void WMEraseBkgnd(TMessage&) = [WM_FIRST+WM_ERASEBKGND];
virtual void WMDrawItem(TMessage& Msg) = [WM_FIRST+WM_DRAWITEM]
{ DefWndProc(Msg); };
};
TCDListBox::TCDListBox(PTWindowsObject AParent,
int ResourceID,
PTModule Module)
: TListBox(AParent, ResourceID, Module)
{
Brush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ));
SetFlags(WB_ALIAS, True);
};
void TCDListBox::WMEraseBkgnd(TMessage& Msg)
{
RECT R;
GetClientRect(HWindow,&R);
FillRect(Msg.WParam,&R,Brush);
Msg.Result = 1;
};
_CLASSDEF(TBWCCFileDlg)
class TBWCCFileDlg : public TFileDlg {
public:
TBWCCFileDlg(PTWindowsObject AParent,
long AFlags,
LPSTR AFileName,
int ANameLength);
};
TBWCCFileDlg::TBWCCFileDlg(PTWindowsObject AParent,
long AFlags,
LPSTR AFileName,
int ANameLength)
: TFileDlg(AParent, AFlags, AFileName, ANameLength)
{
OFN.Flags |= OFN_ENABLETEMPLATE;
OFN.lpTemplateName = "FileOpen_BWCC";
new TCDListBox(this, 1120);
new TCDListBox(this, 1121);
};
_CLASSDEF(TCommDlgDemoWindow)
class TCommDlgDemoWindow : public TWindow {
public:
TCommDlgDemoWindow(LPSTR ATitle)
: TWindow(NULL, ATitle)
{ AssignMenu("MainMenu"); };
virtual void CMFileOpen(TMessage&) = [CM_FIRST + 101];
};
void TCommDlgDemoWindow::CMFileOpen(TMessage&)
{
char FileName[80];
int Result;
strcpy(FileName, "*.cpp");
Result = GetApplication()->ExecDialog( new TBWCCFileDlg
(this, OFN_FILEMUSTEXIST, FileName, sizeof(FileName)));
if (Result == IDOK)
MessageBox(HWindow, FileName, "You selected", MB_OK);
};
_CLASSDEF(TCommdlgDemoApp)
class TCommDlgDemoApp : public TApplication {
public:
TCommDlgDemoApp( LPSTR AName,
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmd,
int nCmdShow)
: TApplication(AName, hInstance, hPrevInstance,
lpCmd, nCmdShow) {};
virtual void InitMainWindow()
{ MainWindow = new TCommDlgDemoWindow("Test CommDlg"); };
};
/* Run the CommDlgDemoApp */
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmd, int nCmdShow)
{
TCommDlgDemoApp DemoApp("TestCommDlg", hInstance, hPrevInstance, lpCmd, nCmdShow);
DemoApp.Run();
return DemoApp.Status;
}