⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pflowwin.cpp

📁 用于电力系统潮流计算 c++程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//----------------------------------------------------------------------------
// UWPflow for Windows routines:
//      - Windows creation and controls (menus, keyboard, etc.)
//      - Redefinition of some stdio.h routines (in 'pfwstdio.h')
//
//  Claudio Canizares (c) 1996
//  University of Waterloo
//----------------------------------------------------------------------------
//
#define _PFLOW_WINDOWS
#include <owl\owlpch.h>
#include <owl\applicat.h>
#include <owl\decframe.h>
#include <owl\dc.h>
#include <owl\inputdia.h>
#include <owl\opensave.h>
#include <owl\controlb.h>
#include <owl\buttonga.h>
#include <owl\statusba.h>
#include <owl\gdiobjec.h>
#include <owl\chooseco.h>
#include <owl\scroller.h>
#include <owl\textgadg.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <process.h>
#include <time.h>

#include "pflowwin.rc"
#include "pfwstdio.h"
#include "pflowwin.h"

// Redefinition of stdin, stdout and stderr
FILE *stdout, *stdin, *stderr;

// Redefine input arguments  (command line)
int Argc=0;
char **Argv;

// Define exit label
jmp_buf exit_main;

// Define Screen and other realted variables to Paint window
ScreenType *ScreenBegin=NULL, *ScreenEnd=NULL, *Screen=NULL;
BOOL NewLine=TRUE;
int NumberLines,TotalNumberLines;
time_t InitialT,DeltaT=0;


// Define pointer to desired window for writing
PflowWindow *MyWindow;
TDecoratedFrame* Frame;
TStatusBar *StatusBar;
TControlBar *ControlBar;

// Definiton of UWPflow main
int pfw_main();

// Define Response Table
DEFINE_RESPONSE_TABLE1(PflowWindow, TWindow)
  EV_WM_LBUTTONDOWN,
  EV_WM_RBUTTONDOWN,
  EV_COMMAND(CM_CLEARSCREEN, CmClearScreen),
  EV_COMMAND(CM_FILEOPEN, CmFileOpen),
  EV_COMMAND(CM_FILESAVE, CmFileSave),
  EV_COMMAND(CM_FILESAVEAS, CmFileSaveAs),
  EV_COMMAND(CM_ABOUT, CmAbout),
  EV_COMMAND(CM_COMMANDLINE, CmCommandLine),
  EV_COMMAND(CM_BATCH, CmBatch),
  EV_COMMAND(CM_RUN, CmRun),
  EV_COMMAND(CM_HELP, CmHelp),
  EV_COMMAND(CM_EDIT,CmEdit),
END_RESPONSE_TABLE;

// Intialization of main window
PflowWindow::PflowWindow(TWindow *parent):TWindow(parent)
{
  ofstream os;

  InitialT=time(NULL);
  IsNewFile = TRUE;
  IsDirty = FALSE;
  CountRuns=0;
  MyWindow=this;
  strcpy(Options,"");
  LogFileData = new TOpenSaveDialog::TData(OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
                                        "Log Files (*.log)|*.log|All Files (*.*)|*.*|", 0, "",
                                        "log");

  BatchFileData = new TOpenSaveDialog::TData(OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
                                        "Batch/Script Files (*.bat)|*.bat|All Files (*.*)|*.*|", 0, "",
                                        "bat");

  DataFileData = new TOpenSaveDialog::TData(OFN_HIDEREADONLY,
                                        "WSCC Files (*.wsc)|*.wsc|IEEE Files (*.cf)|*.cf|All Files (*.*)|*.*");

  // Construct Scrollbars
  NumberLines=TotalNumberLines=1;
  FirstScreen=TRUE;
  xRange=BUFFER;
  yRange=10;
  dyRange=SCROLL;
  xUnits=8;
  yUnits=12;
  Attr.Style |= WS_VSCROLL | WS_HSCROLL;
  Scroller = new TScroller(this,xUnits,yUnits,xRange,yRange);

  // Font selection
  MyFont= new TFont(yUnits,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,0,
                    OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
                    FIXED_PITCH|FF_DONTCARE,0);
/* Definition of the different variables above:
   TFont(int height, int width, int escapement = 0, int orientation = 0,
        int weight = FW_NORMAL, BYTE italic = FALSE,
        BYTE underline = FALSE, BYTE strikeout = FALSE,
        BYTE charSet = 1,
        BYTE outputPrecision = OUT_DEFAULT_PRECIS,
        BYTE clipPrecision = CLIP_DEFAULT_PRECIS,
        BYTE quality = DEFAULT_QUALITY,
        BYTE pitchAndFamily = DEFAULT_PITCH|FF_DONTCARE,
        const char far* facename = 0);   */


  // Initialize FILE variables stdout, stderr, stdin
  stdout=new FILE;
  strcpy(stdout->Name,"");
  stdout->Screen=1;
  stderr=new FILE;
  strcpy(stderr->Name,"");
  stderr->Screen=1;
  stdin=new FILE;
  strcpy(stdin->Name,"");
  stdin->Screen=0;
}

