coding UTF-8; // Load required libraries import GUI; import File; import Process; // Declare global variables together for storing GUI component IDs int window = NULL; // Window int aField = NULL; // Input field for value A int aLabel = NULL; // Label for value A int bField = NULL; // Input field for value B int bLabel = NULL; // Label for value B int cField = NULL; // Input field for value C int cLabel = NULL; // Label for value C int runButton = NULL; // Run button int outputArea = NULL; // Output display area int outputLabel = NULL; // Label for the output area int errorArea = NULL; // Error display area int errorLabel = NULL; // Label for the error area // Program execution starts here (entry point) void main() { // Build the GUI components and create the window initGUI(); // Hide the VCSSL console (black window) because it is not used hide(); // Startup processing ends here. // Processing when the button is clicked starts from the // onButtonClick event handler and reaches executeExternalProgram() // near the end of this code. } // Function that builds the GUI components and creates the window void initGUI() { // Create the window // Arguments: top-left X, Y, width, height, window title window = newWindow(0, 0, 540, 530, "GUI Wrapper Window"); // Create and place the input field and label for value A // Arguments: top-left X, Y, width, height, label text or default value aLabel = newTextLabel(10, 10, 50, 30, "Value A:"); aField = newTextField(60, 10, 450, 30, "aaa"); mountComponent(aLabel, window); mountComponent(aField, window); // Create and place the input field and label for value B bLabel = newTextLabel(10, 50, 50, 30, "Value B:"); bField = newTextField(60, 50, 450, 30, "bbbb"); mountComponent(bLabel, window); mountComponent(bField, window); // Create and place the input field and label for value C cLabel = newTextLabel(10, 90, 50, 30, "Value C:"); cField = newTextField(60, 90, 450, 30, "ccccc"); mountComponent(cLabel, window); mountComponent(cField, window); // Create and place the Run button runButton = newButton(10, 130, 500, 50, "Run"); mountComponent(runButton, window); // Create and place the output display area and label outputArea = newTextArea(10, 220, 500, 150, ""); outputLabel = newTextLabel(10, 200, 500, 20, "Output:"); mountComponent(outputArea, window); mountComponent(outputLabel, window); // Create and place the error display area and label errorArea = newTextArea(10, 400, 500, 80, ""); errorLabel = newTextLabel(10, 380, 500, 20, "Error:"); mountComponent(errorArea, window); mountComponent(errorLabel, window); // Redraw the screen paintComponent(window); } // Event handler function called when a button is pressed void onButtonClick(int id, string text) { // If the pressed button is the Run button, execute the program if (id == runButton) { executeExternalProgram(); } // If there are other buttons as well, handle them in an if statement like above } // Execute the external C program "program.exe" using the values entered on the screen as parameters void executeExternalProgram() { // Get the absolute path of the C program file to execute string programPath = getFilePath("program.exe"); // Prepare an array to store the command used to launch the C program string commandWords[4]; // Put the absolute path of the program to run in the first element commandWords[0] = programPath; // The remaining elements are parameter values passed to the program, so get them from the screen commandWords[1] = getComponentText(aField); // Input value A commandWords[2] = getComponentText(bField); // Input value B commandWords[3] = getComponentText(cField); // Input value C // Prepare the program in an executable state (passing the command prepared above here) int processID = newProcess(commandWords); // If the program outputs Japanese or other multibyte text, // specify character encoding to avoid garbled output // (If this causes garbling instead, try specifying "UTF-8" and so on) // --- // setProcessInputEncoding(processID, "CP932"); // setProcessOutputEncoding(processID, "CP932"); // setProcessErrorEncoding(processID, "CP932"); // Run the program and wait for it to finish startProcess(processID); waitForProcess(processID); // Get the program output and display it on the screen string outputContent = getProcessOutput(processID); setComponentText(outputArea, outputContent); // Get the program error output and display it on the screen string errorContent = getProcessError(processID); setComponentText(errorArea, errorContent); } // Event handler function called when the window is closed void onWindowClose(int id) { // End execution of this VCSSL program exit(); }