2010年11月15日 星期一

Genero 對 Windows 的支援 (進行中..未完)

What is DDE?
DDE is a form of inter-process communication implemented by Microsoft for Windows platforms. DDE uses shared memory to exchange data between applications. Applications can use DDE for one-time data transfers, and for ongoing exchanges in applications that send updates to one another as new data becomes available.
Please refer to your Microsoft documentation for DDE compatibility between existing versions. As an example, DDE commands were changed between Office 97 and Office 98. 

http://www.4js.com/techdocs/genero/fgl/devel/DocRoot/User/WinDDE.html


DDE Commands
引自 http://www.vsh.com/Documentation/WinList/helpid_ddecommands.htm

Dynamic Data Exchange (DDE) provides a way for Windows programs to share data and interact with one another. WinList currently supports DDE as a client of other applications. In other words, it can request information and instruct other applications to do things. It does not currently support DDE as a server of information.

When connecting WinList to other applications with DDE, there are several internal commands which WinList recognizes. These commands allow you to ship data to other programs and to retrieve data from them. Below is a list of the current internal DDE commands for WinList and an explanation of usage for each.

POKE
This command is used to send histogram or results data to another program in either TEXT format or VSH format. The syntax of the command is:
POKE(externalRef, format, optional internal reference)
where externalRef is a reference the other application uses to determine where to put or how to use the data, and format is either TEXT, TEXTNOHEADER, or VSH. TEXT format is supported by most applications that can paste text from the clipboard. TEXTNOHEADER format is identical to TEXT except that it sends a result window's text as a table of information, without column headings. It can only be used with results windows. VSH is a Verity Software House binary data format, which provides a more efficient use of memory. It pertains only to histogram connections and should be used when interacting with other VSH products or with products known to support the format.
The optional internal reference for histograms can be any histogram-related keyword, and for results windows can be any results-related keyword. See Internal Keywords for details.
Examples:
 POKE(DATA,VSH) - used to send data to ModFit or IsoContour.
 POKE(R1C1:R64C64,TEXT) - used to send a 64 x 64 resolution histograms to Microsoft Excel in TEXT format. Note the reference tells Excel to put the data into the active spreadsheet at row-1 column-1 to row-64 column-64.
 POKE(RC:R[+6]C[+6],TEXTNOHEADER) - used to send a results window to Microsoft Excel in TEXT format, excluding the column headings and id fields in the results window. The reference tells Excel to put the data into the active spreadsheet at a location starting at the current row and column, and extending through 6 rows and 6 columns. Relative references of this sort are very useful for adding results to a database without overwriting previous results.
 POKE(KEYWORDS,VSH,KEYWORDS) - used in a histogram connection to send keywords from the listmode file to a Verity application like ModFit LT 3.0 or greater.
 POKE(R1C1:R1C255,TEXT,KEYWORDS) - sends keywords from the listmode file to an application like Microsoft Excel. The format of the keywords is keyword followed by a tab character, then the keywordValue and another tab character.
 POKE(R1C1,TEXT,R1 Events) - sends the label "R1 Events" as text to an application like Microsoft Excel to place in row 1 column 1.
 POKE(R1C2,TEXT,{R(1,REGIONEVENTS)}) – evaluates the string "{R(1,REGIONEVENTS)}" as a keyword, and then sends the result as text to an application like Microsoft Excel to place in row 1 column 2. See Internal Keywords for a list of internal keywords supported by WinList. You can also specify FCS keywords for the optional argument of this command, e.g. {$DATE}. Note that keywords are enclosed with curley braces "{ }" instead of the usual square brackets "[ ]" when used in a remote script command.


PASTE
This command tells WinList to paste a copy of the contents of the Windows clipboard into the histogram or results window for display. The syntax is PASTE(format) where format is METAFILE or TEXT. METAFILE is a picture format supported by many Windows graphic programs and can be used by both Results and Histogram windows. TEXT format should only be used with Results windows. When WinList successfully completes the PASTE command, the pasted object will be displayed in the window.
Examples:
 PASTE(METAFILE) is used to get a copy of a picture from the clipboard. It can be used both by Results and Histogram windows.
 PASTE(TEXT) is used to get a copy of text from the clipboard. It can be used only by Results windows.

COPY
This command tells WinList to copy the results or histogram window to the Windows Clipboard so that another application can paste it into its workspace. Its syntax is COPY(format) where format can be METAFILE, TEXT, or BITMAP.
Examples:
 COPY(METAFILE) is used to copy a picture of a histogram to the clipboard. It can be used only by Histogram windows.
 COPY(TEXT) is used to copy text to the clipboard. It can be used only by Results windows.
 COPY(TEXTNOHEADER) is used to copy text to the clipboard. It can be used only by Results windows. The only difference between this format and TEXT format is that TEXTNOHEADER strips off all lines up to and including the column headings. It is useful for databasing of results in another program using a DDE connection.

SETREGIONRESULT
This command tells WinList to set the value of a specific region's result to a value extracted from a remote application. Its syntax is SETREGIONRESULT("region reference","external request") where region reference is in R(n,stat)format and external request is a string which is requested from another application. For more information on R(n, stat) format, see Internal KeywordsExternal Request is expected to be a value number of the same type as the field it is copied to.
Examples:
 If connected to ModFit, SETREGIONRESULT("R(1,REGIONEVENTS)","A[1,0]") tells WinList to ask ModFit for the answer to "A[1,0]", and to put the result into the Region Events field for Region 1.

PAUSE
This command is supported by histograms. It displays a dialog with optional message and waits to proceed until the dialog is closed. The dialog appends "Press OK to continue or Cancel to stop the script." Its syntax is PAUSE(message) where message is optional text for the message.
Example:
 PAUSE(Please check results in ModFit LT.)


Front End Functions

Basics

The BDL language provides a specific method to call functions defined in the front end that will be executed locally on the workstation where the front end resides. When you call a user function from BDL, you specify a module name and a function name. Input and output parameters can be passed/returned in order to transmit/receive values to/from the front end. A typical example is an "open file" dialog window that allows you to select a file from the front end workstation file system.
A set of standard front end functions is built-in by default in the front end. It is possible to write your own functions in order to extend the front end possibilities. For example, you can write a set of functions to wrap an existing API, such as Window DDE or OLE. A set of user functions is defined in a module, implemented as a Windows DLL or UNIX shared library. These modules are loaded automatically according to the module name. See the front end documentation for more details about creating user function modules in the front end.
Tip: Regarding DDE/OLE APIs to manipulate Microsoft Office documents, note that there are freeware alternatives such as the Apache POI Java library which can be used with the Java Interface. See for example Java Interface: Example 2.

http://www.4js.com/techdocs/genero/fgl/devel/DocRoot/User/FrontEndFunctions.html



The Interface classhttp://www.4js.com/techdocs/genero/fgl/devel/DocRoot/User/ClassInterface.html










範例中的程式

Example

dde_example.per


01 DATABASE formonly
02 SCREEN
03 {
04 Value to be given to top-left corner :
05 [f00                                ]                                                                                                                                    
06 Value found on top-left corner :
07 [f01                                ]
08 }                                                                                                                                    
09 ATTRIBUTES
10   f00 = formonly.val;
11   f01 = formonly.rval, NOENTRY;

dde_example.4gl


01 MAIN
02   -- Excel must be open with "File1.xls"
03   CONSTANT file = "File1.xls"
04   CONSTANT prog = "EXCEL"
05   DEFINE val, rval STRING
06   DEFINE res INTEGER
07   OPEN WINDOW w1 AT 1,1 WITH FORM "dde_example.per"
08   INPUT BY NAME val
09   CALL ui.Interface.frontCall("WINDDE","DDEConnect", [prog,file], [res] )
10   CALL checkError(res)
11   CALL ui.Interface.frontCall("WINDDE","DDEPoke", [prog,file,"R1C1",val], [res] );
12   CALL checkError(res)
13   CALL ui.Interface.frontCall("WINDDE","DDEPeek", [prog,file,"R1C1"], [res,rval] );
14   CALL checkError(res)
15   DISPLAY BY NAME rval
16   INPUT BY NAME val WITHOUT DEFAULTS
17   CALL ui.Interface.frontCall("WINDDE","DDEExecute", [prog,file,"[save]"], [res] );
18   CALL checkError(res)
19   CALL ui.Interface.frontCall("WINDDE","DDEFinish", [prog,file], [res] );
20   CALL checkError(res)
21   CALL ui.Interface.frontCall("WINDDE","DDEFinishAll", [], [res] );
22   CALL checkError(res)
23   CLOSE WINDOW w1
24 END MAIN
25
26 FUNCTION checkError(res)
27   DEFINE res INTEGER
28   DEFINE mess STRING
29   IF res THEN RETURN END IF
30   DISPLAY "DDE Error:"
31   CALL ui.Interface.frontCall("WINDDE","DDEError",[],[mess]);
32   DISPLAY mess
33   CALL ui.Interface.frontCall("WINDDE","DDEFinishAll", [], [res] );
34   DISPLAY "Exit with DDE Error."
35   EXIT PROGRAM (-1)
36 END FUNCTION

#========================================
#test020.4gl
#========================================
#這段程式執行後會使用內定的軟體直接開始 c:\test.doc
#========================================
main
DEFINE path STRING, res INTEGER
LET path = "\"c:\\test.doc\""
-- This is: "c:\test.doc"
CALL ui.Interface.frontCall( "standard", "shellexec", [path], [res] )
end main


#========================================







沒有留言:

張貼留言