BOOL PflowWindow::CanClose()
{

  if (IsDirty)
    switch(MessageBox("Do you want to save Screen?", "Screen has changed",
                      MB_YESNOCANCEL | MB_ICONQUESTION)) {
      case IDCANCEL:
        // Choosing Cancel means to abort the close -- return FALSE.
        return FALSE;

      case IDYES:
        // Choosing Yes means to save the Screen.
        CmFileSave();
        if (IsDirty) return FALSE;

      case IDNO:
        // Choosing No means clear variables
        IsDirty=FALSE;
    }
  return TRUE;
}


BOOL PflowWindow::PreProcessMsg(MSG& msg)
{
  if(msg.message==WM_KEYDOWN) switch(msg.wParam){
    case VK_DOWN:
      Scroller->ScrollBy(0,1);
      return TRUE;
    case VK_UP:
      Scroller->ScrollBy(0,-1);
      return TRUE;
    case VK_LEFT:
      if (GetKeyState(VK_CONTROL)<0) Scroller->ScrollBy(-10,0);
      else Scroller->ScrollBy(-1,0);
      return TRUE;
    case VK_RIGHT:
      if (GetKeyState(VK_CONTROL)<0) Scroller->ScrollBy(10,0);
      else Scroller->ScrollBy(1,0);
      return TRUE;
    case VK_NEXT:
      Scroller->ScrollBy(0,10);
      return TRUE;
    case VK_PRIOR:
      Scroller->ScrollBy(0,-10);
      return TRUE;
    case VK_END:
      Scroller->ScrollTo(0,yRange);
      return TRUE;
    case VK_HOME:
      Scroller->ScrollTo(0,0);
      return TRUE;
    case VK_TAB:
      if (GetKeyState(VK_SHIFT)<0) Scroller->ScrollBy(-10,0);
      else Scroller->ScrollBy(10,0);
      return TRUE;
    case VK_F1:
      CmHelp();
      return TRUE;
    case VK_F4:
      CmCommandLine();
      return TRUE;
    case VK_F5:
      CmRun();
      return TRUE;
    case VK_F6:
      CmBatch();
      return TRUE;
    case VK_F3:
      CmFileSave();
      return TRUE;
    case VK_F2:
      CmFileOpen();
      return TRUE;
    case VK_F10:
      CmClearScreen();
      return TRUE;
  }
  return FALSE;
}

BOOL PflowWindow::Stop()
{
  MSG msg;

  if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
    if (msg.message==WM_KEYDOWN && msg.wParam==VK_ESCAPE) {
      printf("\nWARNING:  Case interrupted by user.  Some files might\n");
      printf("          still be open; this could cause some problems.\n");
      Invalidate();
      UpdateWindow();
      return TRUE;
    } else return FALSE;
  }
  return FALSE;
}

void PflowWindow::EvLButtonDown(UINT, TPoint&)
{
  CmCommandLine();
}

void PflowWindow::EvRButtonDown(UINT, TPoint&)
{
  CmFileSave();
}


