home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windoware
/
WINDOWARE_1_6.iso
/
source
/
cppwin10
/
readme.doc
< prev
next >
Wrap
Text File
|
1991-01-11
|
17KB
|
468 lines
Windows/Zortech C++ Classes Version 1.0 01/11/91
Comptech Software Inc.
Keith Murray
16013 Saddlestring Dr.
Tampa, FL 33618
Compuserve 71601,3673
(813)962-3908
This document and all software included with it are Copyright (c) 1991
Comptech Software Inc. All rights are reserved. This software is not in
the public domain. It is released through an brilliant system known and
shareware. It allows you the customer to try a product before you buy
it. It also helps keep the publishers costs down by allowing a cheaper
method for distribution. The publisher can then pass these savings on to
you by supplying a superior product and a reasonable price. If you find
this product useful and continue using it, please send $35. For this you
will receive full source code. This shareware product is full featured.
The libraries supplied are compiled for small model Zortech C++ v2.1.
They were compiled with the following options:
ztc -a -g -c -br -ms -W -DMSW -DLINTARGS
The following is a list of files included:
README.DOC This file
WINS.LIB The library of classes
CBUFFER.HPP CBuffer class header file
CWIND.HPP CWind class header file
CDLG.HPP CDlg class header file
CDLGABT.HPP CDlgAbout class header file
CSELPRN.HPP CSelPrnterDlg class header file
CAPPL.HPP CAppl class header file
COPENDLG.HPP COpenDlg class header file
COPENDLG.H COpenDlg dialog #defines
CSELPRN.H CSelPrnterDlg dialog #defines
MENUDEF.H Menu #defines for example program
COPENDLG.DLG COpenDlg dialog template
CSELPRN.DLG CSelPrnterDlg dialog template
EXHPP.EXE .HPP Extractor
EXHPP.C .HPP Extractor source
TEST.CPP Main program used in the example
TEST.DLG Dialog templates used in example program
TEST.DEF Definition file for example program
TEST.RC Resource file for example program
TEST.MK Make file for example
TEST.ICO Icon for example program.
CDLG1.CPP Example CDlg super class
CDLG1.HPP Example CDlg super class header file
CWIND1.CPP Test CWind super class used in the example
CWIND1.HPP Test CWind super class header file
To build the example program:
C:\>make -ftest.mk
The test program creates a main window that has an "EDIT" class and a
"BUTTON" class object. Clicking on the button increases the number on
the button. The edit class allows you to type in text. This programming
example could easily be expanded to be a full text editor by supplying
code for the Open, Save, Save As, New and Print menu options.
These classes simplify the creation of Windows 3.0 applications by using
an object oriented method. Anyone who has done a Windows application
using C will find this method much easier. The skeleton of an
application takes a program of 10 lines instead of the several hundred
needed when using C.
The following is a list of classes and .CPP files.
Class .CPP File
-------- -------------
CAppl CAPPL.CPP
CBuffer CBUFFER.CPP
CWind CWIND.CPP
CDlg CDLG.CPP
CDlgAbout CDLGABT.CPP
COpenDlg COPENDLG.CPP
CSelPrnterDlg CSELPRN.CPP
CAppl (CAPPL.CPP)
This class is the Application class. There is only one of these classes
in a program. It is created in WinMain() as follows:
--------------------------- Start --------------------------------
/***
The main part of a Windows program is WinMain().
***/
int PASCAL WinMain(HANDLE hInst, HANDLE hPrev, LPSTR cmdln, int cmd)
{
CWind *pWind;
int x;
// Create the Topmost window.
pWind = new CWind(hInst, hPrev);
// Create the application class
gAppl = new CAppl(hInst, hPrev, pWind->GetHWnd());
// Run the application
x = gAppl->Run();
// Delete the application class
delete gAppl;
// Delete the top window.
delete pWind;
return x;
}
--------------------------- End ----------------------------------
This is the simplest application. It creates a Window class 'CWind'. The
application class, 'CAppl' is created by passing the handle to the
instance, the previous instance and the handle to the applications main
window. After being constructed, the 'Run' method is called which
handles doing the message loop and dispatching messages to the correct
window. It also handles any modeless dialogs that may be opened later in
the application.
If the application uses menus the method 'SetAppMenu' is called before
'Run':
--------------------------- Start --------------------------------
// Set Application menu
gAppl->SetAppMenu("APPMENU");
--------------------------- End ----------------------------------
If the application has an icon it wants to be used when made ICONIC, use
the 'SetAppIcon' method before 'Run':
--------------------------- Start --------------------------------
// Set Application icon
gAppl->SetAppIcon("PROGICON");
--------------------------- End ----------------------------------
The following is a list of methods available:
CAppl(HANDLE hI, HANDLE hP, HWND hWnd);
Constructor for the object.
WORD Run();
Run the application until a WM_QUIT message is received.
HANDLE GetInst(void);
Return the handle of the instance of the application.
HANDLE GetPrevInst(void);
Return the handle of the previous instance of the application.
BOOL SetAppIcon(LPSTR pIconName);
Set the icon of the application to the icon with the name
pointed to by 'pIconName'.
BOOL SetAppMenu(LPSTR pMenuName);
Set the menu of the application to the menu with the name
pointed to by 'pMenuName'.
BOOL SetAccelerator(LPSTR pAccelName);
Set the accelerator of the application to the accelerator with
the name pointed to by 'pAccelName'.
void EnableMenu(WORD wItem)
Enable the menu item with the id of 'wItem'.
void DisableMenu(WORD wItem)
Disable the menu item with the id of 'wItem'.
void GrayMenu(WORD wItem)
Gray the menu item with the id of 'wItem'.
void CheckMenu(WORD wItem)
Check the menu item with the id of 'wItem'.
void UnCheckMenu(WORD wItem)
Uncheck the menu item with the id of 'wItem'.
void InsertMenuItem(WORD wPos, WORD wFlags, WORD wItem, LPSTR pText)
Insert a menu item using wPos, wFlags, wItem and pText. See the
Windows SDK manual for the meaning of these parameters.
void AppendMenuItem(WORD wFlags, WORD wItem, LPSTR pText)
Append a menu item using wPos, wFlags, wItem and pText. See the
Windows SDK manual for the meaning of these parameters.
void DeleteMenuItem(WORD wPos, WORD wFlags)
Delete a menu item using wPos and wFlags. This allows menu items
to be deleted using a menu id or position.
HWND hTopWin;
Handle to the topmost window for the application.
HMENU ApplMenu;
Handle to the menu for the application.
CBuffer (CBUFFER.CPP)
The 'CBuffer' class is used internally by 'CAppl' to handle the list of
modeless dialog boxes. It can also be used to handle a list of fixed
length objects. The following methods are available:
CBuffer(WORD nItemSize);
Construct a CBuffer object with an item size of 'nItemSize'.
BOOL AppendItem(LPVOID lpItem);
Append an item to the end of the list.
BOOL DeleteItem(WORD Index);
Delete the item with index 'Index' from the list. All items
after the indexed item are moved down one position.
BOOL GetItem(LPVOID lpItem, WORD Index);
Move a copy of the data with index 'Index' into the buffer
pointed to by lpItem.
void DoForEach(CALLBACK lpFunc, LONG lParam);
Call a function passing a pointer to each item in the list. The
callback function is defined as:
int FAR PASCAL CallFn(LPVOID, LONG);
The 'lParam' variable is passed unchanged to the callback
function.
WORD GetItemCount(void);
Return the number of items in the list.
CWind (CWIND.CPP)
This class defines a top most or child window class. This is an abstract
class, you must define your own window class based upon this class. You
will want to at least override the DoPaint() method and maybe more.
The following is a list of methods available for the CWind class:
CWind(HANDLE hInst, HANDLE hPrevInst);
Constructor for creating a topmost window. A class created using
this constructor should only be created once.
CWind(CWind *pParent, LPSTR lpClass, LPSTR lpCaption, DWORD dwStyle,
int x, int y, int width, int height, int Id);
Create a CWind class for a child window. If 'lpClass' is NULL,
the normal 'Base' class is used. You can create a child window
of another class such as 'BUTTON' or 'LISTBOX'. The CWind object
created will be a subclass of the control and the object will
receive the messages before the control.
HANDLE GetHWnd(void);
Return the window handle for the window associated with the
CWind class.
HDC GetWndDC(void);
Get a DC for the window.
void ReleaseWndDC(HDC hDC);
Release a DC for the window.
void GetWndClientRect(LPRECT lpRect);
Get the client rectangle for the window.
void GetWndRect(LPRECT lpRect);
Get the windows rectangle. This includes any title bar, menu bar
or border.
void SetWndText(LPSTR lpTitle);
Set the window's title.
void Show(void);
Show the window.
void Hide(void);
Hide the window.
void Move(int x, int y, int width, int height, BOOL bRepaint);
Move the window to a new location.
void Center(void);
Center the window inside the screen.
virtual void UpdateMenus(void);
This virtual function is called whenever a mouse down message is
received and the mouse is in the menu bar. It allows the CWind
object to change the status of the menu items before the menu's
drop down.
virtual void SetupDC(HDC hDC);
This virtual function allows the CWind class to setup the DC
before the GetWndDC() method returns. You can change the map
mode, default colors, etc..
virtual LONG DoDefault(unsigned Message, WORD wParam, LONG lParam);
This virtual function is the default message handler. If the
CWind object can not handle the message, this method is called.
virtual LONG DoCommand(WORD wMenuId, LONG lParam);
This virtual method handles the WM_COMMAND message. It would be
overridden to handle menu options selected by the user.
virtual LONG DoCreate(LPCREATESTRUCT lpCreate);
This virtual method is called whenever the WM_CREATE message is
received.
virtual LONG DoDestroy(void);
This virtual function handles the WM_DESTROY message.
virtual LONG DoKillFocus(HWND hNewWnd);
This virtual function handles the WM_KILLFOCUS message. The
windows is about to lose the input focus.
virtual LONG DoPaint(void);
This virtual function handles the WM_PAINT message. This method
would be overridden to repaint the screen as necessary.
virtual LONG DoSetFocus(HWND hOldWnd);
This virtual function handles the WM_SETFOCUS message;
virtual LONG DoSize(WORD wCmd, LPPOINT lpPoint);
This virtual function handles the WM_SIZE message.
virtual LONG DoSysCommand(WORD wCmd, LPPOINT lpPoint);
This virtual function handles the WM_SYSCOMMAND message. It
should be overridden to handle any menu commands selected from
the system menu.
virtual LONG DoMouseDown(unsigned Message, WORD wParam, LPPOINT lpPoint);
This virtual function handles the mouse down event.
virtual LONG DoMouseUp(unsigned Message, WORD wParam, LPPOINT lpPoint);
This virtual function handles the mouse up event.
virtual LONG DoMouseMove(WORD wParam, LPPOINT lpPoint)
This virtual function handles the mouse move event.
CDlg (CDLG.CPP)
The CDlg class handles modal dialogs. This is an abstract class similar
to the CWind class. You will want to override the DoInitDialog and
DoCommand methods. See the CDlgAbout class for additional details.
The following methods are available from the CDlg class:
virtual BOOL FAR PASCAL Go(HWND hDlg, unsigned Message,
WORD wParam, LONG lParam);
This virtual method does the CASE statement to branch off to the
various virtual functions. It most likely will not be overridden.
virtual BOOL DoInitDialog(WORD nFocusID, LONG lParam);
This virtual method handles initializing the dialog. Override to
setup the dialog accordingly.
virtual BOOL DoCommand(WORD ControlID, LONG lParam);
This virtual method handles the WM_COMMAND message received.
Override to handle the messages received from the controls in
the dialog.
virtual BOOL DoDefault(unsigned Message, WORD wParam, LONG lParam);
This virtual method handles any messages that are not handled by
the CDlg class.
int DoDialog(HANDLE hInst, LPSTR lpDlgName, HWND hParent, LONG lParam);
Do the dialog. Pass the handle to the application instance, a
pointer to the dialog template name, the parent's window handle
and a LONG parameter that is passed to the DoInitDialog method.
void Center(void);
Center the dialog within the screen.
CDlgAbout (CDLGABT.CPP)
The CDlgAbout class is a super class of the CDlg class. It defines an
About dialog that has one button labeled OK. Normally you will not have
to subclass this object. It automatically looks in the applications
resources for the dialog called "ABOUT_BOX" and uses it. The dialog
remains until a button is pressed that sends a IDOK value.
The following methods are available from the CDlgAbout class:
void DoAboutBox(HANDLE hInst, HWND hParent);
Do the dialog. It passes "ABOUT_BOX" as the name of the dialog
to show and 0l and the LONG parameter to the DoDialog() method.
BOOL DoInitDialog(WORD nFocusID, LONG lParam);
This is an overridden method of the CDlg class. It centers the
dialog in on the screen and returns.
BOOL DoCommand(WORD ControlID, LONG lParam);
This is an overridden method of the CDlg class. It watches for a
IDOK ControlID and then closes ends the dialog.
Example of use:
--------------------------- Start --------------------------------
CDlgAbout *pDlgAbout;
pDlgAbout = new CDlgAbout;
pDlgAbout->DoAboutBox(WhInstance, WhWnd);
delete pDlgAbout;
--------------------------- End ----------------------------------
COpenDlg (COPENDLG.CPP)
This class implements an Open File dialog. You can specify the default
extension to show in the list box and whether the file name entered must
exist. This class is a superclass of the CDlg class.
The dialog template "OPEN_DLG" is defined in the COPENDLG.RC and
#defines for the controls are defined in COPENDLG.H.
The following methods are available from the CDlgAbout class:
COpenDlg(LPSTR lpExt, BOOL bFExist);
This is the constructor to be used when creating the object.
lpExt is a pointer to the default extension. bFExist is TRUE if
the file must exist.
BOOL DoInitDialog(WORD nFocusID, LONG lParam);
This is an overridden virtual function to handle initializing the
dialog.
BOOL DoCommand(WORD ControlID, LONG lParam);
This is an overridden virtual function to handle the control's
messages.
void GetFileName(LPSTR lpName);
This method returns the file name selected. Call this method
before destroying the object.
Example of use:
--------------------------- Start --------------------------------
COpenDlg *pOpenDlg;
pOpenDlg = new COpenDlg((LPSTR)"*.cpp", TRUE);
pOpenDlg->DoDialog(WhInstance, "OPEN_DLG", WhWnd, 0l);
pOpenDlg->GetFileName((LPSTR)FileName);
delete pOpenDlg;
--------------------------- End ----------------------------------
CSelPrnterDlg (CSELPRN.CPP)
This class presents the user with a select printer dialog. The user can
select a printer and this class finds the correct driver and port name.
The variables CSelPrnterDlg::szDevice, CSelPrnterDlg::szDriver and
CSelPrnterDlg::szPort are static and can be accessed after the object
has been destroyed.
The dialog template "SELPRN_DLG" is defined in the CSELPRN.RC and
#defines for the controls are defined in CSELPRN.H.
Example of use:
--------------------------- Start --------------------------------
CSelPrnterDlg *pSelPrn;
pSelPrn = new CSelPrnterDlg;
pSelPrn->DoDialog(WhInstance, "SELPRN_DLG", WhWnd, 0l);
delete pSelPrn;
--------------------------- End ----------------------------------
EXHPP.EXE
This program allows the programmer to have the .HPP file embedded inside
the .CPP file. One the most irritating things I found about programming
in C++ was the idea that for each class you had two files, the .CPP code
and .HPP header file. By putting codes in the .CPP file, the EXHPP.EXE
program can extract a .HPP file. The running of the EXHPP.EXE file can
even be automated in MAKE. By adding the following rule, any .OBJ file
that relies on a .HPP file will have the .HPP file extracted:
.cpp.hpp:
exhpp $*.cpp
If EXHPP.EXE is run, it extracts the .HPP portion and compares it with
an existing HPP file. If they are the same, the old file is left alone
so no MAKE dependencies will be triggered. If they are different, the
new .HPP file is saved.