Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

2004 alternative for default windowing

14 views
Skip to first unread message

Lynn McGuire

unread,
Feb 9, 2015, 1:11:33 PM2/9/15
to
To refresh my alternative for default windowing:

I have created an alternative for default windowing that allows a
"prettier" default window. The problem is that in order to use this,
you have to translate all writes to 6 to use the functions
"writeLineToScreen" and "writeCharToScreen". All reads from 5
must use "readLineFromScreen". The neat thing about this is that
depending on which version of these functions you have linked in
you can either be a console process or a windowed process,
your code just does not care.

I do not remember where I got this code, I think that I developed
it from some sample MS dev kit code.

Lynn

Lynn McGuire

unread,
Feb 9, 2015, 1:12:07 PM2/9/15
to
// winmain.h

// 12/04/96 Lynn McGuire created


#define MSG_SAVEAS 1
#define MSG_EXIT 2
#define MSG_COPY 3
#define MSG_SELECTALL 4
#define MSG_ABOUT 5

extern HWND ScreenOutputWindow;
extern HWND MainWindow;
extern char AboutMsg [4096];
extern char AboutTitle [4096];

int MessageLoop ();
void writeLineToScreen (char *msg);
void writeCharToScreen (char aChar);
void readLineFromScreen (char *msg);
void mymain (char *programDirectory, char *inputfile, char *outputfile);

Lynn McGuire

unread,
Feb 9, 2015, 1:13:05 PM2/9/15
to
// winmain.c


// 12/04/96 Lynn McGuire created
// 01/27/97 Lynn McGuire added check for loading RICHED32.DLL library
// 11/29/00 Lynn McGuire delete the temporary file if there is one
// when we are done
// 01/26/01 Lynn McGuire increase filename buffers


#define STRICT 1


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <windows.h>

#include "winmain.h"


static char mainClass [] = "DESIGN II Main Window";

/* Text for window title bar */

char WinTitleBar [] = "DESIGN II Application";


#define KBFSIZE 256
#define AllowableChars " 0123456789abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\\|?,.<>`'\";:~!@#$%^&*()_+-="


HWND ScreenOutputWindow;
HWND MainWindow;
HFONT FixedFont;
HMENU MainMenu;
char AboutMsg [4096];
char AboutTitle [4096];
char keyboardBuffer [KBFSIZE];
int keyboardBufferSize = 0;
int totalCharactersWrittenToScreen = 0;
WNDPROC oldEditWindowProc = NULL;


static BOOL firstInstance( HANDLE );
static int windowsInit( HANDLE, int );
LRESULT CALLBACK MainWindowProc (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam);
LRESULT CALLBACK EditWindowProc (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam);
int BlockingMessageLoop (void);
void SaveAsToFile ( void );
void KILL_DII_WINDOW (int status);


int WINAPI WinMain (HINSTANCE inst, HINSTANCE previnst, LPSTR cmd, int show)
{
int rc = 0;
char filename [2048];
char inputFile [2048];
char outputFile [2048];
int i = 0;
int len = strlen (cmd);
int quote = FALSE;
int count = 0;

// MessageBox (NULL, cmd, "DII Command Line", MB_OK);

if ( ! firstInstance ( inst ) ) return ( FALSE );
if ( ! windowsInit ( inst, show ) ) return ( FALSE );

GetModuleFileName (NULL, filename, sizeof (filename));
for (i = strlen (filename); i > 0; i--)
{
if ('\\' == filename [i] || '/' == filename [i]) break;
filename [i] = '\0';
}

// the input file and the output file are the 1st and 2nd arguments
// the name of the excutable is NOT here
inputFile [0] = '\0';
outputFile [0] = '\0';
for (i = 0; i < len; i++)
{
if ( ! quote && ' ' == cmd [i]) break;
if (quote && '"' == cmd [i])
quote = FALSE;
else
{
if ('"' == cmd [i])
quote = TRUE;
else
{
inputFile [count] = cmd [i];
count++;
inputFile [count] = '\0';
}
}
}
// look for whitespace
while (i < len && (' ' == cmd [i] || '\t' == cmd [i])) i++;
quote = FALSE; // reset
count = 0; // reset
// get the second argument
for ( ; i < len; i++)
{
if ( ! quote && ' ' == cmd [i]) break;
if (quote && '"' == cmd [i])
quote = FALSE;
else
{
if ('"' == cmd [i])
quote = TRUE;
else
{
outputFile [count] = cmd [i];
count++;
outputFile [count] = '\0';
}
}
}

// set the current working directory to the directory of the
// input file
if (inputFile [0])
{
char workingDirectory [2048];

sprintf (workingDirectory, inputFile);
for (i = strlen (workingDirectory) - 1;
i > 0 && workingDirectory [i] != '\\';
i--)
workingDirectory [i] = '\0';

SetCurrentDirectory (workingDirectory);

GetCurrentDirectory (2048, workingDirectory);
// MessageBox (NULL, workingDirectory, "Working Directory", MB_OK);
}

// MessageBox (NULL, inputFile, "DII Input File", MB_OK);
// MessageBox (NULL, outputFile, "DII Output File", MB_OK);

if ( ! SetForegroundWindow (MainWindow))
{
#ifdef NOT_USED
int lastError = GetLastError ();
char msg [1024];

sprintf (msg, "WARNING ! ! !\n\n"
"Could not set the Main Window to be the\n"
"Foreground Window. Error code %d",
lastError);
MessageBox (MainWindow, msg, AboutTitle,
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
#endif
}

// call the simulator kernel
mymain (filename, inputFile, outputFile);

// delete the temporary file if there is one
if (inputFile [0])
{
char tempFile [2048];

strcpy (tempFile, inputFile);
// remove the trailing "in"
for (i = strlen (tempFile) - 1;
i > 0 && tempFile [i] && '.' != tempFile [i]; i--)
tempFile [i] = '\0';
strcat (tempFile, "tmp");
DeleteFile (tempFile);
}

// go ahead and quit now if they put -QUIT on the command line
// otherwise continue until the user kills the window manually
if ( ! strstr (cmd, "-QUIT") && ! strstr (cmd, "-Quit") &&
! strstr (cmd, "-quit"))
while (BlockingMessageLoop () == TRUE);

return ( rc );

} /* WinMain */


/*
* firstInstance - initialization at startup
*/
static BOOL firstInstance( HANDLE inst)
{
char tmp[128];
BOOL rc;
WNDCLASS wc;
HMENU smf, smh, sme;

strcpy (AboutTitle, "");
strcpy (AboutMsg, "");

/*
* make a menu (this way, we don't need resources)
*/
smf = CreateMenu();
if( smf == NULL ) return( FALSE );
AppendMenu( smf, MF_ENABLED, MSG_SAVEAS, "&Save As..." );
AppendMenu( smf, MF_SEPARATOR, 0, NULL );
AppendMenu( smf, MF_ENABLED, MSG_EXIT, "E&xit" );

sme = CreateMenu();
if( sme == NULL ) return( FALSE );
AppendMenu( sme, MF_ENABLED, MSG_COPY, "&Copy" );
AppendMenu( sme, MF_SEPARATOR, 0, NULL );
AppendMenu( sme, MF_ENABLED, MSG_SELECTALL, "Select &All" );

smh = CreateMenu();
if( smh == NULL ) return( FALSE );
AppendMenu( smh, MF_ENABLED, MSG_ABOUT, "&About..." );

MainMenu = CreateMenu();
if( MainMenu == NULL ) return( FALSE );
AppendMenu( MainMenu, MF_POPUP, (UINT) smf, "&File" );
AppendMenu( MainMenu, MF_POPUP, (UINT) sme, "&Edit" );
AppendMenu( MainMenu, MF_POPUP, (UINT) smh, "&Help" );

// register window classes
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) MainWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = inst;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = GetStockObject( WHITE_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = mainClass;

rc = RegisterClass( &wc );
return rc;
} /* firstInstance */


/*
* windowsInit - windows-specific initialization
*/
static int windowsInit( HANDLE inst, int showcmd )
{
LOGFONT logfont;
WORD x, y;
WORD width = 640;
WORD height = 400;
RECT rect;
char msg [256];
int limit = 0;
char *editControlName = NULL;

x = GetSystemMetrics( SM_CXSCREEN );
y = GetSystemMetrics( SM_CYSCREEN );

MainWindow = CreateWindow(
mainClass, /* our class */
"Main Window", /* Text for window title bar */
WS_OVERLAPPEDWINDOW, /* Window style. */
(x - width) / 2, /* horizontal position. */
(y - height) / 2, /* vertical position. */
width, /* width. */
height, /* height. */
NULL, /* parent */
MainMenu, /* menu handle */
inst, /* owner of window */
NULL /* extra data pointer */
);

if ( ! MainWindow ) return ( FALSE );

// display the window
//ShowWindow ( MainWindow, showcmd );
ShowWindow ( MainWindow, SW_SHOWNORMAL );
UpdateWindow ( MainWindow );

// this library is available in Win 95, Win 31 with Win32s 1.30,
// and Win NT 3.51 and up
if (LoadLibrary ("RICHED32.DLL"))
// RICHEDIT allows an unlimited text buffer
editControlName = "RICHEDIT";
else
{
// EDIT only allows a 64K buffer
editControlName = "EDIT";
MessageBox (MainWindow,
"Could not load the RICHED32.DLL dynamic link libary.\n"
"If this is Windows 3.1/3.11 then you must install\n"
"version 1.30 of Microsoft Win32s. If this is Windows\n"
"95 or Windows NT then you should reinstall the\n"
"operating system. Using the EDIT control for now.",
AboutTitle, MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
}

GetClientRect( MainWindow, &rect );
ScreenOutputWindow = CreateWindow(
editControlName, /* class */
NULL, /* no caption */
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
ES_READONLY |
ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, /* style */
0, /* init. x pos */
0, /* init. y pos */
rect.right-rect.left, /* init. x size (entire parent) */
rect.bottom-rect.top, /* init. y size (entire parent) */
MainWindow, /* parent window */
MainMenu, /* i.d. */
inst, /* program handle */
NULL /* create parms */
);

// set the font for the edit window
// Create a font to use, could also use ANSI_FIXED_FONT but it is
// not as pretty a font
FixedFont = GetStockObject( SYSTEM_FIXED_FONT );
GetObject( FixedFont, sizeof(LOGFONT), (LPSTR) &logfont );
FixedFont = CreateFontIndirect( &logfont );
SendMessage (ScreenOutputWindow, WM_SETFONT, (WPARAM) FixedFont, 0);

// see what the current text buffer size is
// limit = SendMessage (ScreenOutputWindow, EM_GETLIMITTEXT, 0, 0);
// sprintf (msg, "window size is %d", limit);
// writeLineToScreen (msg);

// reset the current text buffer size limit to 10,000,000 bytes
SendMessage (ScreenOutputWindow, EM_LIMITTEXT, 10000000, 0);
// limit = SendMessage (ScreenOutputWindow, EM_GETLIMITTEXT, 0, 0);
// sprintf (msg, "new window size is %d", limit);
// writeLineToScreen (msg);

// put my edit window proc first
oldEditWindowProc = (WNDPROC) SetWindowLong
(ScreenOutputWindow, GWL_WNDPROC, (LONG) EditWindowProc);

return( TRUE );

} /* windowsInit */


LRESULT CALLBACK MainWindowProc(
HWND hwnd, /* window handle */
UINT message, /* type of message */
WPARAM wParam, /* additional information */
LPARAM lParam) /* additional information */
{
switch (message)
{
case WM_CHAR:
MessageBox (MainWindow, "", "got WM_CHAR msg in MainWindowProc",
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
if (keyboardBufferSize < KBFSIZE)
{
keyboardBuffer [keyboardBufferSize] = wParam;
keyboardBufferSize++;
keyboardBuffer [keyboardBufferSize] = '\0';
}
break;

case WM_CREATE:
return 0;

case WM_COMMAND:
switch (wParam)
{
case MSG_ABOUT:
MessageBox (MainWindow, AboutMsg, AboutTitle,
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK);
break;

case MSG_COPY:
SendMessage (ScreenOutputWindow, WM_COPY, 0, 0);
break;

case MSG_EXIT:
DestroyWindow (MainWindow);
break;

case MSG_SELECTALL:
SendMessage (ScreenOutputWindow, EM_SETSEL, 0, -1);
break;

case MSG_SAVEAS:
SaveAsToFile ();
break;

// case IDM_ABOUT:
// DialogBox(hinst, /* current instance */
// "AboutBox", /* resource to use */
// hwnd, /* parent handle */
// (DLGPROC) About);
// break;

default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
break;

case WM_KEYDOWN:
MessageBox (MainWindow, "", "got WM_KEYDOWN msg",
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
if( wParam == VK_CANCEL )
{
MessageBox( MainWindow, "SIGBREAK", AboutTitle,
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
raise( SIGBREAK );
break;
}

case WM_SETFOCUS:
SetFocus(ScreenOutputWindow);
return 0;

case WM_SIZE:
// Make the edit control the size of the window's client area
MoveWindow(ScreenOutputWindow,
0, 0, /* starting x- and y-coordinates */
LOWORD(lParam), /* width of client area */
HIWORD(lParam), /* height of client area */
TRUE); /* repaint window */
return 0;

case WM_DESTROY:
DeleteObject (FixedFont);
PostQuitMessage(0);
return 0;

case WM_QUIT:
DestroyWindow (MainWindow);
exit (0);
return 0;

case WM_CLOSE:
DestroyWindow (MainWindow);
exit (0);
return 0;

default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return NULL;
}


LRESULT CALLBACK EditWindowProc(
HWND hwnd, /* window handle */
UINT message, /* type of message */
WPARAM wParam, /* additional information */
LPARAM lParam) /* additional information */
{
char msg [80];

switch (message)
{
case WM_CHAR:
// sprintf (msg, "%c %d, '\\n' is %d", wParam, wParam, '\n');
// MessageBox (MainWindow, msg, "got WM_CHAR msg in EditWindowProc",
// MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
if (keyboardBufferSize < KBFSIZE &&
(strrchr (AllowableChars, (char) wParam) ||
wParam == VK_RETURN ||
wParam == VK_BACK))
{
keyboardBuffer [keyboardBufferSize] = wParam;
keyboardBufferSize++;
keyboardBuffer [keyboardBufferSize] = '\0';
}
else
return CallWindowProc
(oldEditWindowProc, hwnd, message, wParam, lParam);
break;

case WM_KEYDOWN:
// MessageBox (MainWindow, "", "got WM_KEYDOWN msg in EditWindowProc",
// MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
// look for control-Break combination
if ( wParam == VK_CANCEL )
{
MessageBox ( MainWindow, "Stopping Execution", AboutTitle,
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
SendMessage (MainWindow, WM_CLOSE, 0, 0);
}
// look for a control-C combination
else if ((wParam == 'C' || wParam == 'c') &&
HIBYTE (GetKeyState (VK_CONTROL)) != 0)
{
MessageBox ( MainWindow, "Stopping Execution", AboutTitle,
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
SendMessage (MainWindow, WM_CLOSE, 0, 0);
}
// pass the message along to the edit window regardless
return CallWindowProc (oldEditWindowProc, hwnd, message, wParam, lParam);
break;

default:
return CallWindowProc
(oldEditWindowProc, hwnd, message, wParam, lParam);
}

return NULL;
}


int BlockingMessageLoop ( void )
{
MSG msg;
WORD rc=1;

rc = GetMessage ( &msg, NULL, NULL, NULL );
if (rc == TRUE)
{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
return MessageLoop ();
}
else
return rc;

} /* BlockingMessageLoop */


void SaveAsToFile ( void )
{
char fname[256];
OPENFILENAME of;
BOOL rc;
FILE *f;
int numLines = 0;
int index = 0;
char buffer [256];
int *pBuffer = (int *) buffer;
int length = 0;

char filterFiles[] = "Result Files (*.TXT)" \
"\0" \
"*.TXT" \
"\0\0";

fname[0] = 0;
memset( &of, 0, sizeof( OPENFILENAME ) );
of.lStructSize = sizeof( OPENFILENAME );
of.hwndOwner = MainWindow;
of.lpstrFilter = filterFiles;
of.nFilterIndex = 1L;
of.lpstrFile = fname;
of.nMaxFile = 256;
of.lpstrTitle = "Save File Name Selection";
of.Flags = OFN_HIDEREADONLY;
rc = GetSaveFileName( &of );

if ( !rc ) return;

f = fopen( fname, "w" );
if ( f == NULL )
{
MessageBox ( NULL, fname,"Error opening file", MB_OK );
return;
}
numLines = SendMessage (ScreenOutputWindow, EM_GETLINECOUNT, 0, 0);
for (index = 0; index < numLines; index++)
{
*pBuffer = 255;
length = SendMessage (ScreenOutputWindow, EM_GETLINE, index,
(LPARAM) (LPCSTR) buffer);
// remove the carriage return and line feed
if (length > 1) length -= 2;
buffer [length] = '\0';
fprintf ( f, "%s\n", buffer );
}
fclose ( f );
MessageBox ( NULL, fname, "Data saved to file", MB_OK );

} /* SaveAllLines */


int MessageLoop ( void )
{
MSG msg;
int rc = TRUE;

while ( PeekMessage( &msg, NULL, NULL, NULL, PM_NOREMOVE ) == TRUE )
{
rc = GetMessage( &msg, NULL, NULL, NULL );
if (rc == TRUE)
{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
}
Sleep (0);
return ( rc );

} /* MessageLoop */

Lynn McGuire

unread,
Feb 9, 2015, 1:13:25 PM2/9/15
to
// desman.c - main program for DESIGN II


/*
07/02/96 Lynn McGuire created
10/30/96 Lynn McGuire make child window wider
12/12/96 Lynn McGuire modify for new windowing scheme
02/25/99 Lynn McGuire new arguments for CAPSMN
01/26/01 Lynn McGuire up the buffer lengths
*/


#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <signal.h>

#include "winmain.h"

#include "..\..\bin\dii2vbas.h"


void myFloatingPointErrors (int signalNumber);


void mymain (char *programDirectory, char *inputFile, char *outputFile)
{
char string [4096];

sprintf (string, "DESIGN II Win32 %s %s", inputFile, outputFile);
SetWindowText (MainWindow, string);

strcpy (AboutTitle, "DESIGN II Win32");
strcpy (AboutMsg, "Copyright \251 1995-2001 WinSim Inc.\n"
"Copyright \251 1995 ChemShare Corporation\n"
"\n"
"WinSim Technical Support Can Be Contacted At:\n"
"\n"
"Phone & Fax USA 281-565-6700\n"
"Internet email sup...@winsim.com\n"
"Internet WebSite www.winsim.com");

// signal (SIGFPE, myFloatingPointErrors); // catch floating point errors

InitDesignII (inputFile, outputFile, ScreenOutputWindow);

ShutDownDesignII ();
}


void myFloatingPointErrors (int signalNumber)
{
// must reset the floating point handler
signal (SIGFPE, myFloatingPointErrors); // catch floating point errors
}

Lynn McGuire

unread,
Feb 9, 2015, 1:13:41 PM2/9/15
to
// screen.c (window version)
//
// for fortran to call to write ...'s to the screen


// 04/07/00 Lynn McGuire copy everything written to the screen to the
// output file also


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <windows.h>

#include "winmain.h"


// fortran character string in Watcom
typedef struct Descriptor
{
char *addr;
unsigned len;
} descriptor;


int numberOfScreenTaps = 0;


#pragma aux SCRBEG "^";
#pragma aux SCRTAP "^";
#pragma aux SCREND "^";
#pragma aux SCRREA "^";
#pragma aux SCRWRI "^";
#pragma aux SETSCREENOUTPUTWINDOW "^";

#pragma aux WriteLineToOutputFile "^";


#define KBFSIZE 256
#define AllowableChars " 0123456789abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\\|?,.<>`'\";:~!@#$%^&*()_+-="

HWND ScreenOutputWindow = NULL;
char keyboardBuffer [KBFSIZE];
int keyboardBufferSize = 0;
int totalCharactersWrittenToScreen = 0;
WNDPROC oldEditWindowProc = NULL;


LRESULT CALLBACK EditWindowProc (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam);


void SETSCREENOUTPUTWINDOW (int *screenOutputWindow)
{
if (*screenOutputWindow && *screenOutputWindow != -1112223334)
{
ScreenOutputWindow = (HWND) *screenOutputWindow;

if (ScreenOutputWindow)
{
// put my edit window proc first
oldEditWindowProc = (WNDPROC) SetWindowLong
(ScreenOutputWindow, GWL_WNDPROC, (LONG) EditWindowProc);
}
}
}


void SCRBEG (void)
{
numberOfScreenTaps = 0;
}


void SCRTAP (void)
{
if (numberOfScreenTaps > 60)
{
numberOfScreenTaps = 0;
writeLineToScreen ("");
}
numberOfScreenTaps++;
writeCharToScreen ('.');
}


void SCREND (void)
{
writeLineToScreen ("");
}


void SCRWRI (descriptor *desc)
{
char *p = desc -> addr;
int length = desc -> len;
// msg must be bigger than ScreenBuffer in termin.inc (add 1 for NULL)
char msg [10001];
int i = 0;
int blanks = TRUE;

msg [length] = '\0';
// dont write trailing blanks
for (i = length - 1; i >= 0; i--)
{
if ( ! blanks || p [i] != ' ')
{
msg [i] = p [i];
blanks = FALSE;
}
else
msg [i] = '\0';
}
writeLineToScreen (msg);
}


void SCRREA (descriptor *desc)
{
// msg must be bigger than ScreenBuffer in termin.inc (add 1 for NULL)
char msg [10001];
int length = 0;
int i = 0;
char *p = desc -> addr;
int oldLength = desc -> len;

readLineFromScreen (msg);
length = strlen (msg);
if (length > oldLength) length = oldLength;
// copy the user given data to the fortran character string
for (i = 0; i < length; i++) p [i] = msg [i];
// make sure that the rest of the fortran character string is blanks
if (oldLength > length)
for (i = length; i < oldLength; i++) p [i] = ' ';
}


// this function is to tell if the screen is a console or a window
int screenIsAWindow (void)
{
if (ScreenOutputWindow)
return TRUE;
else
return FALSE;
}


void writeLineToScreen (char *msg)
{
descriptor desc;
int len = strlen (msg);

if (ScreenOutputWindow)
{
char newMsg [256];

// add a carriage return and a line feed
sprintf (newMsg, "%s\r\n", msg);
totalCharactersWrittenToScreen += strlen (newMsg);
// move the cursor to the bottom of the text
SendMessage (ScreenOutputWindow, EM_SETSEL, -1, -1);
// actually write the string to the screen
SendMessage (ScreenOutputWindow, EM_REPLACESEL, 0, (LPARAM) newMsg);
SetFocus (ScreenOutputWindow);
MessageLoop ();
}
else
{
printf ("%s\n", msg);
fflush (stdout);
}

if (len > 0)
{
desc.addr = msg;
desc.len = len;
}
else
{
desc.addr = " ";
desc.len = 1;
}
WriteLineToOutputFile (&desc);
}


void writeCharToScreen (char aChar)
{
if (ScreenOutputWindow)
{
char msg [2];

msg [0] = aChar;
msg [1] = '\0';
totalCharactersWrittenToScreen++;
// move the cursor to the bottom of the text
SendMessage (ScreenOutputWindow, EM_SETSEL, -1, -1);
// actually write the chacter to the screen
SendMessage (ScreenOutputWindow, EM_REPLACESEL, 0, (LPARAM) msg);
SetFocus (ScreenOutputWindow);
MessageLoop ();
}
else
{
printf ("%c", aChar);
fflush (stdout);
}
}


void readLineFromScreen (char *msg)
{
if (ScreenOutputWindow)
{
int done = FALSE;
int msgSize = 0;
int i = 0;
// char msgmsg [256];

msg [0] = '\0';
while ( ! done)
{
char aChar = keyboardBuffer [0];

if (keyboardBufferSize > 0)
{
// sprintf (msgmsg,
// "msg is %s\n"
// "keyboardBufferSize is %d\n"
// "keyboardBuffer is %s",
// msg, keyboardBufferSize, keyboardBuffer);
// MessageBox (MainWindow, msgmsg, "readLineFromScreen",
// MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
if (aChar == VK_RETURN) // return key
{
done = TRUE;
writeLineToScreen ("");
}
else if (aChar == VK_BACK) // backspace
{
if (msgSize > 0)
{
msgSize--;
msg [msgSize] = '\0';
// go ahead and subtract one from total characters since
// the edit control is zero based
totalCharactersWrittenToScreen--;
// select the last character in the text buffer
SendMessage (ScreenOutputWindow, EM_SETSEL,
totalCharactersWrittenToScreen, -1);
// overwrite the last character on the screen
SendMessage (ScreenOutputWindow, EM_REPLACESEL, 0, (LPARAM) "");
}
}
else if (strrchr (AllowableChars, aChar))
{
writeCharToScreen (aChar);
msg [msgSize] = aChar;
msgSize++;
msg [msgSize] = '\0';
}
// strip the first character out of the buffer
for (i = 1; i < keyboardBufferSize; i++)
keyboardBuffer [i - 1] = keyboardBuffer [i];
keyboardBufferSize--;
}
MessageLoop ();
}
}
else
gets (msg);
}


int MessageLoop ( void )
{
MSG msg;
int rc = TRUE;

while ( PeekMessage( &msg, NULL, NULL, NULL, PM_NOREMOVE ) == TRUE )
{
rc = GetMessage( &msg, NULL, NULL, NULL );
if (rc == TRUE)
{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
}
Sleep (0);
return ( rc );

} /* MessageLoop */


LRESULT CALLBACK EditWindowProc(
HWND hwnd, /* window handle */
UINT message, /* type of message */
WPARAM wParam, /* additional information */
LPARAM lParam) /* additional information */
{
char msg [80];

switch (message)
{
case WM_CHAR:
// sprintf (msg, "%c %d, '\\n' is %d", wParam, wParam, '\n');
// MessageBox (MainWindow, msg, "got WM_CHAR msg in EditWindowProc",
// MB_APPLMODAL | MB_ICONINFORMATION | MB_OK );
if (keyboardBufferSize < KBFSIZE &&
(strrchr (AllowableChars, (char) wParam) ||
wParam == VK_RETURN ||
wParam == VK_BACK))
{
keyboardBuffer [keyboardBufferSize] = wParam;
keyboardBufferSize++;
keyboardBuffer [keyboardBufferSize] = '\0';
}
else
return CallWindowProc
(oldEditWindowProc, hwnd, message, wParam, lParam);
break;

Lynn McGuire

unread,
Feb 9, 2015, 1:14:10 PM2/9/15
to
// screen.c (console version)
//
// for fortran to call to write ...'s to the screen


#include <stdio.h>
#include <stdlib.h>


#define TRUE 1
#define FALSE 0


// fortran character string data structure
typedef struct descriptor
{
char *addr;
unsigned len;
} descriptor;


int numberOfScreenTaps = 0;


#pragma aux SCRBEG "^";
#pragma aux SCRTAP "^";
#pragma aux SCREND "^";
#pragma aux SCRREA "^";
#pragma aux SCRWRI "^";


void SCRBEG (void)
{
numberOfScreenTaps = 0;
}


void SCRTAP (void)
{
if (numberOfScreenTaps > 60)
{
numberOfScreenTaps = 0;
printf ("\n");
}
numberOfScreenTaps++;
printf (".");
fflush (stdout);
}


void SCREND (void)
{
printf ("\n");
fflush (stdout);
}


void SCRWRI (descriptor *desc)
{
char *p = desc -> addr;
int length = desc -> len;
char msg [1025];
int i = 0;
int blanks = TRUE;

msg [length] = '\0';
// dont write trailing blanks
for (i = length - 1; i >= 0; i--)
{
if ( ! blanks || p [i] != ' ')
{
msg [i] = p [i];
blanks = FALSE;
}
else
msg [i] = '\0';
}
printf ("%s\n", msg);
fflush (stdout);
}


void SCRREA (descriptor *desc)
{
char msg [1025];
int length = 0;
int i = 0;
char *p = desc -> addr;
int oldLength = desc -> len;

fgets (msg, 255, stdin);
length = strlen (msg);
// check for a line feed, if there get rid of it
if (msg [length - 1] == '\n')
{
length--;
msg [length] = '\0';
}
if (length > oldLength) length = oldLength;
// copy the user given data to the fortran character string
for (i = 0; i < length; i++) p [i] = msg [i];
// make sure that the rest of the fortran character string is blanks
if (oldLength > length)
for (i = length; i < oldLength; i++) p [i] = ' ';
}


void writeLineToScreen (char *msg)
{
printf ("%s\n", msg);
fflush (stdout);
}


void writeCharToScreen (char aChar)
{
printf ("%c", aChar);
fflush (stdout);
}


void readLineFromScreen (char *msg)
{
gets (msg);
}


void KILL_DII_WINDOW (int status)
{
// this function is used in the Window version of DII

// SendMessage (MainWindow, WM_CLOSE, 0, 0);
}


// this function is to tell if the screen is a console or a window
int screenIsAWindow (void)
{
return FALSE;
}


0 new messages