PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: John Montenigro on October 01, 2006, 11:22:17 AM

Title: Custom control question
Post by: John Montenigro on October 01, 2006, 11:22:17 AM
For this sample custom control:

in DDT style:
http://www.powerbasic.com/support/forums/Archives/Archive-000002/HTML/20020808-7-000215.html

also in SDK style:
http://www.powerbasic.com/support/forums/Forum7/HTML/000505.html


Instructions say:
' To use this control from your own code, simply $INCLUDE this file after
' WIN32API.INC and call InitUrlCtrl from WinMain or LibMain to initialize
' the custom control and make it available.

OK, I've added the module URL.BAS to the project, and I've included the initialization call in FF_WINMAIN



I'm not seeing how to connect it to the form I created in FF...any thoughts?



-John
Title: Custom control question
Post by: TechSupport on October 01, 2006, 12:01:50 PM
The easiest way to use this control is to use the "Custom Control" tool in the FireFly Toolbox. Set the "Caption" property to whatever text you want to display and set the "ClassName" property to "PBURL32".

Otherwise, you can manually create the control in code using CreateWindowEX.
Title: Custom control question
Post by: John Montenigro on October 01, 2006, 05:12:40 PM
Quote from: TechSupportThe easiest way to use this control is to use the "Custom Control" tool in the FireFly Toolbox. Set the "Caption" property to whatever text you want to display and set the "ClassName" property to "PBURL32".

Otherwise, you can manually create the control in code using CreateWindowEX.

OK, I've been reading and experimenting for hours, and cannot make sense of this.

1. As mentioned, I set the caption to "thislink;http://www.thislink.com"  (fictional)  and the ClassName to PBURL32.
In the form, I let FF add code for FORMABOUT_CustomControl1_INIT. The control docs and samples do not show the use of CreateWindow, so I'm not sure what code to put there.


2. As suggested by the custom control's author, I tried to add the line to the "Module1.rc" resource file:

CONTROL "link;http://www.link.com", HWND_FRMABOUT_CUSTOMCONTROL1, 5, 5, 50, 15

I tried this handle, too:  IDC_FRMABOUT_CUSTOMCONTROL1

Neither worked - I kept getting RES file errors, so I commented out the line.

Do I even need to do this? I thought FF would handle this when it interprets the About form?


3. As the PBURL author mentions, URL.BAS should be INCLUDEd after Win32API.INC.  All I did in FF was "Project/AddModule", then selected URL.BAS. How do I know if FF does this Include in the right place?
Should I also do an explicit #INCLUDE? Is there a preferred point that I should do it? Where?


Sorry for the bother. I know I'm missing something in the big picture, but I can't determine what.

-John

(Regarding the CreateWindows stuff - do I need this? If so, what and where?)

BTW, if there's something I should be reading in order to understand this better, you give me the name of the book or webpage, and I'll read it!
I may not have a clue, but I'm not lazy! I do try before I ask.
Title: Custom control question
Post by: TechSupport on October 01, 2006, 05:27:23 PM
Here is what I did.....

(1) #Include the control's source file. I used an explicit #Include but you could also do the Project/Add Module route as well. I put the #Include at the top of the source code in the Main form. You could basically put that #Include anywhere and it should work.

#Include "url.inc"


(2) In the FF_WinMain function I added the following:

InitUrlCtrl


(3) On the Form, I add a CustomControl (that is the large rectangle looking icon in the Toolbox). The default name when you add the control will be CustomControl1.

(4) Click on the CustomControl1 that you added and change the necessary properties. For example, you could change the name of the control, Caption to "link;http://www.link.com", the ClassName to "PBURL32".

(5) Doubleclick on the control and it should take you into the code editor. You should see something like the following:

Function FORM1_CUSTOMCONTROL1_INIT ( _
                                  ClassName   As Asciiz, _  ' windows class
                                  Caption     As Asciiz, _  ' window caption
                                  hWndParent  As Dword,  _  ' handle of parent window
                                  ExStyles    As Dword,  _  ' extended window styles
                                  Styles      As Dword,  _  ' standard window styles
                                  nLeft       As Dword,  _  ' left position of control
                                  nTop        As Dword,  _  ' top position of control
                                  nWidth      As Dword,  _  ' width of control
                                  nHeight     As Dword   _  ' height of control
                                  ) As Long


  'If your custom control uses CreateWindowEx then use the template below, otherwise
  'follow the instructions provided by the Custom Control's author. The Custom Control
  'INIT function is called during the %WM_CREATE message for the Form on which the
  'Custom Control is created.

  Local hWndControl As Dword

  hWndControl = CreateWindowEx(ExStyles, _
                               ClassName, _
                               Caption, _
                               Styles, _
                               nLeft, nTop, nWidth, nHeight, _
                               hWndParent, IDC_FORM1_CUSTOMCONTROL1, _
                               GetModuleHandle(ByVal %Null), _
                               ByVal %Null)

  'It is important that this function return the Windows Handle to the newly created Control *** Do not delete this ***.
  Function = hWndControl

End Function


(6) Compile and Run the program. It should work.

You don't need to do anything with a Resource file.
Title: Custom control question
Post by: John Montenigro on October 02, 2006, 03:56:28 AM
OK, I went back and checked everything, and removed from Module1.rc any lines I had inserted for the CONTROL.

I've done all the above steps exactly (except that the name of the form in my project is FRMABOUT_ ).

The custom control's window style properties are:  WS_VISIBLE property is checked, and the WS_CHILD is checked but grey.

The program compiles and runs, but the hyperlink does not appear on the form. Clicking in the area produces nothing.

I've resized and moved the control, changed the font to SYSTEM and others, but I haven't been able to make it to show up.

UPDATE:
Out of pure frustration, I deleted the control and created it anew, set its properties, etc.

This time it's visible and working. Go figure?