Multi form application message handling.

Started by Francisco Dom, January 07, 2015, 03:14:08 PM

Previous topic - Next topic

Francisco Dom

Hi all,

This is my first post in this forum and  although I always tried to learn by myself instead of asking at the first obstacle, right now I am absolutely blocked. I am a totally beginner with FireFly and even with PowerBasic. In fact I decided to purchase FF because coming from VB4, the lack of a form editor in PowerBasic made me think I will never progress with PB. Happily, FireFly come to the rescue and now I am able to write some small programs for personal use.

Now I am writing a program that collects data from 3 diferent test instruments through GPIB with a main control Window (form created in the FireFly IDE) that under user request creates new windows inside a class using the PowerBasic command "Graphic Window New" to plot the data acquired from the instruments.

The "Graphic Window New" function has a parameter that specifies the height and width of the window that is going to be created. I managed to change the Window Style to make it resizable with the mouse but now I need the graph that is plotted in that window to be plotted again to fit the new window dimensions if the user changes its size.

I suppose that in order to do that I need to write a function that is called when a WM_SIZE message is detected. The question is that as this plot window has not been created with a form in the FF Form Editor I don't know where the message loop for the plot window is located. So, where I should call the "Replot" function?

Could you give me some advice about this?

This is are some parts of the Class code:


Class cMeasurement

Instance MeasName As String
Instance PlotWidth As Long
Instance PlotHeight As Long
Instance PlotXPos As Long
Instance PlotYPos As Long
Instance hPlot As Long
 

Class Method Create()
   MeasName = "Test of Plot Window."
 
   PlotWidth=400
   PlotHeight=400
   PlotXPos=200
   PlotYPos=200
   End Method

Interface iMeasurement   
      Inherit IUnknown            ' inherit the base class

   
Property Get MeasName As String
   Property =Trim$(MeasName)
   End Property
Property Set MeasName(Caption As String)
   MeasName=Caption
   End Property




Method Plot As Long
   Graphic Window New MeasName, PlotXPos, PlotYPos, PlotWidth, PlotHeight To hPlot   
   Graphic Window Nonstable  hPlot
   ChangeWindowStyle( hPlot, %WS_OVERLAPPEDWINDOW )
   
   Graphic Attach hPlot, 0 ', ReDraw
   Graphic Box (0, 0) - (PlotWidth, PlotHeight), 0, %Red
   Graphic Line  (0, 0) - (PlotWidth, PlotHeight), %Red
   Graphic ReDraw
   'FF_Control_ShowState( hPlot,  %SW_MAXIMIZE  )
   End Method     
   
End Interface

End Class         


And this is where the Class "Plot" function in a button click event in the main form is called:



'--------------------------------------------------------------------------------
Function FRMCONFIGMEASUREMENT_COMMAND1_BN_CLICKED ( _
                                                  ControlIndex     As Long,  _  ' index in Control Array
                                                  hWndForm         As Dword, _  ' handle of Form
                                                  hWndControl      As Dword, _  ' handle of Control
                                                  idButtonControl  As Long   _  ' identifier of button
                                                  ) As Long
Measurement =Class "cMeasurement"
Dim Measurement As iMeasurement

Measurement.Plot
End Function



Any help and/or suggestion will be welcome.

Best regards.

Fran Dominguez

David Kenny

Fran,

Welcome to the forum!

First question for you...  how many of these graphic windows might you open in an instance of your main program?

Elias Montoya

 Hello Francisco.

There is a feature in firefly (Work space > Properties) to handle automatically the resizing of controls. See image below.



Once the resizement is handled by the IDE, you only need to trap the WM_SIZE message of your
canvas, like this:



Then, just add the re-plotting code in there.

Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

David Kenny

The resizing rules are available to controls on FF generated forms (without some creative programming).  I am trying to figure out what the needs of the program are so I can offer suggestions that will likely enable Francisco to use FF generated forms.


Elias Montoya

Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

David Kenny

Sorry Elias, what I am saying is that right now, Francisco is using the PB statement "Graphic Window New" which creates (at runtime of course) a non-FF window (meaning no ResizeRules option).  How many of these windows a user can launch per instance of the program is information I would like before recommending a FF-form-only solution.

