Please login or register.

Login with username, password and session length
gfx gfx
1617 Posts in 535 Topics by 779 Members - Latest Member: November 27, 2022, 08:09:11 PM
gfx* Home | Help | Search | Login | Register | gfx
Absoft User Forum  |  Support  |  Windows  |  MRWE Messages in colour

Author Topic: MRWE Messages in colour  (Read 6954 times)

Frances Rose Bauckham

  • Newbie
  • *
  • Posts: 12
MRWE Messages in colour
« on: June 20, 2007, 03:51:11 PM »
Just wondering if there is any easy method in producing colours on the MRWE screen.

The sort of application is to produce text (such as extreme values) in red or blue.   I notice that the editor, which I assume to be written in Absoft Fortran, does have coloured text.

Any information would be very useful please.

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: MRWE Messages in colour
« Reply #1 on: June 20, 2007, 08:03:46 PM »
Frances, thank your for your question. You would need to rewrite the MRWE screen-write routine to support color information. Not a huge challenge if you are familiar with Windows API, but if you have that level of sophistication, it would probably be easier to incorporate a text-box from a C++ package.

Mark Coxhead

  • Jr. Member
  • **
  • Posts: 82
Re: MRWE Messages in colour
« Reply #2 on: June 21, 2007, 04:04:43 AM »

As mentioned in the previous answer, you do need a certain level of sophistication and familiarity with windows programming.  At the time this was something I not have, and if my approach that I have outlined below appears convoluted you know the reason.    However what I have described does work and has been live in the user community since June 2004 – almost three years now, and no issues have been reported.   The result is that the users receive dialogue that not lost in masses of black text.

It is possible to write out complete lines in say RED, which may be warnings or to draw attention by highlighting results from calculations that are significant or exceptional.

I interface between the MRWE and an application program by a COMMON statement added in the file:

         integer TEXT_COLOR
         integer BK_COLOR
         common /TCOLOR/ TEXT_COLOR, BK_COLOR

To write, in the application program a line in say RED, I use the following code:

TEXT_COLOR = 5       (corresponds to the number in COLORS.INC)
WRITE (6,1000)
TEXT_COLOR = 1      (resets line back to BLACK, which is the default
1000   FORMAT(‘This line will appear in RED ‘)

Likewise for a RED background and WHITE text this is done by:

   BK_COLOR = 5
   TEXT_COLOR = 16
   WRITE (6,1001)
   BK_COLOR = 16   (reinstates background color to white)
   TEXT_COLOR = 1 (reinstates text to black)
1001   FORMAT(‘This line will be surrounded in RED, but is in white text’)

We have also changed the screen background color to yellow.   I will outline how to do this at the end.

Then within the module CHILD.F, under the case condition WM_PAINT you will need to undertake the following changes.   However, the important item to understand is that when a new line is written at the foot of the screen what actually happens is that entire screen is refreshed, each previous line moving up one line (if the bottom is reached).     

I therefore set up a large two-dimensional array:

        integer*4       col_index(MAX_LINES,2)     

which retains the colors used for previous lines.   There are two occurrences because one is used for text color, and the other for the background color.

Therefore within the DO LOOP

   Do i = first, last


If  i is a previous line that has been displayed hitherto, retrieve original value for both the text color and the background color.   Alternatively, if the line is a current/new line new use the colors specified in TEXT_COLOR and BK_COLOR respectively.    This was very fiddly to get correct, however I thought is would be better to describe the logic rather than give the lines of code (seventeen in all).

Then, just before the existing call TextOut statement:

If (TEXT_COLOR == 1) Call SetTextColor(val(dc), val(BLACK))
If (TEXT_COLOR == 2) Call SetTextColor(val(dc), val(BLUE))
If (TEXT_COLOR == 3) Call SetTextColor(val(dc), val(GREEN))
…………………………… etc ………………………………………

If (BK_COLOR == 1) Call SetBKColor(val(dc), val(BLACK))
If (BK_COLOR == 2) Call SetBKColor(val(dc), val(BLUE))
If (BK_COLOR ==3) Call SetBKColor(val(dc), val(GREEN))
…………………………… etc ………………………………………

These are the colors defined in the file.   We have actually defined several other alternative colors, as the yellow was too bright for instance.  The values of TEXT_COLOR and BK_COLOR being taken from the array col_index if they have been written previously.

I mentioned that there was a third component concerning coloring that it was possible to change, the screen color.   Work is done in the module INIT.F

Integer      hbrush
hbrush    =     CreateSolidBrush(VAL(LIGHTMAGENTA))

On the second of the three procedures to set up class information, mrwe_TextProc         = CS_VREDRAW .or. CS_HREDRAW .or. CS_DBLCLKS
            wc.lpfnWndProc   = loc(mrwe_TextProc)                    ! child
            wc.cbClsExtra    = 0
            wc.cbWndExtra    = 4
            wc.hInstance     = hInstance
            wc.hIcon         = LoadIcon(val(hInstance), val(IDR_MRWEDOC))
            wc.hCursor       = LoadCursor(val(NULL), val(IDC_IBEAM))
*           wc.hbrBackground = GetStockObject(val(WHITE_BRUSH))     ! comment out
wc.hbrBackground = hbrush                                ! new code            wc.lpszMenuName  = 0
            wc.lpszClassName = g_ChildName

General comment:  What this solution does not achieve is to write out parts of lines in different colors.     I am sure this is achievable, however is probably complex.   As you say the Absoft editor uses alternate colors for key/reserved words and functions.    The issue involves establishing the co-ordinates of the part-string and keeping track of the colors used as the line scrolls up the screen.

Hope this helps.

Mark Coxhead.

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: MRWE Messages in colour
« Reply #3 on: June 21, 2007, 04:21:56 AM »
Thanks, Mark. You posted something similar on the old Forum, but it was lost in the switch-over. So appreciate your posting this again ... ;D

Absoft User Forum  |  Support  |  Windows  |  MRWE Messages in colour

gfx gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!