1. Introduction to OLE technology
OLE and DDE are mechanisms that support mutual communication between Windows applications. OLE technology integrates Windows applications through "objects", which use images, charts, databases, sounds, texts, etc. to form composite objects (also called composite documents). OLE technology is a set of protocols for implementing linked objects or embedded objects in compound documents. This technology was first proposed by Aldus in 1988 and was later introduced into Windows by Microsoft. Using OLE, an application can cooperate with other applications to produce composite documents containing different types of objects, and the objects contained in the document can be easily manipulated by users.
Windows software that supports OLE calls will have registration information in Windows. Check the content of the [embedding] section in WIN.INI to know which OLE objects are included in Windows and can be called. Paintbrush (PBRUSH.EXE), statistical graph (MicrosoftGraph), object packager (PACKGER.EXE) and recorder (SOUNDREC.EXE) are commonly used OLE embedded programs in the Windows environment.
Enter the object.
Most development tools in the Windows environment (such as C, C++, PASCAL, VisualBasic3.0, CA-Realizer, FoxPRoforWindows, VisualFoxProforWindows, etc.) mostly support the development of applications with the ability to call OLE objects. In contrast, VisualBasic3.0 development OLE calling programs is easier.
There are many advantages to developing applications using OLE technology in Windows environment:
(1) Improve software development efficiency: By embedding OLE into other WINDOWS applications, the software development work performed by application programmers actually becomes software integration (or "software combination"), which is easier than developing software functions one by one. The modules are much faster and the development cycle of application software is greatly shortened;
(2) Stable and reliable performance: Since OLE embedded object programs are commercial software that have been rigorously tested, the "combined" software only needs to be rigorously tested for the "combined process" part (the workload of testing is relatively large). is relatively small), it can become high-quality software with stable and reliable performance;
(3) Complete functions: OLE is embedded in other WINDOWS applications, not only "embedding" the data of other applications, but also "embedding" the functions of other applications. All WINDOWSOLE embedded objects can be "embedded" in the application software. For example, you can use Word, Excel, Mail, Microsoft Graph, etc. to build a comprehensive office automation system software including word processing, electronic reports, e-mail and statistical graphics;
(4) Developers no longer need to be programming experts: Visual Basic 3.0 provides the OLE2.0 calling function, which greatly reduces the difficulty of OLE calling. General software developers can develop applications that call Windows OLE objects.
Visual Basic for Windows 3.0 (hereinafter referred to as VB) is an advanced development system for Windows. It adopts event-driven mechanism, visual interface design and integrated development, debugging and compilation environment. VB also provides DDE and OLE program development functions. VB is suitable for both junior programmers and senior programmers to write powerful application software.
2. Design of general drawing system
1. Add MicrosoftDrawOLE tool to Windows:
(1) Modify win.ini:
[embedding]
MSDraw=MicrosoftDrawing,MicrosoftDrawing,c:/yzgraph/msdraw.exe,picture
(2)Create MSDRAW.REG:
REGEDIT
HEKY_CLASSES_ROOT/MSDraw=MicrosoftDrawing
HKEY_CLASSES_ROOT/MSDraw/protocol/StdFileEditing/server=c:/yzgraph/msdraw.Exe
(3) Run REGEDIT.EXEMSDRAW.REG, and "The information in c:/yzgraph/msdraw.exe" has been successfully logged in the login database" will appear on the screen.
(4) Copy MSDRAW.EXE and MS-DRAW.HLP from the /windows/msapps/msdraw subdirectory in the Chinese version of Microsoft Word 5.0 to the c:/yzgraph subdirectory.
2. Create a FORM1 in VB: start VisualBASIC3.0 and select the File-NEWProject menu;
3. Create three button objects on FORM1: "Save", "Print" and "Exit";
4. Create an OLE2 object on FORM1: Select the OLE2.0 control in the Toolbox window, move the mouse to the Forml window, press the left mouse while moving the mouse cursor and drag out a small rectangle. Release the left mouse. At this time, the "insertobject" dialog window will appear on the screen. Select CreateNew-MicrosoftDrawing-ok. At this time, MicrosoftDrawing will start and exit MicrosoftDrawing;
5. Add a graphics save and print control (mhoutbx.vbx) in Visual Basic 3.0:
mhoutbx.vbx is a universal VBX control with graphic display and printing functions provided by MicroHelp. Select the File-AddFile menu in VisualBasic3.0 and select mhoutbx.bx;
AutoSize=-1'True
EraseForRead=-1'True
6. Create a mhoutbx object for graphics saving and printing on FORM1 (used for MicrosoftDraw
Result saving, printout);
7. Make FORM1 always at the "top" (that is, not covered by other windows):
Global.bas:
GlobalConstSWP_MOVE=2
GlobalConstSWP_NOSIZE=1
GlobalConstFLAGS=SWP_MOVEOrSWP_NOSIZE
GlobalConstHWND_TOPMOST=-1
GlobalConstHWND_NOTOPMOST=-2
DeclareFunctionSetWindowsPosLib"user"(ByValh,ByValhb,ByValX,
ByValy,ByValcx,ByValcy,By-Valf)AsInteger
DeclareFunctionGetSystemMetricsLib"user"(ByValnIn-dex)
GlobalConst
NILL=0&
GlobalConstWM_SYSCOMMAND=&H112
GlobalConstWM_LBUTTONDBLCLK=&H203
GlobalConstSC_CLOSE=&HF06O
GlobalConstWM-CLOSE=&H10
GlobalConstWM_GETMINMAXINFO=&H24
DeclareFunctionFindWindowsLib"User"(ByVallpClassNameAsAny,
ByVallpWindowsNameAsAny)
AsInteger
DeclareFunctionsendmessage&Lib"user"(ByValhWnd,ByValwmsg,
ByValwparam,ByValiparamAsLong)
GlobalConstSW_SHOWMAXIMIZED=3
DeclareFunctionShowWindowsLib"User"(ByValhWndAsInteger,
ByValnCmdShowAsInteger)AsInteger
8. Activate MSDraw and maximize it:
SubForm_Load()
Dimrc,msdraw_h,Ipclass$,lpcaption$
form1,Width=Pane13D1.Width
rc=SetWindowPos(form1.hWnd,HWND
_TOPMOST,0,0,0,0,Flags)
rc=sendmessage(form1,OLE1.hWnd,WM
_LBUTTONDBLCLK,0,NILL)
AppActivate"MicrosoftDraw-Drawing"
SendKeys"F",True
SendKeys"{LEFT}X",True
form1.Show
EndSub
9. Graphic save:
SubPanel3D1_Click()
a$="c:/test.wmf"
AppActivate"MicrosoftDraw-Drawing"
SendKeys"FU",True
FORM1.MhOutbox1.MetaFileName=a$
FORM1.MhOutbox1.SaveMetaFile=True
EndSub
10. Graphic printing:
SubPanel3D2_Click()
AppActivate"MicrosoftDraw-Drawing"
SendKeys"FU",True
MhOutboxl.OutContext=1
MhOutbox.EndPage=True
EndSub
11. Exit:
SubPanel3D3_Click()
Unloadform1
End
EndSub->