Guidance
指路人
g.yi.org
software / rapidq / Examples / Tools - IDE, Designer, Builder / FreeQ IDE src / inc ide / IDE_gLibrary.inc

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

  
'general library of functions for FreeQ IDEa

'=======================================================================|
'Routines from Fileops to manipulate file names and paths.              |
'  QUOTE - Returns a quoted string                                      |
'  STRIPPATH - Returns file path (without file name)                    |
'  STIPFILENAME - Returns file name (without path)                      |
'  STRIPFILEEXT - Returns file extension (like ".exe", ".html" etc.)    |
'  FILENAMENOEXT - Returns file name without extension                  |
'  FULLPATHNOEXT - Returns full path without file extension             |
'  BROWSEFORFOLDERS,  BROWSEFORFILE not used for efficiency with native code
'=======================================================================|


     $IFNDEF __FILEOPS_INC
      $DEFINE __FILEOPS_INC


    '===============================================================================
    '# QUOTE : Returns a quoted string
      FUNCTION Quote$(StringToQuote AS STRING) AS STRING
       StringToQuote = CHR$(34) + StringToQuote + CHR$(34)
       Result = REPLACESUBSTR$(stringtoquote , CHR$(34) + CHR$(34) , CHR$(34))
      END FUNCTION

    '===============================================================================
    '# STRIPPATH : Returns file path (without file name)
      FUNCTION StripPath(fullname AS STRING) AS STRING
       Result = LEFT$(fullname , rinstr(fullname , "\"))
      END FUNCTION

    '===============================================================================
    '# STRIPFILENAME : Returns file name (without path)
      FUNCTION StripFileName(fullname AS STRING) AS STRING
       Result = RIGHT$(fullname , LEN(fullname) - rinstr(fullname , "\"))
      END FUNCTION

    '===============================================================================
    '# STRIPFILEEXT : Returns file extension (like ".exe", ".html" etc.)
      FUNCTION StripFileExt(fullname AS STRING) AS STRING
       Result = RIGHT$(fullname , LEN(fullname) - rinstr(fullname , ".") + 1)
      END FUNCTION

    '===============================================================================
    '# FILENAMENOEXT : Returns file name without extension
      FUNCTION FileNameNoExt(fullname AS STRING) AS STRING
       fullname = RIGHT$(fullname , LEN(fullname) - rinstr(fullname , "\"))
       Result = LEFT$(fullname , rinstr(fullname , ".") - 1)
      END FUNCTION

    '===============================================================================
    '# FULLPATHNOEXT : Returns full path without file extension
      FUNCTION FullPathNoExt(fullname AS STRING) AS STRING
       Result = LEFT$(fullname , rinstr(fullname , ".") - 1)
      END FUNCTION

    '===============================================================================
    '# C_Style : Returns "slashed" path from a "backslashed" one
      FUNCTION C_Style(fullname AS STRING) AS STRING
       fullname = REPLACESUBSTR$(fullname , "\\" , "\")
       Result = REPLACESUBSTR$(fullname , "\" , "/")
      END FUNCTION


    '===============================================================================
    '# SYSDIR : Retrieves windows shell directories
    '-------------------------|
    'Allowed values for dir  |
    '----------------------------------------------------------------------------|
    'Desktop                 | Templates               | AppData                 |
    'Start Menu              | Programs                | Startup                 |
    'Fonts                   | SendTo                  | Recent                  |
    'Favorites               | Cache                   | Cookies                 |
    'History                 | NetHood                 | Personal                |
    'PrintHood               | Local AppData           | My Pictures             |
    'Administrative Tools    |                         |                         |
    '----------------------------------------------------------------------------|
      FUNCTION SysDir(dir AS STRING) AS STRING
       DIM fo_reg AS QREGISTRY
       fo_reg.RootKey = &H80000001
       fo_reg.openkey("Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" , 0)
       Result = fo_reg.readstring(dir) + "\"
      END FUNCTION


'-- ***********************************************************************'
      SUB FileCopy(FileSrc$ AS STRING, FileDst$ AS STRING)
    'Andrew Shelkovenko dec 2003
    'Copy FileSrc$ to FileDst$
    'if path dest is not exists - create it.

       DIM FileSrc AS QFILESTREAM
       DIM FileDst AS QFILESTREAM

'     DEFSTR dr$ = StripPath(FileDst$)
'     IF dr$ <> "" THEN
'         MKSubDir dr$
'         IF DIREXISTS(dr$) = 0 THEN SHOWMESSAGE("Cannot create directory " + dr$)
'         EXIT SUB
'     END IF

       FileSrc.OPEN(FileSrc$ , fmOpenRead)
       FileDst.OPEN(FileDst$ , fmCreate)
       FileDst.CopyFrom(FileSrc , 0)
       FileSrc.CLOSE
       FileDst.CLOSE
      END SUB

     $ENDIF



     FUNCTION TRIM$(Str AS STRING) AS STRING  'Clean spaces in one string
      Result = LTRIM$(RTRIM$(Str))
     END FUNCTION


     FUNCTION StripTabs(TheString AS STRING) AS STRING
      IF INSTR(TheString, Tab) THEN
       StripTabs = REPLACESUBSTR$(TheString, Tab, CHR$(32))
      ELSE
       StripTabs = TheString
      END IF
     END FUNCTION


'------- general functions -----------
     FUNCTION NOT!(n AS INTEGER) AS INTEGER                 'logical NOT, dont use RQ NOT
      IF n = 0 THEN RESULT = 1 ELSE RESULT = 0
     END FUNCTION


     SUB LaunchMe(Sender AS QLABEL)
      DEFSTR s = Sender.CAPTION
      DEFINT l, i = INSTR(UCASE$(s), "HTTP://")
      IF i = 0 THEN
       i = INSTR("WWW.", UCASE$(s))
       IF i > 0 THEN l = LEN(s) - 4
      ELSE
       l = LEN(s) - 7
      END IF
      IF i > 0 THEN s = MID$(s, i, l)
      ShellExecute(0,"open",s,"","",1)
     END SUB



     FUNCTION GetChildHandle(BYVAL hParent AS LONG, BYVAL sClass AS STRING, BYVAL lInstance AS LONG) AS LONG
      DEFLNG gCnt = 0
      DEFLNG gWnd = GetWindow(hParent, GW_CHILD)
      DEFSTR gStr = ""

      DO
       gStr = SPACE$(255)
       GetClassName(gWnd, VARPTR(gStr), 255)
       IF LCASE$(LEFT$(gStr, INSTR(gStr, CHR$(0))-1)) = LCASE$(sClass) THEN INC(gCnt)
       IF gCnt = lInstance THEN EXIT DO
       gWnd = GetWindow(gWnd, GW_HWNDNEXT)
      LOOP UNTIL gWnd = 0

      Result = gWnd
     END FUNCTION



     FUNCTION IDE_AttemptToFindFile(inTxt AS STRING) AS STRING
      DEFSTR s = "\" + StripFileName(inTxt)

      IF FILEEXISTS(inTxt) THEN                   'default is ok
       RESULT = inTxt
       EXIT FUNCTION

      ELSEIF FILEEXISTS(Application.Path + s) THEN                'otherwise start searching
       RESULT = Application.Path + s
       EXIT FUNCTION

      ELSEIF FILEEXISTS(Application.Path +"\tools" + s) THEN
       RESULT = Application.Path +"\tools" + s
       EXIT FUNCTION

      ELSEIF FILEEXISTS(Application.Path +"\help" + s) THEN
       RESULT = Application.Path +"\help" + s
       EXIT FUNCTION

      ELSEIF FILEEXISTS(Application.Path +"\templates" + s) THEN
       RESULT = Application.Path +"\templates" + s
       EXIT FUNCTION

      ELSEIF FILEEXISTS("\rapidq" + s) THEN
       RESULT = "\rapidq" + s
       EXIT FUNCTION

      ELSEIF FILEEXISTS("\rapidq\lib" + s) THEN
       RESULT = "\rapidq\lib" + s
       EXIT FUNCTION

      ELSEIF FILEEXISTS("\rapidq\inc" + s) THEN
       RESULT = "\rapidq\inc" + s
       EXIT FUNCTION

      ELSEIF FILEEXISTS("\rapidq\include" + s) THEN
       RESULT = "\rapidq\include" + s
       EXIT FUNCTION

      ELSEIF FILEEXISTS("\rapidq\help" + s) THEN
       RESULT = "\rapidq\help" + s
       EXIT FUNCTION

      ELSEIF FILEEXISTS("\rapidq\doc" + s) THEN
       RESULT = "\rapidq\doc" + s
       EXIT FUNCTION

      ELSEIF FILEEXISTS("\rapidq\templates" + s) THEN
       RESULT = "\rapidq\templates" + s
       EXIT FUNCTION

      ELSE
       RESULT = ""
      END IF
     END FUNCTION



     FUNCTION IDE_AttemptToFindFolder(inTxt AS STRING) AS STRING
      DEFSTR s = RIGHT$(inTxt, LEN(inTxt) - RINSTR(inTxt, "\") + 1) 'inTxt

      IF DIREXISTS(inTxt) THEN                   'default is ok
       RESULT = inTxt
       EXIT FUNCTION

      ELSEIF DIREXISTS(Application.Path + s) THEN                'otherwise start searching
       RESULT = Application.Path + s
       EXIT FUNCTION

      ELSEIF DIREXISTS(Application.Path +"\tools" + s) THEN
       RESULT = Application.Path +"\tools" + s
       EXIT FUNCTION

      ELSEIF DIREXISTS(Application.Path +"\help" + s) THEN
       RESULT = Application.Path +"\help" + s
       EXIT FUNCTION

      ELSEIF DIREXISTS(Application.Path +"\templates" + s) THEN
       RESULT = Application.Path +"\templates" + s
       EXIT FUNCTION

      ELSEIF DIREXISTS("\rapidq" + s) THEN
       RESULT = "\rapidq" + s
       EXIT FUNCTION

      ELSEIF DIREXISTS("\rapidq\lib" + s) THEN
       RESULT = "\rapidq\lib" + s
       EXIT FUNCTION

      ELSEIF DIREXISTS("\rapidq\inc" + s) THEN
       RESULT = "\rapidq\inc" + s
       EXIT FUNCTION

      ELSEIF DIREXISTS("\rapidq\include" + s) THEN
       RESULT = "\rapidq\include" + s
       EXIT FUNCTION

      ELSEIF DIREXISTS("\rapidq\help" + s) THEN
       RESULT = "\rapidq\help" + s
       EXIT FUNCTION

      ELSEIF DIREXISTS("\rapidq\doc" + s) THEN
       RESULT = "\rapidq\doc" + s
       EXIT FUNCTION

      ELSEIF DIREXISTS("\rapidq\templates" + s) THEN
       RESULT = "\rapidq\templates" + s
       EXIT FUNCTION

      ELSE
       RESULT = ""
      END IF
     END FUNCTION


掌柜推荐
 
 
¥1,420.00 ·
 
 
¥950.00 ·
 
 
¥288.00 ·
 
 
¥738.00 ·
 
 
¥397.00 ·
 
 
¥750.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-12-07 21:18:03