Guidance
指路人
g.yi.org
software / rapidq / Examples / QObject / objectToolbox.inc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
' ObjectToolbox API for Rapid-Q! Version 1.1.
'
' About
' ---------------
' ObjectToolbox is a library that provides useful functions and subs for manipulating objects and
' retrieving information about them.
'
' Release Notes
' --------------
' o Code is provided as-is.
' o ObjectToolbox is designed for Windows, not Linux/Unix.
'
'
' This package includes:
' ===============================================================================
' - TypeOf, a function which returns a string representation of the type of object the given handle identifies.
'
' Usage Notes:
' --------------
' You can't pass objects by name (by reference) to TypeOf, only their handles. I hope to provide a
' workaround for this, though.
'
' GDI object handles may be implemented for the next version of TypeOf().
'
' Updates:
' --------------
' TypeOf now recognizes QMenuItems


     $IFNDEF __OBJECT_TOOLBOX_USED
      $DEFINE __OBJECT_TOOLBOX_USED

      REM [This section contains the TypeOf FUNCTION AND all other code related TO it]
      REM ------------------------------------------------------------------------------------------------------
' Not a local function (See below). The underscore denotes this as an API call.
      DECLARE FUNCTION ObjectToolbox_GetClassName LIB "user32" ALIAS "GetClassNameA" _
       (BYVAL hWnd AS LONG, ByRef lpClassName AS STRING, BYVAL nMaxCount AS LONG) AS LONG

' Returns the win32 class name for an object, as opposed to Rapid-Q's predetermined component name
      FUNCTION ObjectToolbox.TypeOfA(Object AS LONG) AS STRING
'ShowMessage "Called ObjectToolbox.TypeOfA"
       DIM StrBuf AS STRING, StrPtr AS STRING, StrLen AS LONG
       StrBuf=SPACE$(256): StrLen=LEN(StrBuf)
       StrLen=ObjectToolbox_GetClassName(Object, StrBuf, StrLen)
       StrPtr=LEFT$(StrBuf, StrLen)
       Result=StrPtr
      END FUNCTION

' Returns Rapid-Q's definition of the class name Object identifies
      FUNCTION ObjectToolbox.TypeOf(Object AS LONG) AS STRING
'ShowMessage "Called ObjectToolbox.TypeOf"
       DIM StrBuf AS STRING, StrPtr AS STRING, StrLen AS LONG
       StrBuf=SPACE$(256): StrLen=LEN(StrBuf)
       StrLen=ObjectToolbox_GetClassName(Object, StrBuf, StrLen)
       StrPtr=LEFT$(StrBuf, StrLen)

       IF LEFT$(StrPtr, 1)="T" THEN
  ' Let's convert the first character from 'T' to 'Q'
        StrPtr=REPLACE$(StrPtr, "Q", 1)

 ' Now get rid of the 's' at the end (we don't need it)
        IF RIGHT$(StrPtr, 1)="s" THEN
         StrPtr=LEFT$(StrPtr, LEN(StrPtr)-1)
        END IF
       END IF

 ' Now let's analyze the class name and convert, if necessary
       IF StrPtr="QBitBtn" THEN
        StrPtr="QButton"
       ELSEIF StrPtr="QApplication" THEN
        StrPtr="Application"
       ELSEIF StrPtr="#32768" THEN
        StrPtr="QMenuItem"
       END IF

       Result=StrPtr
      END FUNCTION

' A new way of doing things :)
      FUNCTIONI TypeOf(...) AS STRING
       DIM ptr1 AS INTEGER, lpfn1 AS LONG, lpfn2 AS LONG, bGetNative AS BYTE
       ptr1=PARAMVAL(1): bGetNative=PARAMVAL(2)

       BIND lpfn1 TO ObjectToolbox.TypeOf
       BIND lpfn2 TO ObjectToolbox.TypeOfA

       IF PARAMVALCOUNT=1 THEN
        CALLFUNC lpfn1, ptr1
       ELSEIF PARAMVALCOUNT=2 AND bGetNative=1 THEN
        CALLFUNC lpfn2, ptr1
       END IF

' Frees the pointers, I think
       lpfn1=0: lpfn2=0
      END FUNCTIONI

' Overview
' ---------
' TypeOf() only works on GUI components, not virtual ones (interfaces) like GDI objects
' such as QBitMap, QCanvas, QFont, and Printer.
'
' QCoolBtn is a canvas-type object, so the above rules apply to it as well.
' QDirTree dosen't have a GUI handle; oddly, it's a GDI object :p
' If you test a QFont, TypeOf may return a current class running in Windows, or nothing at all.
      REM ----------------------------------------------------------------------------------------------------
      REM [END TypeOf() code section]

     $ENDIF
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2023-2-1  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-08-24 10:15:41