Announcement

Collapse
No announcement yet.

Can I make a button control CLASS with self-contained user input events methods?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can I make a button control CLASS with self-contained user input events methods?

    Pardon for my poor English and programming background.. My thead is long and not summarized, but easy to read and understand.

    Can I make a XP-style button control using newly introduced CLASS support?

    In reality, I want to make a waveform editor using graphic control.. But I think it's more easy to explain what I want, giving you a example of BUTTON control as a similar case.

    Button control needs to include event methods to receive and process user inputs, like CLICK(), KeyPress(), MouseMove() and etc..

    I think those event methods have to be contained in a CLASS code block, so those event methods should be made automatically per a instance when user declare a OBJ variable using a CLASS definition.

    But to my knowledge, We use a default window callback function or user-defined WindowProc function to handle appropriate event.

    The problem is Callback function is outside the CLASS block.

    I can't contain event methods into a CLASS definition because..

    1) a CLASS definition is a ideal print for instances. It's not a existing codes block, so I can't reference the address of method using CODEPTR.

    2) CODEPTR does not support class method.

    As a reference, I saw codes of chameleonButton control in visual basic 6.. There is 'UserControl' object and 'Public Event Click()'.. So programmer can make sub like 'Private Sub UserControl_Click()'..

    Can I make such event methods using PowerBasic.. Or Are there any event class GUID in Windows responding form event?

  • #2
    Can I make a XP-style button control using newly introduced CLASS support?
    The short answer is yes. You can create properties, methods and events with PB classes.

    Button control needs to include event methods to receive and process user inputs, like CLICK(), KeyPress(), MouseMove() and etc..
    From this description I'm assuming you are trying to emulate or recode a VB project. Is this correct?

    Assuming it is, the main problem I've encountered is emulating the functionality of VB events within PB. In the VB model control properties and methods tend to be generalized, applying to any VB CommandButton control, for example. VB Events, on the other hand, tend to be specific for a particular instance of a control. The way I've been able to solve this problem is by subclassing the control in PB and trapping the Windows messages before they are processed by Windows.

    By subclassing the control you can trap Windows messages such as:

    %WM_LBUTTONDOWN
    %WM_LBUTTONUP
    %WM_RBUTTONDOWN
    %WM_RBUTTONUP
    %WM_MBUTTONDOWN
    %WM_MBUTTONUP
    %WM_MOUSEMOVE
    %WM_KEYDOWN
    %WM_KEYUP
    %WM_CHAR

    From there you can write your own "Event" code in PB for each control you create, such as:

    Code:
    SUB Form1_TextBox_MouseDown(iButton AS LONG, iShift AS LONG, X AS SINGLE, Y AS SINGLE)
    VB allows you to create controls with the same name in any VB project, therefore, I have appended the VB form name onto the "TextBox_MouseDown" event to make the SUB procedure name unique.
    Later...

    JR

    "When governments fear the people there is liberty. When people fear the government there is tyranny." - Thomas Jefferson

    Comment


    • #3
      Thanks for John R. Heathcote..

      As you said above.. I got to know 'SubClassing' is the answer. I read the article about subclassing and related articles yesterday.

      Thank you..

      Comment

      Working...
      X