// Input UWPflow Command Line
void PflowWindow::CmCommandLine()
{

  if (TInputDialog(this, "Program Options",
                        "Input the command line options:",
                        Options,
                        sizeof(Options)).Execute() == IDOK) {
    GetArguments(Options,"uwpflow");
    CmRun();
  }
}

// Read batch/script file
void PflowWindow::CmBatch()
{
  char Buffer[BUFFER],*string;
  int i;
  FILE *InputFile;

  if ((TFileOpenDialog(this, *BatchFileData)).Execute() == IDOK) {
    InputFile=fopen(BatchFileData->FileName,"r");
    if (InputFile==NULL)
      MessageBox("Unable to open file", "File Error", MB_OK | MB_ICONEXCLAMATION);
    else {
      for (i=1; i<BUFFER-1; i++) printf("%c",'-'); printf("\n");
      printf("RUN batch/script file: %s\n",BatchFileData->FileName);
      while (fgets(Buffer,BUFFER,InputFile)!=NULL) if (Buffer[0]!='@'){
        if((string=strstr(Buffer,"echo"))!=NULL) {
          if ((string=strchr(string,' '))!=NULL) printf("%s",&string[1]);
        }
        else if(strstr(Buffer,"rem")!=NULL) { continue;}
        else if(strstr(Buffer,"pause")!=NULL) {
          Invalidate();
          UpdateWindow();
          switch(MessageBox("Do you want to continue?", "Pause", MB_YESNO | MB_ICONQUESTION)) {
            case IDYES:
              continue;

            case IDNO:
              printf("\nEND of batch/script file\n");
              Invalidate();
              UpdateWindow();
              fclose(InputFile);
              return;
          }
          printf("\n");
        }
        else if((string=strstr(Buffer,"uwpflow"))!=NULL ||
                (string=strstr(Buffer,"UWPflow"))!=NULL ||
                (string=strstr(Buffer,"UWPFLOW"))!=NULL ) {
          string=strchr(string,' ');
          string[strlen(string)-1]='\0';
          strcpy(Options,&string[1]);
          GetArguments(Options,"uwpflow");
          CmRun();
        }
#ifdef WIN95
        else if((string=strstr(Buffer,"tomatlab"))!=NULL ||
                (string=strstr(Buffer,"Tomatlab"))!=NULL ||
                (string=strstr(Buffer,"TOMATLAB"))!=NULL ) {
          printf("%s",string);
          string=strchr(string,' ');
          string[strlen(string)-1]='\0';
          strcpy(Options,&string[1]);
          GetArguments(Options,"tomatlab");
          if (spawnvp(P_NOWAIT,"tomatlab.bat",Argv)==-1) {
            StatusBar->SetText("Problems with Tomatlab");
          }
        }
        else if((string=strstr(Buffer,"maxim"))!=NULL ||
                (string=strstr(Buffer,"Maxim"))!=NULL ||
                (string=strstr(Buffer,"MAXIM"))!=NULL ) {
          printf("%s",string);
          string=strchr(string,' ');
          string[strlen(string)-1]='\0';
          strcpy(Options,&string[1]);
          GetArguments(Options,"maxim");
          if (spawnvp(P_NOWAIT,"maxim.exe",Argv)==-1) {
            StatusBar->SetText("Problems with Maxim");
          }
        }
        else if((string=strstr(Buffer,"awk"))!=NULL ||
                (string=strstr(Buffer,"Awk"))!=NULL ||
                (string=strstr(Buffer,"AWK"))!=NULL ) {
          printf("%s",string);
          string=strchr(string,' ');
          string[strlen(string)-1]='\0';
          strcpy(Options,&string[1]);
          GetArguments(Options,"awk");
          if (spawnvp(P_WAIT,"awk.exe",Argv)==-1) {
            StatusBar->SetText("Problems with Awk");
          }
        }
        else if((string=strstr(Buffer,".bat"))!=NULL ||
                (string=strstr(Buffer,".Bat"))!=NULL ||

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -