home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer's Journal Buyer's Guide / Visual_Basic_Programmers_Journal_Buyers_Guide_CD-ROM_1994.iso / vbpjiss / qna.rpl (.txt) < prev    next >
Farallon Replica Document  |  1994-03-15  |  47KB  |  1 lines

  1. Q & Aby Carl Franklinand Ethan WinerVideo ClipsIn Visual BasicThis is your forum for addressing the intricacies of the Visual Basiccode, located in the Form_Load procedure. Since the video is displayedlanguage. Send in your questions, clever tips, and techniques. Visualin a VB picture control, you can move the video image anywhere on yourBasic ProgrammerÆs Journal will pay $25 for any submission or questionform.that we print. If your submission includes code, please send a disk alongThe MCI controlÆs DeviceType property defines the file format towith your hard copy.display (or record, as the case may be). Set this property to ôAVIVideoöMail submissions to Q&A Columnists, c/o Fawcette Technicalto use Video for Windows files. The next step is to open your AVI file.Publications, 280 Second Street, Suite 200, Los Altos, CA, USA, 94022-Set the FileName property to a valid AVI file name. Make sure you give3603. INTERNET:71732.3233@CompuServe.COM.the full path, unless the AVI file is in the current directory. Then, set theINTERNET:RobertVBPJ@AOL.COM.command property to ôOpenö to load the file. The next line of code tellsthe MCI control to display the video clip in Picture1, a standard VisualBasic picture control. If you omit this line, the video clip will be displayedin a separate window.DISPLAY AVI VIDEO FILESUSING VISUAL BASICI cannot seem to get Microsoft Video for Windows AVI filesto display in Visual Basic 3.0 Professional Edition, but I know it can beDROPPING FILES ON A FORMdone. Can you define the position and size of the display window?How do I make a Visual Basic program that has the power to drag filesWhatÆs involved?to other applications the way File Manager can?ùKeith Schaefer, Pleasant Grove, CaliforniaùRobert Lausevic, Sacramento, CaliforniaYou can use the Multimedia control (MCI.VBX) to display anAVI file in Visual Basic. The MCI control is one of the mostCurrently, the File Manager version 3.1 is the only server application thatmisunderstood controls, mostly because it does so much. It cansupports the drag-and-drop protocol. However, future versions of Win-play back digital audio files, MIDI files, movies, AVI files, and CD-dows will enable an application to be a drag-drop server. A server canaudio, with provisions for controlling digital audio tape (DAT) ma-initiate a file drag-and-drop sequence, and a client can receivechines, scanners, VCRs, and other devices.dropped files.At design time, the MCI control is a button bar that resembles theHowever, Windows has support for drag-and-drop clients.transport controls of a tape deck. There are buttons for rewind, play,The code in Listing 2 enables a VB form to receive filesrecord, stop, pause, and so on. The MCI control can be visible at run timedropped from the File Manager. When files are dropped on the form fromor invisible, in case you want to control it with code.the File Manager, the names are displayed on the form. This simpleListing 1 shows a sample program in which an MCI control and aapplication requires only that you add the code in Listing 2 to a moduleVisual Basic Picture control have been placed on a form. The programin a new project. No custom controls are required. However, there areallows the user to display an AVI file in the picture box by manipulatingthird-party add-on tools available that supply the same functionality.the transport buttons on the MCI control. There are only four lines ofIn the Main( ) subroutine, after displaying the form, the first thing todo is tell Windows that Form1 is to receive WM_DROPFILES messagesSub Form_Load ()by calling DragAcceptFiles. If you do not make this call, the user will seea circle with a line through it when he attempts to drop a list of files onMMControl1.DeviceType = "AVIVideo"the form.MMControl1.FileName = "C:\BIRD.AVI"MMControl1.Command = "Open"MMControl1.hWndDisplay = Picture1.hWndCarl Franklin develops programming tools in C, Visual Basic, and DOSBasic for Crescent Software. Carl also writes, plays, produces, andEnd Subengineers music in his spare time.Ethan Winer founded Crescent Software and is the author of CrescentÆsLISTING 1Display video. This code allows you to display an AVI videoQuickPak Professional and P.D.Q. Basic add-on products. Ethan hasclip in a Visual Basic application. Place an MCI.VBX controlwritten numerous magazine articles on programming and is a contribut-and a Picture control on a form, and enter this code into the Form_Loading editor to Visual Basic ProgrammerÆs Journal and PC Magazine.procedure. At run time you can click the play button (third from left) toContact Ethan or Carl at Crescent Software, 11 Bailey Ave., Ridgefield,play the video, and the rewind button (far left) to rewind, as well as pauseConnecticut 06877; 203-438-5300. EthanÆs CompuServe number is(fourth from left), stop (third from right), and step play (fourth from72241,63. CarlÆs is 70662,2605.right).Visual Basic ProgrammerÆs Journal   FEBRUARY/MARCH 1994     99Q & ADefInt A-Z'-- This loop occurs in the backgroundDo While DoEvents()Type POINTAPIx As Integer'-- Ask for a dropfile messagey As IntegerSuccess = PeekMessage(Message,_End Type0, WM_DROPFILES, WM_DROPFILES,_PM_REMOVE Or PM_NOYEILD)Type MsghWnd As Integer'-- Did we get a drop file message?Message As IntegerIf Success ThenwParam As Integer'-- Yes. hDrop returns a handle to thelParam As Long'-- "dropped files" structuretime As LonghDrop = Message.wParampt As POINTAPIEnd Type'-- How many files were dropped?INumFiles = DragQueryFile(hDrop, -1,_Dim Message As MsgFileName$, 127)Declare Function PeekMessage Lib "User" _'-- Clear the form(lpMsg As Msg, ByVal hWnd As Integer,_Form1.ClsByVal wMsgFilterMin As Integer,_ByVal wMsgFilterMax As Integer,_'-- Read all the file names.ByVal wRemoveMsg As Integer) As IntegerFor i = 0 To NumFiles - 1Declare Function DragQueryFile Lib "SHELL.DLL"_'-- Initialize a string with blanks(ByVal hDrop, ByVal Index, ByVal FileName$,_FileName$ = Space$(127)ByVal Size) As Integer'-- Get the next file name. L returnsDeclare Sub DragAcceptFiles Lib "SHELL.DLL"_'-- the string length.(ByVal hWnd, ByVal fAccept)L = DragQueryFile(hDrop, i,_FileName$, 127)Declare Sub DragFinish Lib "SHELL.DLL"_(ByVal hDrop)'-- Print the file name on the form.Form1.Print Left(FileName$, L)Const WM_DROPFILES = &H233Const PM_REMOVE = 1NextConst PM_NOYEILD = 2'-- DragFinish deletes the drop fileSub Main ()'-- structure.Call DragFinish(hDrop)'-- Show the formForm1.ShowEnd IfForm1.RefreshLoop'-- Tell Windows that we want Form1 to receive'-- drop file messagesEnd SubCall DragAcceptFiles(Form1.hWnd, True)LISTING 2Drag and drop files from File Manager. Start a new project, add a new module, and add this code to the module to enable a form to receivefiles from the File Manager. At run time, select one or more files from the Windows File Manager and drop them on your form. The filenames are displayed on the form. You must set the "Startup Form" to Sub Main in the Project Options menu for this code to work. In addition to workingwith a form, this code will work with any control that has an hwnd, such as a picture control.The DoEvents loop that follows will occur whenever the system is notbusy. The PeekMessage API call returns a value of -1 (True) if a receivedDeclare Function ExitWindows Lib "User"_message falls between the specified lower and upper range. In this case,(ByVal dwReturnCode As Long,_you only want to see one message, WM_DROPFILES, so both the lowerByVal wReserved As Integer) As Integerand upper range message values are set to WM_DROPFILES. If one ormore files are dropped on the form, PeekMessage will return a nonzeroConst EW_REBOOTSYSTEM = &H43value.Const EW_RESTARTWINDOWS = &H42When a WM_DROPFILES message is received, the wParam integerelement of the Message TYPE variable contains a handle to a list of fileSub Command1_Click ()'-- Restart WindowsSUB Reboot ()Dummy = ExitWindows(EW_RESTARTWINDOWS, 0)DEF SEG = 0End SubPOKE &H473, &H12Sub Command2_Click ()POKE &H472, &H34'-- Reboot the PCDEF SEG = &HFFFFDummy = ExitWindows(EW_REBOOTSYSTEM, 0)CALL ABSOLUTE(0)End SubEND SUBLISTING 3Restart DOS. This VB-DOS subroutine will reboot theLISTING 4Restart your engines! This code can be used todeclare and call the ExitWindows API function to rebootPC when called.the PC or restart Windows.100     FEBRUARY/MARCH 1994   Visual Basic ProgrammerÆs JournalQ & Anames (hDrop). This handle has no real value,define the location of the segment (or 64Kexcept that it can be passed to the DragQueryFileblock), and two bytes define the offset withinfunction to return the number of files droppedthat segment. Since POKE accepts only theon the form and their names. If you passaddress or offset portion, you must define theDragQueryFile a value of -1 as the secondsegment. The DEF SEG = XXXX statement isparameter (Index), DragQueryFile returns therequired to define the segment within 64K ofnumber of files that were dropped on the form.the POKE address. Therefore, the address thatTo return a particular file name, pass thethe first POKE statement accesses is actuallyzero-based file number as the second param-0000 0473 (hex). neter, and a fixed-length string as the third pa-rameter, and the string will return the file name.The return value of DragQueryFile is the lengthof the file name. You can simply use the Left$function to return only the file name from thefixed-length string.REBOOTING THE PCREBOOTING INWINDOWS IS EASY,BUT IN VB-DOS YOU HAVETO DO A LITTLEPOKING AROUND.FROM DOS OR WINDOWSHow can I reboot the PC from VB-DOS orWindows, and is there a way to just restartWindows from a VB app without rebooting?ùRoss Lally, Waterford, ConnecticutRebooting the PC is one of those things thatisnÆt required often, so there isnÆt much helpavailable on the subject. However, when youneed to reboot, thereÆs no substitute.Rebooting in Windows is easy: thereis an API call that reboots. But in VB-DOS, you have to do a little pokingaround.The code in Listing 3 is a VB-DOS routinethat reboots the PC, and Listing 4 is a VB-Windows example of both rebooting the PCand restarting Windows using the ExitWindowsAPI function.Note the use of POKE in the VB-DOS Reboot subroutine (see Listing3). If you didnÆt already know, POKEsets the value of a byte at a particularaddress in memory. Intel 80x86-based systemsuse a full address of four bytes. Two bytesVisual Basic ProgrammerÆs Journal   FEBRUARY/MARCH 1994     101