Copyright © 2013-2014 MultiMedia Soft

How to perform custom graphic rendering over the control's surface

Previous pageReturn to chapter overviewNext page

Although graphic features and customization possibilities should be already quite rich, at runtime you may have the need to add your own custom graphic rendering over the control's surface; this can be done in two ways:

 

by catching the WaveAnalyzerPaintDone event and by using the handle to the drawing device context passed as a parameter to the event management routine: this event is generated as soon as the rendering of the control has been completed; using this technique is generally faster but, due to the fact that the passed device context is the screen device context, it could cause some flicker.
by using the SetCustomPaintFunction method and providing your own drawing functionalities: this technique could be a little bit slower because the rendering is performed using double-buffering but the final result will be certainly better because it will be completely flicker free.

It's up to you deciding which of these techniques will better fit your needs.

 

Note that you have the possibility to use both of them at the same time but it's important to remember that the function provided through the call to the SetCustomPaintFunction method will be called before generating the WaveAnalyzerPaintDone event.

 

Let's see a sample that demonstrates how to paint a flicker free red ellipse over the button surface:

 

 

Visual Basic example

Inside a BAS module, add the following declarations that will allow accessing the Windows GDI primitives:

Public Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long

Public Declare Function Ellipse Lib "gdi32" (ByVal hDC As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject&) As Long

Public Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long

Inside the same BAS module add the following subroutine that will perform our custom rendering:

Sub MyPaintFunction(ByVal hDC As Long)

 Dim brushColor As Long

 Dim brushOld As Long

 brushColor = CreateSolidBrush(RGB(255, 0, 0))

 brushOld = SelectObject(hDC, brushColor)

 Ellipse hDC, 10, 10, 50, 50

 SelectObject hDC, brushOld

 DeleteObject brushColor

End Sub

Inside the Form_Load subroutine, supposing that you have instanced a member variable ActiveWaveformAnalyzer1 for one of our controls, call the SetCustomPaintFunction method passing the pointer to the MyPaintFunction subroutine, obtained through the AddressOf function:

Private Sub Form_Load()

 ActiveWaveformAnalyzer1.SetCustomPaintFunction AddressOf MyPaintFunction

End Sub

 

Note that you can call the SetCustomPaintFunction method from wherever you want, also passing different drawing function depending upon your rendering needs.

 

 

Visual C++ example

Write your own function like the one below (note that the function must have the _stdcall declaration):

void _stdcall MyPaintFunction (long hDC)

{

     HBRUSH brushColor = ::CreateSolidBrush (RGB (255,0,0));

     HBRUSH brushOld = (HBRUSH) ::SelectObject ((HDC) hDC, brushColor);

     ::Ellipse((HDC) hDC, 10, 10, 50, 50);

     ::SelectObject ((HDC) hDC, brushOld);

     ::DeleteObject (brushColor);

}

Supposing that we have created a member variable ActiveWaveformAnalyzer1 for one of our controls, you will have to call the following line:

ActiveWaveformAnalyzer1.SetCustomPaintFunction ((long) MyPaintFunction);