📄 wpig.cpp
字号:
// File: wpig.cpp PIGS for Windows
/* ====================================================================
Written by: Lizhuang Fu July 1994
Norman Chan
John Carver
WPIG.CPP is the MS Windows implementation of the Portable Interface
for Graphical Systems. PIG.FOR and PIG1.FOR retain the function
definitions used by the applications. WPIG deals with the Windows
interface.
Naming:
Functions beginning with WPig... are Windows functions, callable
from an application. Those beginning with IWPig... are internal to
the WPIG program.
For an application to use WPIG, the main routine of the application
must be changed to SUBROUTINE MainApp so that it can be called from
Windows.
Files used by WPIG.CPP:
WPIG.HPP PIG.FOR
WPIG.H PIG1.FOR
WPIG.RC PIG.DEF
WPIG.DEF IPIG.DEF
WPIG.ICO PIG_MENU.FOR
RESOURCE.H PIGPANEL.FOR
==================================================================== */
#include <afxwin.h>
#include <afxcoll.h>
#include <commdlg.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
//#pragma hdrstop
#include "wpig.h"
#include "wpig.hpp"
//#include "wpig.h"
#include "resrc1.h"
#include "resource.h"
#if defined(_DEBUG)
#define new DEBUG_NEW
#endif
// Device contexts for client's Main window, Control window, Status window,
// and application window.
static CClientDC *CurrentClientDC;
static CDC *CurrentDC;
static Long Printing = FALSE;
static CRgn CurrentRgn;
//RECT MainRect, ProfileRect, CtrlRect, StatRect;
static CRect MainRect, ProfileRect, CtrlRect, StatRect;
//static int WindowNum = MAINWIN;
static int WindowNum = -1;
static BOOL quitting = FALSE;
//
static BOOL ButtonDown = FALSE;
static BOOL MouseMove = FALSE;
static int ZoomStatus = ZOOM_OFF;
static int RubberStatus = RUBBER_OFF;
static POINT StartPos;
static POINT MousePos;
// Default pen and brush attributes
static int PenStyle = PS_SOLID;
static int PenWidth = 0;
static Real SpacingFactor = (Real)0.0;
static DWORD PenColour = WWHITE;
static DWORD BrushColour = WYELLOW;
static DWORD TextColour = WWHITE;
static DWORD BackgrColour = WBLACK;
static DWORD ForegrColour = WLTGRAY;
// Size of client area
static int nMaxX=0, nMaxY=0; // max size of client area
static int nSizeX, nSizeY; // current size of client area
// for printing
static int border_x = 0;
static int border_y = 0;
// Symbol attributes
static Long SymbolNumber = WPPOINT;
static DWORD SymbolColour = WYELLOW;
static Real SymbolSize = 1.0f;
// initialization of StdSymbolSize should use the symbolids...
//Real StdSymbolSize[] = {0, 1, 3.0, 1.2, 2.0, 1.7, 1.7, 1.5};
//static Real StdSymbolSize[] = {(Real)0.0, (Real)2.0, (Real)2.0,
// (Real)2.0, (Real)4.0, (Real)2.0, (Real)2.0, (Real)2.0};
static Real const StdSymbolSize[] = {0.0f, 2.0f, 2.0f, 2.0f, 4.0f, 2.0f, 2.0f, 4.0f, 0.0f};
//Real StdSymbolSize[] = {0, 5.0, 6.0, 8.0, 4.0, 5.0, 5.0, 5.0};
static Real const RootThree = 1.732f;
// World coordinates for
//int XMainExt=1000, YMainExt=1000; // Windows's WC extents for MAINWIN
//static int XMainExt=10000, YMainExt=10000; // Windows's WC extents for MAINWIN
static int XMainExt=1000, YMainExt=1000; // Windows's WC extents for MAINWIN
static int XProfileExt=4000, YProfileExt=10000; // Windows's WC extents for PROFILEWIN
static int XCtrlExt=4000, YCtrlExt=10000; // Windows's WC extents for CONTROLWIN
static int XStatExt=100, YStatExt=500; // Windows's WC extents for STATUSWIN
static double wx1=0.0, wx2=1.0;
static double wy1=0.0, wy2=1.0; // user defined world coordinates for MAINWIN
static double waspect=-1.0;
static double px1=0.0, px2=1.0;
static double py1=0.0, py2=1.0; // user defined world coordinates for PROFILEWIN
static double paspect=1.0;
static Real StatusWinHight = (Real).05; // 5% of nMaxY of client area
static Real CtrlWinWidth = (Real).35; // 345% of nMaxX of client area
static CWnd *winPtr;
static HWND hWnd;
static WinPig thePig;
static WinPig *FuncPtr = &thePig;
static int pig_initialized = FALSE;
// Long Retval; // , MenuItem;
// static BOOL WinQuit = FALSE;
static UINT TextAlignFlag = 0;
static char Answer = 'N';
static CString InString;
CTheApp theApp;
static FILE *debugfile = 0;
static int cdebug = FALSE;
// ------------------------ BEGIN ------------------------------- //
// Sets the message passed from application to the caption for the
// dialogue box.
BOOL CEditDialog::OnInitDialog()
{
// this->SetWindowText(*MsgStr);
// return TRUE;
// this->SetWindowText(*MsgStr);
this->SetWindowText("Edit String");
SetDlgItemText( IDC_INPUT_MSG, *MsgStr);
// SetDlgItemText( IDC_EDIT1, *MsgStr);
SetDlgItemText( IDC_DATA, *ReplyStr);
return TRUE;
}
// When the user hits OK, get the data entered and store it in
// Instring.
void CEditDialog::OnOKBtn()
{
GetDlgItemText( IDC_DATA, InString.GetBuffer(79), 79);
InString.ReleaseBuffer();
EndDialog(IDOK);
}
BEGIN_MESSAGE_MAP( CEditDialog , CModalDialog )
ON_COMMAND( IDOK, OnOKBtn )
END_MESSAGE_MAP()
// Sets the message passed from application to the caption for the
// dialogue box.
BOOL QuitDialog::OnInitDialog()
{
this->SetWindowText(*MsgStr);
SetDlgItemText( IDC_QUIT_MSG, *MsgStr);
return TRUE;
}
// This member function is called when the user confirms on quit.
void QuitDialog::OnOKBtn()
{
#if defined(_DEBUG)
(void)AfxCheckMemory( );
#endif
#if defined(_DEBUG)
(void)AfxCheckMemory( );
#endif
// if ( WinQuit ) {
//#if defined(_DEBUG)
// (void)AfxCheckMemory( );
//#endif
// WPigExit();
//#if defined(_DEBUG)
// (void)AfxCheckMemory( );
//#endif
// } else {
Answer = 'Y';
EndDialog(IDOK);
// };
#if defined(_DEBUG)
(void)AfxCheckMemory( );
#endif
// EndDialog(IDOK);
}
// This member function is called when the user hits the CANCEL button.
void QuitDialog::OnCancelBtn()
{
#if defined(_DEBUG)
(void)AfxCheckMemory( );
#endif
Answer = 'N';
EndDialog(IDCANCEL);
#if defined(_DEBUG)
(void)AfxCheckMemory( );
#endif
}
BEGIN_MESSAGE_MAP( QuitDialog , CModalDialog )
ON_COMMAND( IDOK, OnOKBtn )
ON_COMMAND( IDCANCEL, OnCancelBtn )
END_MESSAGE_MAP()
// Set the message passed from application to the caption for fatal error
// dialogue box.
BOOL FatalDialog::OnInitDialog()
{
this->SetWindowText(*aTitleStr);
SetDlgItemText( IDC_FATAL_MSG, *aTitleStr);
return TRUE;
}
// Failure error, quits application.
void FatalDialog::DoQuit()
{
#if defined(_DEBUG)
(void)AfxCheckMemory( );
#endif
WPigExit();
#if defined(_DEBUG)
(void)AfxCheckMemory( );
#endif
}
BEGIN_MESSAGE_MAP( FatalDialog , CModalDialog )
ON_COMMAND( IDOK, DoQuit )
END_MESSAGE_MAP()
// This function is called just before dialog box becomes visible, and
// initializes the list items.
BOOL CListDialog::OnInitDialog()
{
nChoice = 0;
POSITION pos;
this->SetWindowText(*aCStr);
SetDlgItemText( IDC_SELECT_MSG, *aCStr);
int nItems = pList->GetCount();
if ( nItems > 0 )
{
pListBox = (CListBox*) this->GetDlgItem(DLI_LISTBOX);
pListBox->ResetContent();
pos = pList->GetHeadPosition();
for ( int i = 0; i < nItems; i++ )
{
CString str = pList->GetNext(pos);
pListBox->AddString(str);
};
pListBox->SetCurSel(0); // highlights first item.
};
return TRUE;
}
// This member function called when the user sets the cursor position.
void CListDialog::OnListBoxSel()
{
nChoice = pListBox->GetCurSel();
}
BEGIN_MESSAGE_MAP( CListDialog, CModalDialog )
ON_COMMAND( DLI_OK, OnOkBtn )
ON_LBN_SELCHANGE( DLI_LISTBOX, OnListBoxSel )
END_MESSAGE_MAP()
// Override default InitInstance()
extern "C" {
static void MainAppCall(void)
{
#if defined(_DEBUG)
(void)AfxCheckMemory( );
#endif
MainApp();
#if defined(_DEBUG)
(void)AfxCheckMemory( );
#endif
}
};
BOOL CTheApp::InitInstance()
{
// open c debug file if needed
cdebug = FALSE;
{
FILE *tmp = NULL;
if((tmp = fopen("PIGDEBUG.","rt")) != NULL) {
cdebug = TRUE;
fclose(tmp);
}
}
if(cdebug) {
debugfile = fopen("debugc.","wt");
fprintf(debugfile,"Starting CTheApp::InitInstance()\n");
fflush(debugfile);
}
// initialize application and set window max
nMaxX = nMaxY = 0;
m_pMainWnd = new CMainWindow ();
m_pMainWnd->ShowWindow (SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow ();
winPtr = m_pMainWnd;
// create and initialize display context
CurrentClientDC = new CClientDC(m_pMainWnd);
CurrentDC = (CDC *)CurrentClientDC;
// create clipping regions
IWPigSetWindowRect ();
CurrentRgn.CreateRectRgn(0, 0, nSizeX, nSizeY);
IWPigSetWindowRgn ();
// set default window to MAINWIN
WPigSetWindowNum(MAINWIN);
// call main routine of TRIGRID application
if(cdebug) {
fprintf(debugfile,"Calling MainApp()\n");
fflush(debugfile);
}
MainAppCall(); // calls application subroutine
// which provides addresses of...
return TRUE;
}
int CTheApp::ExitInstance ()
{
if(cdebug) {
fprintf(debugfile,"Starting CTheApp::ExitInstance()\n");
fflush(debugfile);
}
#if defined(_DEBUG)
(void)AfxCheckMemory( );
#endif
delete CurrentClientDC;
return 0;
}
// constructor for window
CMainWindow::CMainWindow()
{
if(cdebug) {
fprintf(debugfile,"Starting CMainWindow::CMainWindow()\n");
fflush(debugfile);
}
CString AppTitle, ClassName;
// AppTitle.LoadString (S_PROGRAMCAPTION); // needs to be changed...
AppTitle = CString("TriGrid/Win32 Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -