Custom Control - How To

Started by Richard Marchessault, January 15, 2013, 01:53:51 PM

Previous topic - Next topic

Richard Marchessault

I have a custom control (OCX) that I want to evaluate. The control is successfully registered with Windows. A demo application supplied with the control works fine. I have used the PB COM browser. I can see all the methods, etc. I have created an include file with this information for my evaluation project.

I have tried something simple like calling the "About" method but nothing happens. Although the program compiles and runs and I do not get any error messages, it is not clear to me that I am successfully passing information to and from the control.

What exactly are the steps I need to take to succeed in my evaluation of this control?

Any help you can give me would be appreciated.
Thanks,
Dick

Wilko Verweij

Hi, if you open the FireFly-helpfile, then browse to "User Reference Guide", you will find an item on "Working with OCX/ActiveX Controls". Was sufficient even for me to get things working ;-)

Richard Marchessault

Thanks. That helps and it is what I was doing. I believe my problem is with the OCX and and not Firefly. I'm working with the author.
Thanks,
Dick

Rolf Brandt

Maybe you should try Jose's com browser. Jose probably could be of help.
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Richard Marchessault

Thanks for the recommendation. I did try Jose's COM browser. Unfortunately it did not help me to get the OCX working. Waiting for a reply from the OCX author.

What do you do if you find what appears to be a really useful DLL that does not have a Type Library?
Thanks,
Dick

José Roca

Standard DLLs don't have type libraries. You need to translate the headers to PowerBASIC.

Richard Marchessault

Quote from: Jose Roca on January 16, 2013, 05:14:40 PM
Standard DLLs don't have type libraries. You need to translate the headers to PowerBASIC.

Can you point me in the right direction on how to get started on translating headers to PowerBASIC?
Thanks,
Dick

José Roca

You can browse my headers or the PowerBASIC headers. Not an easy task unless you know parameter passing and calling conventions very well.

Richard Marchessault

I am attaching a zip file with the control, the help file for it, and the include file created based on the COM browser to this message. Any help you or anyone in the forum can give me on getting this to work would be appreciated. The examples given in the help file are all for Visual Basic. No matter what I try to do with the control, I seem to get an error code 99. A key event seems to be assigning a bitmap image to the control and it's not clear to me how this can be done. Thanks.
Thanks,
Dick

Richard Marchessault

I'm trying to figure out how to render the following two lines of Visual Basic code in Firefly.

Picture1.Picture = LoadPicture(“Image.jpg”)
Control.Picture = Picture1.Image

Any recommedations?
Thanks,
Dick

Haakon Birkeland

On the top of my head before I leap out of the house, you're looking for using the SendMessage API with the %STM_SETIMAGE constant.
I've usually used it with the picture loaded in the Image Library of FireFly, but it should also work fine with a picture fetched straight from the disk.
Haakon 8o)

Paul Squires

If you are to display a JPEG image then you should use the FireImage control. Check out this post:
http://www.planetsquires.com/protect/forum/index.php?topic=2063.msg16600#msg16600
Paul Squires
PlanetSquires Software

Richard Marchessault

Quote from: TechSupport on January 19, 2013, 11:23:48 PM
If you are to display a JPEG image then you should use the FireImage control. Check out this post:
http://www.planetsquires.com/protect/forum/index.php?topic=2063.msg16600#msg16600

My problem is not how to load an image into a FireImage control. It is how to transfer that image into the custom control.
Thanks,
Dick

Richard Marchessault

The code below was provided on the PB Forums by Chris Holbrook. (Thanks Chris) With this code run in Powerbasic the control does load and show its "About" box. When I try to implement this code in Firefly the object is created but the about box never shows. Why would that be?

#COMPILE EXE
#DIM ALL
'#include "win32api.inc"

%UNICODE = 1

' // Include files for external files
%USEOLECON = 1                ' // Use OLE container
#INCLUDE ONCE "CWindow.inc"   ' // CWindow class

%IDC_OCX = 101
#INCLUDE "EymBarcodeReader.inc" '
GLOBAL ordr AS Int__DEymBarcodeReader
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN
    LOCAL hCtl AS DWORD

   ' // Create the dialog
   LOCAL hDlg AS DWORD
   DIALOG NEW PIXELS, 0, "test", , , 300, 300, %WS_OVERLAPPEDWINDOW TO hDlg

   ' // Create an instance of the class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Add EYMBARCODERREADER control
   LOCAL nWide, nHigh AS LONG
   DIALOG GET CLIENT hDlg TO nWide, nHigh
   hCtl = pWindow.AddOCX(hDlg, %IDC_OCX, "EYMBARCODEREADER.EymBarcodeReaderCtrl.1" , "", 0, 0, nWide, nHigh)
   IF hCtl = 0 THEN MSGBOX "failed to add OCX" ELSE MSGBOX "added OCX" : EXIT FUNCTION
   CONTROL SET FOCUS hDlg, %IDC_OCX

   ' // Get the IDispatch of the control
   oRdr = OC_GetDispatch(hCtl)
   IF ISOBJECT(oRdr) THEN

       OBJECT CALL oRdr.aboutbox
       MSGBOX "object created"
   ELSE
       MSGBOX "Reader object not created"
   END IF

   ' // Display and activate the dialog
   DIALOG SHOW MODELESS hDlg, CALL DlgProc

   ' // Message handler loop
   ' // We need to forward the messages to this control to have keyboard navigation
   LOCAL uMsg AS tagMsg
   WHILE GetMessage(uMsg, %NULL, 0, 0)
      IF ISFALSE OC_ForwardMessage(GetFocus, uMsg) THEN
         IF IsDialogMessage(hDlg, uMsg) = 0 THEN
            TranslateMessage uMsg
            DispatchMessage uMsg
         END IF
      END IF
   WEND

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main Dialog procedure
' ========================================================================================
CALLBACK FUNCTION DlgProc() AS LONG

   SELECT CASE CBMSG

      CASE %WM_COMMAND
         SELECT CASE CB.CTL
         MSGBOX "Test"
         ' ...
            ' ...
         END SELECT

      CASE %WM_SIZE
         IF CB.WPARAM <> %SIZE_MINIMIZED THEN
            ' // Resize the control
            LOCAL nWide, nHigh AS LONG
            DIALOG GET CLIENT CB.HNDL TO nWide, nHigh
            CONTROL SET SIZE CB.HNDL, %IDC_OCX, nWide, nHigh
         END IF

      CASE %WM_DESTROY
         ' // End the application
         ' // Use this method instead of DIALOG END with modeless dialogs
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

END FUNCTION
' ===========================           
Thanks,
Dick

José Roca

Quote
When I try to implement this code in Firefly the object is created but the about box never shows. Why would that be?

If you don't show the code you are using, we have no clue.