Login Page - Create Account

Support Board


Date/Time: Wed, 15 May 2024 16:08:16 +0000



Post From: Using Visual Studio C++ to create Custom Studies

[2020-11-30 10:56:20]
User310645 - Posts: 49
I have a framework I use to start studys that have GUI controls which basically handles the SC lifecycle functions (Init, SetDefaults, CleanUp) for each study.
I'm not going to post all of that as I don't want to distract from the matter in hand which is just creating the UI components.

The Study is also responsible for creating the study and storing it in a sc.SetPeristentPointer as we don't want to recreate the components on each run and
destroying everything when done (sc.LastCallToFunction).

I see 3 main ways to create GUI components:

1) Use the SC callback sc.GDIFunction which is basically a hook into the main forms WM_PAINT event that allows you to draw your own GDI graphics directly onto the study
  This is how the example posted worked with the power meter simply being ::GradientFill() rects rendered to the HWND of the study and new window.  
2) Use common controls (EditBoxes, Combo, Buttons etc) which can be drawn directly onto the study
  As the controls are using the parent windows WNDPROC for message processing you will need to implement subclasses to handle any events the control might generate.
  You will need to link to comctl32.lib/#pragma comment(lib,"commctl32.lib") and call ::InitCommonControls() somewhere in the Init() of the study.

3) Create a new window and handle your own messages
  For most cases you could probably get away with creating a blank study with all scales/scrollbars/draw types removed and use a combination of 1) and 2).
  This way is likely to yield better results as the window will play nicely with the SC infrastructue.
  If you really want to create your own window bear in mind you will need to handle all the windows message pump events yourself and will be on your own outside of SC.

It must be noted that there is nothing special about 2) and 3) in relation to SC. These are just standard API calls that you would perform in any windows app using GDI.

I've attached a couple of stripped down files that hopefully will help.

DialogForm.cpp shows an implementation of my Study class which just sets up a simple dialog with 2 text boxes (that have attached labels) and a button. On clicking the button
the value of an input parameter on another chart is updated to the contents of the first text box.

Button.cpp shows a simple wrapper of the GDI object and applying the subclass for the click handler. The state is checked on each execution in Study::DoStudy() method.

WindowFactory.cpp (part of Button.cpp) shows a cutdown version of the factory that creates GDI objects. The idea here was to abstract away the underlying technology so could use another graphics frameworks apart from GDI.

HTH
imagedialog.PNG / V - Attached On 2020-11-30 10:54:55 UTC - Size: 12.9 KB - 635 views
attachmentDialogForm.cpp - Attached On 2020-11-30 10:55:02 UTC - Size: 2.07 KB - 599 views
attachmentButton.cpp - Attached On 2020-11-30 10:55:57 UTC - Size: 3 KB - 433 views