|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Thu Mar 12, 2015 9:32 pm Post subject: |
|
|
here's A Modified code .... which will appear below after this chitter-chat ......
I've:-
a) taken the 2nd window definition (previously in the call-back from the string control in the first window) and put it in Main underneath the first window definition.
[NOTE - that the %gr I have changed NOT to call a handle, I tried it but got an odd Run-time Error message "Unused arguments on winio@ call (continuation 2)" which is the %gr call for Win 2 (hwnd_sep_plot). Try it by commenting out the %gr&%lw and un-commenting the 3 lines at the bottom. I can't figure out why this occurs, but it did also when I had the definition of this Window inside the call-back function - but strangely there I got text in the window ! - probably defaulting to the last defined %gr area in absence of a valid handle maybe?]
b) made the %gr ID's variables more logical by re-naming, added better %ca descriptions for each and changed the backgound colour of window 1 and also of the text to be different colour for each sindow (red (_win1) and green (win 2)).
I've also put in 'print' 's to check the values of the handles of the 2 gr's just before the DRAW_CHARACTERS calls.
c) left the 2 graphics write's in the call-back to the string control, modified with the necessary SELECT_GRAPHIC_OBJECT and GRAPHIC_UPDATE calls before/after.
Now, here's the interesting bit (aka - another puzzle ! (or 'devilry' as DanRRight would say )
If you run the program you'll see:-
a) program opens with both %gr's 'blank'
b) after clicking on 'Write' button, a window will pop up with the values of the %gr handles - all seems correct here, 11 for Win 1 and 12 for Win 2). I thought at first that still I had the problem, but then I saw that the string is actually written to the first window !!!! ... albeit, i) very small , ii) in BLACK !
(Note - I thought maybe the non-appearance in the earlier version may have been because it was putting black-on-black but I checked by changing the colour of the %gr in the earlier code and it didn't write it .)
c) click on 'WRITE' again and the text is re-written, in the correct intended size (tick v.g.) but still in BLACK, when it should be in RED ! Strange.
d) NOTHING now in the 2nd window.
I'm still convinced there's some restriction of some kind about cross-writing data from one control's call-back (associated with one window) to a graphic window in another.
I'll play now around with some other changes (such as taking the GRAPHICS WRITE CALLS out into a seperate Subroutine, etc ...... but having replaced one problem with what appears to be another, I go ahead without much confidence....
In the meantime, Any other ideas anyone about what stange happenings I'm seeing now ?
Why is that text now appearing so amall on first click ? Why black and not the colour specified ? (no doubt picking up some 'default' somewhere - but from where and why ?) ... and why is that error occurring if I try to put a handle (as it were) on the 2nd graphics window ?
My eyes tell me its Dan-devilry, but my brain, in its experience, says it's a very small stupid mistake somewhere. |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Thu Mar 12, 2015 9:34 pm Post subject: |
|
|
... and the modified code is .....
Code: | module mod1
character(50) str
integer hwnd,left,right
integer left2,right2
integer w_win, h_win
integer hwnd_str,hwnd_plot,hwnd_sep_plot
integer i_act_win2
integer h_win1,h_win2
contains
!______________________________________________________________________________
integer function cb()
use mswin
integer i, j,ii
ii = SendMessage(hwnd_str,EM_GETSEL,loc(left),loc(right))
ii = SetFocus(hwnd_str)
left2=left+1
right2=right+1-1
!hwnd_plot=11
!hwnd_sep_plot=12
!if(i_act_win2.eq.0) then
!
! Win 2 setup was here, now in Main
!
!endif
i_act_win2=1
!--- Select Windows font
CALL select_font@('Arial')
! CALL CHOOSE_FONT@(RGB@(255,0,0))
CALL scale_font@(3.0D0)
print *,'just before Drawing to Window 1 (hwnd_plot)'
print *, 'hwnd_plot (Win 1), hwnd_sep_plot (Win 2) =',hwnd_plot,hwnd_sep_plot
i=SELECT_GRAPHICS_OBJECT@(hwnd_plot)
CALL DRAW_CHARACTERS@(str(left2:right2),50,100,RGB@(255,0,0))
CALL PERFORM_GRAPHICS_UPDATE@(hwnd_plot)
print *,'Drawing to Window 1 (hwnd_plot)COMPLETE'
print *,'just before Drawing to Window 2 (hwnd_sep_plot)'
print *, 'hwnd_plot (Win 1), hwnd_sep_plot (Win 2) =',hwnd_plot,hwnd_sep_plot
i=SELECT_GRAPHICS_OBJECT@(hwnd_sep_plot)
CALL DRAW_CHARACTERS@(str(left2:right2),50,100,RGB@(0,255,0))
CALL PERFORM_GRAPHICS_UPDATE@(hwnd_sep_plot)
print *,'Drawing to Window 2 (hwnd_sep_plot)COMPLETE'
cb = 1
end function
end module
!________________________________________________________________________________________
winapp
program sel
use mod1
integer i,winio@
i_act_win2=0
hwnd_plot=11
hwnd_sep_plot=12
str = "BOLDly going where no program has gone before"
w_win=600 ! Width of window for character string
h_win=100 ! height of window for character string
i=winio@('%ww%ca[Window 1]&')
i=winio@('%mn[&Exit]&','EXIT')
i = winio@("%nl%cn%^bb[Write Title]&", cb)
i = winio@("%2nl%cn%rs[keep_focus]&", str)
i = winio@("%lc&", hwnd_str)
i = winio@("%nl%cnLeft:%2rd&", left2);
i = winio@(" Right:%2rd&", right2);
!i = winio@("%nl%gr[black]&",w_win,h_win)
!i = winio@("%lc", hwnd_plot)
i = winio@("%nl%`gr[blue]&",w_win,h_win,hwnd_plot)
i=winio@('%lw',h_win1)
!**********************************************************************
! SET UP SEPERATE GR WINDOW TEMPORARILY
!
! INTEGER j
!--- Graphics window
j=winio@('%ww%ca[WINDOW 2]&')
j=winio@('%mn[&Exit]&','EXIT')
j=winio@('%gr[white,rgb_colours]&',w_win,h_win)
j=winio@('%lw',h_win2)
! j=winio@('`gr[white,rgb_colours]&',w_win,h_win,hwnd_sep_plot)
! j = winio@("%lc&", hwnd_sep_plot)
! j=winio@('%lw',h_win2)
!***********************************************************************
end program |
|
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Sat Mar 14, 2015 12:11 am Post subject: |
|
|
John,
I can't follow the scoping rules of modules, so this is inhibiting my ability to help, but: if you have a %gr without a handle ten you can access it after it is created, but if you move to a different %gr you can never go back to the one without a handle.
PERFORM_GRAPHICS_UPDATE@() shouldn't have a parameter - it should work on the current %gr. I made a mistake, but as it seemed to work I left it in. Maybe it's an undocumented feature.
You need the apostrophe qualifier to %gr when you supply a handle to it and ^ when you have a callback.
In my example, you could easily write to both graphics areas in the callbacks, but I was conscious of space.
Eddie |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Sat Mar 14, 2015 6:57 am Post subject: |
|
|
Eddie, thnks again for the suggestions.
I understood completely about needing the handles on both windows, but,
As I explained (probably very badly) at the top of my last post I did try to put the apostophe on the %gr and give it a handle but when I did that I get the ""Unused arguments on winio@ call (continuation 2)" error ! and I couldn't work out what argument it was referring to, unless it's the handle !?!
Strange. It can be tried by uncommenting the last 3 commented lines in Main and commenting out the preceding 2 lines.
Maybe someone could shed light on that strange behaviour and fatal error just by adding a handle to the second %gr ?
In fact it's all very strange (especially the shock of seeing the first small print on the first write to the first Window then correct bigger size fonts afterwards on subsequent clicks.
I am inclined like you to think it's something to do with some scoping limitations connected to modules when using CLEARWIN maybe. I'll have to re-formulate the code to try it out in 'classic FORTRAN77 style' similar to yours and will report back.
Meanwhile I guess the question is for Paul L. , is there anything in particular concerning MODules Paul which might affect/be the cause of this problem ???
Documentation concerning MODules in relation to CLEARWIN+ seems to be a bit scarce on the ground. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Sat Mar 14, 2015 11:44 am Post subject: |
|
|
As I readily confess, I'm a dinosaur in the Fortran world (and not a big or aggressive one) and the only reliable ways I know to pass any variables between routines are via common or through subroutine arguments - so my limitation.
When I put the grave modifier and the %gr handle in to this line in your demo:
Code: | j=winio@('%`gr[white,rgb_colours]&',w_win,h_win,hwnd_sep_plot) |
I got the text in green in the second window, so I don't know what you did wrong. You say 'apostrophe', but it I use a straightforward apostrophe instead of the correct modifier I don't get 'unused arguments', instead I get 'unterminated character constant'.
Your last 3 commented lines have a %lc with the hwnd_sep_plot, and this is a serious problem, because for %gr you give the handle value, and for %lc Windows/Clearwin+ gives you the handle value, thus overwriting the 12 that hwnd_sep_plot should contain, and I'm not sure of the relevance of the returned value anyway.
I wrote a post a long time ago, "When is a handle not a handle?" and with the benefit of the passage of time I sort of understand it now. There are 2 types of handle, those you give (e.g. for %gr) and those you receive (e.g. %lc and %lw and %hw). Muddle them up at your peril!
Eddie |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Sat Mar 14, 2015 6:11 pm Post subject: |
|
|
It is difficult for me to sort this out as I am out of office without a laptop.
I can see a gr without a percent before it and I can see more than one mis-applied %gr handle.
A %gr handle should appear as a fixed value that you supply in the program. It could be a literal constant (e.g. 42) or an integer parameter (e.g. integer,parameter::han=42). You choose the value (instead of 42).
I hope this helps. I am not that good at sending messages from a tablet. |
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Sun Mar 15, 2015 10:55 am Post subject: |
|
|
grave accent " ` " not apostrophe " ' " |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Sun Mar 15, 2015 12:35 pm Post subject: |
|
|
Yes I know that Ian, thanks, and I have a grave accent in the %gr in my MAIN.
Eddie, I 'said' apostrophe because that's what you wrote in one of your comments above ! :O)
Still, useful that you tried it because:-
a) the error message you got I recognized from my earlier code problems where I did have an apostrophe ! (I think I'd tried it and subsequentley just commented it out there. Anyway it's fixed noe
b) along the way to that, when I put in the grave accent I FOUND MY STUPID ERROR ! (remember above I said it had to be something simple).
Look carefully and you'll see that ..... wait for it ..... in the %gr which is in the call-back function, when I put in the 'aposstrophe' I also deleted the % !!!!!!
HOWEVER, having corrected all that, I still don't get any text in the Win 1 (the hwnd_plot one) !
and the text which was for some mysterious reason appearing previously in Win 1 (with the code errors), albeit initially at the wrong size and in BLACK (still no explanation for that) , is now only appearing at the wrong size ! and not changing to the correct size at the second click as it was previously
I'm off to experiment further. At least I got rid of the odd errors, thanks to your suggestions. |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Mon Mar 16, 2015 3:49 am Post subject: |
|
|
OK, problems resolved:
a) text obtained in both boxes now - I made sure for both CHARACTER_DRAWs that:
i) in the callback function that the fonts definition commands are made for for each window and are AFTER the SET_GRAPHICS_OBJECT command for each window. I've been worjìking on the basis that if you set them all first then they become the 'current active' settings and that they'll be picked up for any susequent drawing commands. They're not.
ii) in the WINdow 1 definition that rgb_colours was set in the call to %gr !
I'd taken that out as a test at some stage in the evolution of trying to solve the other problems. Shouldn't make a difference though should it, I thought the default was rgb_colours since last July ? Doesn't seem to be for %gr though.
I've tidied up, re-arranged the code now as follows, and it works as I wanted it to , note I've switched the Windows creation around with Window 2 now being the higher level one and it's call-back function including the one for the string .
I now just have to go ahead and work out how to do the overwriting of the string 'titles' when the user changes it, probably the simplest way by first overwriting the existing text with a rectangle the same colour as the %gr background colour.
I'll also 'nest' the string entry window (Win1) into the other window using frames and add some string formatting functions.
Lessons learned:
a. always define/ask for handles for all windows and drawing surfaces and keep track of what they correspond to !
b) when using the graphics routines, always set parameters relating to fonts FOR EACH drawing surface seperately, even if they're the same !
c) check all %'s are where they should be and grave accents are not apostophes !
In the context of what I've been doing, it seems there are no issues with using either MODules nor cross-calling of drawing surfaces between functions, etc, ...
Thanks to everyone for your help and patience so far.
Here's the new working code (V3) to date:
Code: |
module mod1
character(50) str
integer hwnd,left,right
integer left2,right2
integer w_win, h_win
integer hwnd_str,hwnd_plot,hwnd_sep_plot
integer i_act_win2
integer h_win1,h_win2
integer col_1,col_2
contains
!______________________________________________________________________
integer function cb()
use mswin
integer i, j,ii
ii = SendMessage(hwnd_str,EM_GETSEL,loc(left),loc(right))
ii = SetFocus(hwnd_str)
left2=left+1
right2=right+1-1
i_act_win2=1
col_1=RGB@(255,0,0)
col_2=RGB@(0,255,0)
! Graphics write to Window 1
i=SELECT_GRAPHICS_OBJECT@(hwnd_plot)
print *,'just before Drawing to Window 1 (hwnd_plot)'
print *, 'hwnd_plot (Win 1), hwnd_sep_plot (Win 2) =',hwnd_plot,hwnd_sep_plot
!--- Select font
CALL select_font@('Arial')
CALL scale_font@(3.0D0)
!--- Draw String
CALL DRAW_CHARACTERS@(str(left2:right2),50,100,col_1)
CALL PERFORM_GRAPHICS_UPDATE@(hwnd_plot)
print *,'Drawing to Window 1 (hwnd_plot)COMPLETE'
! Graphics write to Window 2
i=SELECT_GRAPHICS_OBJECT@(hwnd_sep_plot)
!--- Select font
CALL select_font@('Times')
CALL scale_font@(3.0D0)
!--- Draw String
CALL DRAW_CHARACTERS@(str(left2:right2),50,100,col_2)
i=SELECT_GRAPHICS_OBJECT@(hwnd_sep_plot)
CALL PERFORM_GRAPHICS_UPDATE@(hwnd_sep_plot)
print *,'Drawing to Window 2 (hwnd_sep_plot)COMPLETE'
print *,'just after Drawing to both Windows completed'
print *, 'hwnd_plot (Win 1), hwnd_sep_plot (Win 2) =',hwnd_plot,hwnd_sep_plot
cb = 1
end function
!______________________________________________________________________
integer function cb2()
use mswin
integer i, j,ii
|
Last edited by John-Silver on Mon Mar 16, 2015 3:56 am; edited 3 times in total |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Mon Mar 16, 2015 3:52 am Post subject: |
|
|
... .damn posting limit ! :O)
here's the rest !
Code: |
!********************************************************
! SET UP WINDOW 1
i=winio@('%ww%ca[Window 1]&')
i=winio@('%mn[&Exit]&','EXIT')
i=winio@("%nl%cn%^bb[Write Title]&", cb)
i=winio@("%2nl%cn%rs[keep_focus]&", str)
i=winio@("%lc&", hwnd_str)
i=winio@("%nl%cnLeft:%2rd&", left2);
i=winio@(" Right:%2rd&", right2);
i=winio@("%nl%`gr[white,rgb_colours]&",w_win,h_win,hwnd_plot)
i=winio@('%lw',h_win1)
!**********************************************************************
cb2 = 1
end function
end module
!________________________________________________________________________________________
winapp
program TitleWrite_V3
use mod1
integer i,j,winio@
i_act_win2=0
hwnd_plot=11
hwnd_sep_plot=12
str = "BOLDly going where no program has gone before"
w_win=600 ! Width of window for character string
h_win=100 ! height of window for character string
!
! SET UP another SEPERATE GR WINDOW TEMPORARILY
! WINDOW 2
!--- Graphics window
j=winio@('%ww%ca[WINDOW 2]&')
j=winio@('%mn[&Exit]&','EXIT')
j=winio@("%nl%cn%^bb[Write Title]&", cb2)
j=winio@('%`gr[white,rgb_colours]&',w_win,h_win,hwnd_sep_plot)
j=winio@('%lw',h_win2)
!***********************************************************************
end program |
|
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Tue Mar 17, 2015 2:01 pm Post subject: |
|
|
The issues with Modules are in my head, not in the compiler!
Setting up all the things like font and character size etc are best done in a subroutine that you call immediately after SET_GRAPHICS_OBJECT@, then you don't forget any. You can do something similar with Clearwin+ windows for background and style etc - WINIO@ commands can be strung across subroutines.
Eddie |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|