Guidance
指路人
g.yi.org
software / RapidQ / RQ Intro / Tips

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

  
技巧与示例 Rapid-Q Programming Tips & Examples
  1. RUN & command line
  2. Event Sender
  3. Wait For Another Process End
  4. Control QRichEdit
  5. OCX
  6. Drag & Drop
  7. Popup Menu
  8. Inter-Process Messaging
  9. Start Splash
  10. Windows Date-Time
  11. ShellExecute
  12. Array Initilization
  13. Form TextOut

还有 More Examples...


  1. RUN statement and command line
    From:   Chris  Sat Apr 19, 2003  4:13 am

    Using the RUN or SHELL function presents an interesting dilemma. Not only must your program conform to RapidQ syntax but also the command line syntax.

    Three things to keep in mind:
    1. The syntax for the copy command is, simply:
    copy <source folder or file> <destination folder or file>
    2. Paths that contain spaces (Ex: c:/Documents and Settings\jdoe\My Documents\) must be in quotes when using command line functions (Ex: "c:/Documents and Settings\jdoe\My Documents\")
    3. To add quotes to a string in RapidQ, first turn on $ESCAPECHARS then escape the quote character with a backslash (Ex: "\"Hello\", he said.").

    NB: When using $ESCAPECHARS, backslashes must also be escaped. So, you have two options for paths:
    1. a_string$ = "\"c:/\\Documents and Settings\\jdoe\\My Documents\\\""
    2. a_string$ = "\"C:/Documents and Settings/jdoe/My Documents/\""
  2. An Undocumented parameter:
    Each event handler of Rapid-Q built-in object has a Sender parameter, this parameter is not well documented for some objects. Don't miss it if you use one sub to handle events from several different objects. You can add this after the parameter(s) listed in the document. For example: QTimer.
  3. 等待另一进程结束:
         proc_id=SHELL("rc.exe",0)' to hide, then
         waitforsingleobject(proc_id,&HFFFF)
    
  4. 彻底控制QRichEdit
    All you may have to do is find out what messages to send your QRichEdit control. There is a listing of all these messages here. Keep in mind that there are 3 versions of the Windows rich edit control. Riched32.dll is Version 1. Some of these messages may only work with Versions 2 and 3 (Riched20.dll). QRichEdit doesn't use riched20.dll. ' example, scroll to beginning after addstrings
    RichEdit1.AddStrings = "Whatever text you have"
    RichEdit1.SelStart=Len(RichEdit1.Text)
    SendMessage(RichEdit1.Handle, &HB7, 0, 0)
  5. Using OCX Control
    '> Is the away to make a program that would give you your Ip address and
    '> User name in RapidQ ?
    '> Thanks
    
    'Try to use Microsoft Winsock Control:
    ' This code requires MSWINSCK.OCX
    ' Check if you have it in c:\windows\system directory and
    ' type the following command to register this library file:
    ' regsvr32 \windows\system\MSWINSCK.OCX
    ' (for Windows NT and 2000:
    ' regsvr32 \WINNT\system32\MSWINSCK.OCX)
    
    
         $APPTYPE GUI
         $INCLUDE "RAPIDQ.INC"
         $TYPECHECK ON
    '$INCLUDE "Miniset.INC"
    
    
         DECLARE SUB Lookup_Click
         DIM font AS QFONT
         Font.AddStyles(fsBold)
    
    
         CREATE Form AS QFORM
          height= 120
          center
          CAPTION = "MSWinsock App"
          BorderStyle = bsSingle
          CREATE Title AS QLABEL
           CAPTION = "Localhostname Lookup"
           font= font
           left = 80
           top =5
          END CREATE
          CREATE lblLocalHostName AS QLABEL
           CAPTION = "Local HostName: "
           left = 50
           top = 30
          END CREATE
          CREATE lblLocalIP AS QLABEL
           CAPTION = "Local IP: "
           left = 50
           top = 50
          END CREATE
          CREATE Lookup AS QBUTTON
           top=30
           left=220
           CAPTION = "Lookup"
           OnClick = Lookup_Click
          END CREATE
          CREATE Winsock AS QOLECONTAINER
           visible=0
           CreateObject("MSWinsock.Winsock.1")
          END CREATE
         END CREATE
    
    'MinSet(Form.handle, -8, 0, application.handle)
         Form.SHOWMODAL
         Winsock.Free
    
    
         SUB Lookup_Click
          lblLocalHostName.CAPTION = "Local HostName: " + Winsock.LocalHostName
          lblLocalIP.CAPTION = "Local IP: " + Winsock.LocalIP
         END SUB
    
    'Source code by ken78x
    
  6. 鼠标拖放
    CONST WM_DROPFILES=&H233
    TYPE TPOINT
     X AS LONG
     Y AS LONG
    END TYPE
    DECLARE SUB DragAcceptFiles LIB "SHELL32" ALIAS "DragAcceptFiles" (hWnd AS LONG, Accept AS LONG)
    DECLARE SUB DragFinish LIB "SHELL32" ALIAS "DragFinish" (hDrop AS LONG)
    DECLARE FUNCTION DragQueryFile LIB "SHELL32" ALIAS "DragQueryFileA" (hDrop AS LONG, iFile AS LONG, lpszFile AS LONG, cch AS LONG) AS LONG
    DECLARE FUNCTION DragQueryPoint LIB "SHELL32" ALIAS "DragQueryPoint" (hDrop AS LONG, lppt AS TPOINT) AS LONG

     ' Two subs to handle the events
    DECLARE SUB Show
    DECLARE SUB FormWndProc(hWnd AS LONG, uMsg AS LONG, wParam AS LONG, lParam AS LONG)

     ' Create our form, OnShow and WndProc do the work
    CREATE Form AS QForm
     Caption="Drag and drop files"
     Center
     OnShow = Show
     WndProc=FormWndProc
     CREATE Edit as QRichEdit
      Align = 5
     END CREATE
    END CREATE

     ' Make our form accept DragDrop Files
    DragAcceptFiles(Form.Handle,1)

    Form.ShowModal

     ' This one accepts files when the program is RUNNING
    SUB FormWndProc
     DIM Point AS TPOINT
     DIM File AS STRING
     IF uMsg = WM_DROPFILES then ' user dropped file
      DragQueryPoint(wParam, Point) ' dropped where?
      IF Point.X > Edit.Left AND Point.Y > Edit.Top AND _
       Point.X < (Edit.Left + Edit.Width) AND _
       Point.Y < (Edit.Top + Edit.Height) THEN ' then
       File = SPACE$(255) ' buffer for filename
       DragQueryFile(wParam, 0, VARPTR(File),255)'get file
       Edit.LoadFromFile(File) ' and load it
      END IF
      DragFinish(wParam) ' free memory
     END IF
    END SUB

     ' This one handles files dropped onto the ICON in Explorer
    SUB Show
     IF Command$(1) <> "" THEN ' Is there a commandline?
      Edit.LoadFromFile Command$(1) ' If yes, load it
     END IF
    END SUB
  7. 任务栏小图标弹出菜单
    Here's a sample tray menu:

    CREATE PopUpMenu AS QPOPUPMENU ' Note no parent!
     Alignment = 1 ' Pop up to the left
     CREATE Options AS QMENUITEM
      Caption = "&Options..."
      OnClick = Options_Click
     END CREATE
     CREATE Sep AS QMENUITEM
      Caption = "-"
     END CREATE
     CREATE MeExit AS QMENUITEM
      Caption = "&Exit"
      OnClick = Exit_Click
     END CREATE
    END CREATE

    And how the WndProc should respond:

    SUB FormWndProc
     IF uMsg = WM_TRAYICON THEN
      IF (lParam AND &HFFFF) = WM_RBUTTONUP THEN
       SetForegroundWindow(Form.Handle) ' Keeps the menu from hanging
       PopUpMenu.Popup(Screen.MouseX, Screen.MouseY)
      END IF
     END IF
    END SUB
  8. 进程间消息传送
    > I need to transfer a filename between two exe's. they are compiled
    > separately. I need to take the information in the string Filename, and
    > put it into another program. I was thinking maybe writing the
    > information to a txt file and then retrieving it, but don't know how to
    > read the info in the other exe

    The sending exe should use:
         CONST WM_COPYDATA = &H4A
    
         TYPE COPYDATASTRUCT
          dwData AS LONG
          cbData AS LONG
          lpData AS LONG
         END TYPE
         DIM CDS AS COPYDATASTRUCT
    
         SUB SendData
          CDS.lpData = VARPTR(FileName)
          CDS.cbData = LEN(FileName)
          SendMessage(hWnd, WM_COPYDATA, 0, CDS)'hWnd is handle of recieving app
         END SUB
    
    The receiving exe should be subclassed like so:
         FUNCTION WndProc
          IF uMsg = WM_COPYDATA THEN
           DIM MS AS QMEMORYSTREAM
           MS.MemCopyFrom(lParam, 12)
           MS.Position = 0
           MS.ReadUDT(CDS)
           MS.CLOSE
           FileName = VARPTR$(CDS.lpData)
           Result = 1
          ELSE
           Result = CallWindowProc(OldWndProc, hWnd, uMsg, wParam, lParam)
          END IF
         END FUNCTION
    
    Hope that helps...
    Psyclops ?
  9. 显示启动画面:
         CREATE MainForm AS QFORM
          Center
         END CREATE
    
    ' For the SplashForm, I used regular form, i.e. one with a
    ' beveled, nonresizable border and used HideTitleBar to, um, well,
    ' hide the titlebar...
         CREATE SplashForm AS QFORM
          Borderstyle = 3
          FormStyle = 3 ' keep in foreground (see below)
          COLOR = &HFFFFFF
          Width = 200
          Height = 150
          Center
          HideTitleBar
          CREATE Label AS QLABEL
           Top = 30
           Left = 30
           Font.Name = "Arial"
           Font.COLOR = &H0000FF
           Font.Size = 30
           CAPTION = "Splash!"
          END CREATE
         END CREATE
    
         SplashForm.Show ' show SplashForm
         SplashForm.RePaint ' needed when using Show
         SLEEP 2 ' pause here
         MainForm.Show ' show MainForm behind Splash
         SLEEP 2 ' pause again
         SplashForm.CLOSE ' bye bye Splash!
         MainForm.CLOSE ' close MainForm so we can
         MainForm.SHOWMODAL ' show it modally
    
  10. 取系统日期时间的各分量
    TYPE SYSTEMTIME
        wyear AS SHORT
        wMonth AS SHORT
        wDayOfWeek AS SHORT
        wDay AS SHORT
        wHour AS SHORT
        wMinute AS SHORT
        wSecond AS SHORT
        wMilliseconds AS SHORT
    END TYPE

    DECLARE SUB GetLocalTime Lib "kernel32" ALIAS "GetLocalTime"_
    (lpSystemTime As SYSTEMTIME)

    DECLARE FUNCTION GetLongDate AS STRING

    CREATE Form AS QFORM
        Center
    END CREATE

    Form.Caption = "Today > "+GetLongDate
    Form.ShowModal

    FUNCTION GetLongDate
        DIM SysTime AS SYSTEMTIME
        DIM year AS INTEGER
        DIM MonthNum AS INTEGER
        DIM DowNum AS INTEGER
        DIM Day AS INTEGER
        DIM DOW AS STRING
        DIM DOWStr AS STRING
        DIM Month AS STRING
        DIM MonthStr AS STRING
        GetLocalTime(SysTime)
        year= SysTime.wyear
        MonthNum = SysTime.wMonth
        DOWNum = SysTime.wDayOfWeek
        Day = SysTime.wDay
        DOWStr = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
        MonthStr = "January February March April May June July August September October November December"
        dow= RTRIM$(MID$(DOWStr, (DOWNum*10)+1,10))
        Month = RTRIM$(MID$(MonthStr, ((MonthNum-1)*10)+1, 10))
        GetLongDate = DOW+" "+STR$(Day)+" "+Month+" "+STR$(year)
    END FUNCTION
  11. 打开其他程序或文档
    • SUB Click
      x = SHELL("start http://g.slyip.com",0)
      END SUB

      CREATE Form AS QFORM
      OnClick = Click
      Center
      ShowModal
      END CREATE

    •      DECLARE FUNCTION ShellExecute LIB "shell32.dll" ALIAS "ShellExecuteA" (BYVAL hwnd AS LONG, _
            BYVAL lpOperation AS STRING, BYVAL lpFile AS STRING, _
            BYVAL lpParameters AS STRING, BYVAL lpDirectory _
            AS STRING, BYVAL nShowCmd AS LONG) AS LONG
      'function to open the webpage.
      
           CONST GWL_HWNDPARENT = -8
           CONST HWND_DESKTOP = 0
           DECLARE FUNCTION SetWindowLong LIB "user32" ALIAS _
            "SetWindowLongA" (hwnd AS LONG, nIndex AS LONG, _
            dwNewLong AS LONG) AS LONG
      ' a function to make the program minmize right.
      '$include "setup.inc"
      
      
           DECLARE SUB LAUNCH
           DECLARE SUB FILTER (KEY AS WORD)
      
           CREATE Form AS QFORM
            CAPTION = "Launch IT!"
            Width = screen.width
            Height = 47
            top = 0
            left = 0
            borderstyle = 2
            DELBORDERICONS = 2
            CREATE CoolBtn1 AS QCOOLBTN
             CAPTION = "GO!"
             Left = 453
             Top = 0
             Width = 100
             Height = 20
             Align = 4
             onclick = launch
            END CREATE
            CREATE Edit1 AS QEDIT
             Text = ""
             Left = 0
             Top = 0
             Width = 453
             Height = 20
             Align = 5
             ONKEYPRESS = FILTER
            END CREATE
           END CREATE
           setwindowlong(form.handle, GWL_HWNDPARENT, _
            HWND_DESKTOP) 'calling the minimize function.
           setwindowlong(application.handle, _
            GWL_HWNDPARENT, form.handle)
           Form.SHOWMODAL
      
           SUB LAUNCH
            FORM.WINDOWSTATE = 1
      
            IF UCASE$(EDIT1.TEXT) = "ABOUT" THEN
             SHOWMESSAGE "ABOUT"
             EXIT SUB
            END IF
      
            IF UCASE$(LEFT$(EDIT1.TEXT, 7)) = "HTTP://"
            THEN
             rediff = ShellExecute(FORM.HANDLE, "Open",
             EDIT1.TEXT, "", "", 1)
      
            ELSE
             IF UCASE$(LEFT$(EDIT1.TEXT, 6)) = "FTP://"
             THEN
              rediff = ShellExecute(FORM.HANDLE, "Open",
              EDIT1.TEXT, "", "", 1)
             END IF
             rediff = ShellExecute(FORM.HANDLE, "Open",
             "http://"+EDIT1.TEXT, "", "", 1)
            END IF
           END SUB
      
           SUB FILTER (KEY AS WORD)
            SELECT CASE KEY
            CASE 13
             LAUNCH
      
            CASE 27
             FORM.CLOSE
      
            END SELECT
           END SUB
      
  12. 数组的快速初始化

    From Appendix C : Other Detailed Keywords

    ----------------
    DEF... Statement
    ----------------
    DEFBYTE, DEFDBL, DEFDWORD, DEFINT, DEFLNG, DEFSHORT, DEFSNG, DEFSTR,
    DEFWORD are declaration statements that name one or more variables and
    allocates storage space for them.

    Syntax: DEFINT variable[(subscripts)] [, ...]
    DEFSTR A, B, C="Hello", D, E
    DEFINT I=99, J(100,10), K

    Details:
    You cannot specify a range of variables, for example: DEFINT A-Z works
    fine under QBasic, but not Rapid-Q. You can initialize each variable as
    demonstrated above. DEF... statements are equivalent to calling DIM, but
    can save you a lot of typing. To initialize an array, wrap the values
    around curly braces {...}. For Example,

    DEFINT A(1 TO 10) = {1,2,3,4,5,6,7,8,9,10}
    Initializes elements 1 through 10 with the values 1, 2, 3, 4, 5, 6, 7,
    8, 9, and 10 respectively.

    -------------------------
    INITARRAY ARRAY Statement
    -------------------------
    Initializes an array with the corresponding values.

    Syntax: INITARRAY(Array, value [, ...])
    DIM A(1 TO 100) AS INTEGER
    INITARRAY(A, 55, 234, 45, 99)

    Details:
    Equivalently:
    DEFINT A(1 TO 100) = {55, 234, 45, 99}

    Initializing arrays as opposed to looping through each one saves a bit
    of time.

    --
    Alan Jones

  13. 在Form中直接显示字符
    --- In rapidq@y..., "achim_kokoska" <achim.kokoska@g...> wrote:
    > Hello mates,
    > maybe a very short problem:
    > I did not manage to print text on a single form:
    >
    > CREATE Win1 AS QFORM
    > END CREATE
    > Win1.TEXTOUT (1,1,"Hello World",1,0)
    > Win1.SHOWMODAL
    >
    > does not work, why ?
    >
    > Please give me an advice.
    >
    > Thank a lot, very best regards
    > Achim

    You need to put your textout in the form's onpaint routine like so:

    declare sub formpaint

    CREATE Win1 AS QFORM
    onpaint = formpaint
    END CREATE
    Win1.SHOWMODAL

    sub formpaint
    Win1.TEXTOUT (1,1,"Hello World",1,-1)
    end sub

    also, the -1 makes the text background transparent

© Thu 2024-12-26  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-21 21:13:21