If the answer is one, then he just creates one in FF and opens that form when the user asks for it.  If the user can open multiple forms, then it might make sense to use FF's new feature that enables multiple instances of one form.  With the second option there are some things you have to consider when creating multiple forms. I can go into more detail if needed.

There is a third option, to just enforce a maximum-number of these user launched forms and create a separate form for each possible instance.  This option would mean the total cost to overhead would be overhead-of-one-form * Maximum-number-of-forms. Each instance of his program would incur that extra overhead even if the user only opened only one form.  Not a very elegant option, in my opinion.

Francisco Dom

Thanks to everybody for your answers!!

Elias,

thanks for your suggestion. I already know how to resize and respond to WM_SIZE in a form created in the FF IDE but the forms I am talking about are created at runtime, not a design time.


David,

the program has not a fixed numbers of plots to be created, it depends on what measurements of the RF Power Amplifier under test the user is interested to get: Pout vs. Pin, Pout vs. Icc, Pout vs. Vbias, etc... That is the reason for me to not create the plot window in the form editor but with "Graphic New Window" function inside de "cMeasurement" Class, I don't know how many plots he is going to create.

The problem is that I don't know where to respond to messages of those runtime created windows as there is not the corresponding event manager function in the FF IDE at design time.
You can have a look at the main control window in the attached files (sorry I am not able to embed images in the post. Any hint?)

There is a ComboBox to select the X-Axis variable to act on and Y-Axis left and right measurement results to be acquired from instruments. Once you select the required plot/plots they are added in a  ListView control. Once you finished to define what measurements you are interested in, a start button will call a function that will cycle through the ListView entries and will create "cMeasurement" object that will acquire the data and plot the results.

At the beginning of the software design phase I though about using MDI inside a tab to show all the measurements but as I started reading about MDI I realized it looked complicated for a beginner like me.

I suspect the way to act on those plot window messages is related to using DefWndProc and WndProc and if that is the case it loos too complicated for me and I'll have to search for a simpler solution. As I told, I am starting in the wonderful world of FF and PB and there are so many things to learn.....


Thank you for your support.

Fran Dominguez


Paul Squires

Hi,

I am just starting to look at this. I expect that using the Firefly Graphic Control embedded on a Firefly Form would be easier, however you could try subclassing the GRAPHIC WINDOW:


Global hPlot As Dword


Function GraphicSubClassProc( ByVal hWndControl As Dword, _
                          ByVal wMsg   As Dword, _
                          ByVal wParam As Long, _
                          ByVal lParam As Long _
                          ) As Long
   
   Select Case wMsg
      Case %WM_SIZE
          Static p As Long
          Incr p
          FF_Control_SetText HWND_FORM1, "wm_size" & Str$(p)
     
      Case %WM_DESTROY
          FF_SubClassEnd hWndControl
          Exit Function
   End Select   

   Function = FF_SubClassOrig( hWndControl, wMsg, wParam, lParam )
           
End Function


'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     As Long,  _  ' index in Control Array
                                   hWndForm         As Dword, _  ' handle of Form
                                   hWndControl      As Dword, _  ' handle of Control
                                   idButtonControl  As Long   _  ' identifier of button
                                   ) As Long
   
   Graphic Window New "Graph", 300, 300, 130, 130 To hPlot   
   Graphic Window Nonstable  hPlot
   'ChangeWindowStyle( hPlot, %WS_OVERLAPPEDWINDOW )
   
   AfxAddWindowStyle hPlot, %WS_OVERLAPPEDWINDOW
   
   FF_SubClassStart hPlot, CodePtr(GraphicSubClassProc)
   
   Graphic Attach hPlot, 0 ', ReDraw
   Graphic Box (0, 0) - (130, 130), 0, %Red
   Graphic Line  (0, 0) - (130, 130), %Red
   Graphic ReDraw
   
End Function

Paul Squires
PlanetSquires Software

Robert Eaton

Francisco,
I'm unsure if this will be helpful or not.
I wrote a program that also needed a plotting function (and sizes with the form). I was also collecting data and displaying it.
In this case it was created as a custom control that was added at run time (if a recall correctly  ::) , it's been a while since I looked at it.)
Using that method I was able to send messages to it to change the scale, plot curves to it, etc.

Although I didn't use multiple forms, that method might be useful.
A sample program is near the bottom of this post. Called "fgrid".

http://www.planetsquires.com/protect/forum/index.php?topic=2020.0

Francisco Dom

#9
Hi Paul,

thank you so much for your kind support and interest.

Quote from: TechSupport on January 08, 2015, 10:57:30 AM
Hi,

I am just starting to look at this. I expect that using the Firefly Graphic Control embedded on a Firefly Form would be easier, however you could try subclassing the GRAPHIC WINDOW:


Wow....maybe too much level for a not real programmer like me...Subclassing!!!

I must have a more detailed look trying to understand what you are suggesting.

Suppose I use a FireFly Graphic Control embedded on a FireFly Form, the problem here is I don't know at design time how many "graphic controls"/"Plots"/"Graphic Windows" will the user decided to get. Now the software works creating as many Graphic Windows as needed and I am able to Plot on it, the only problem I have is to "replot" the graph if the user decides to change the window graph dimension in order to have a more detailed look at the plot results.

I already wrote an application in FireFly 3.10 wich plots data acquired from serial port using a Power Basic Graphic embedded in the unique form the software has that has been created in the FF Form Editor.

The new software that I am writing now is by far more complicated: any number of GPIB converters can be used, you can assign the virtual Comm Port and GPIB address to each of the 3 instruments that are used and you can select any number of measurements you want.
Maybe the software architecture I decided to use for this application is not the best one and that is why I am asking for suggestion provided that:

1.- At design time it is unknown how many graphs are needed.
2.- The graphs should resizable.
3.- The graphs should respond to WM_CONTEXTMENU messages in order to the user can save the graph plots or measurement data to disk.

The only options that crossed my mind were:

1.- Create an MDI form as a child of a Tab control in the Main program control form. I don't know if windows allows that.
2.- Create as many Graphic Windows as the user requests.
3.- Create an MDI window separated from the Main program control form. But I still have the same problem of know where the message loop of the MDI window is located with the added complexity of using MDI.

What do you think? Is there a more obvious approach I overlooked?

Best regards.

Fran


Francisco Dom

#10
Hi Robert,

thanks for answering.

QuoteI'm unsure if this will be helpful or not.

Any comment is helpful by itself because it makes me to learn the way someone solves their problems.


QuoteIn this case it was created as a custom control that was added at run time (if a recall correctly  ::) , it's been a while since I looked at it.)
Something similar is what I done creating a Custom Control with a PB Graphic Control embedded in FF3.10. I was plotting the 1000 RF power samples per second sent via serial port from a RF Power Meter I designed. Have a look at the attached file. I think both you and I, used similar approach to plot the results of our RF test instruments.
I see you also work with RF Instruments...

Quote
A sample program is near the bottom of this post. Called "fgrid".
http://www.planetsquires.com/protect/forum/index.php?topic=2020.0

Nice interface.....I see you used Log freq axis. Maybe EMC measurements?

Once again. Thank you so much for the link with your source code and comments.

Best regards.

Fran

Robert Eaton

Hi Francisco,
You're right. It was for some EMC testing for microphones. The program drives an RF generator through a GPIB port and the signals are returned using and Audio Precision analyser.
However, most of what I do is audio frequency range. I've used that control since in a production test fixture.

Paul Squires

Hi Fran,

I am putting together a little example project to show one way of creating a multiple form project for all of your spawned graphic windows. I am using Jose's CGDIPlus.inc class for GDI+ along with Firefly's built in GraphicControl (which is also based on Jose's graphic control). Using these tools you will have full control over form resizing without subclassing. I'll post it as soon as it's done so others can jump in with comments. I don't normally create programs with GraphicControl stuff so others will probably be better equipped to critique my approach.

Paul Squires
PlanetSquires Software

Elias Montoya

Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Francisco Dom

Hi Paul,

QuoteI am putting together a little example project to show one way of creating a multiple form project for all of your spawned graphic windows.

Wondeful but...take care!! Otherwise we can get used to someone to do our homework.  ;)

Jokes apart, that will be a great help. Thanks again.
Anyway as my goal is to learn I will investigate and try some code "playing" with DefWndProc and WndProc as I think that it can be an aproach as well. Am I right?

Best regards.

Fran