====================================== FoxPro Developers Network of San Diego ====================================== FoxDev TipsLetter #99-8 August 2, 1999 Website: Editor: ---------------------------------------------------------------------- CONTENTS: * Calendar * Tech Tips: Hiding the Windows Taskbar Art Bergquist Using Stored Procedures in the DBC Steve Settimi Adding a VFP Database to SQL Server Microsoft * Other Stuff: Customizing the BSOD - For Real! Dan Covill Consulting Solutions Group * Administrivia ====================================================================== CALENDAR: We are now alternating meetings between Escondido and Sorrento Mesa. All meetings are at 7:00 pm. August 4 Escondido John Little of Microsoft will give an overview of SQL 7. Sept 1 Sorrento Mesa Claude Nikula will demonstrate managing SQL Server 7.0 from VFP. Escondido meetings are at Bergelectric, 2222 Meyers Avenue. Take the Nordahl exit from Highway 78 (west of I-15). Head South. Right on Meyers Ave, first right past Mission. It's a one-story building on the right (there's no sign). Sorrento Mesa meetings are in the PS Business Center, 6450 Lusk Blvd. From the Lusk Blvd driveway, go straight back to the furthest corner of the rear bldg and park. The conference room is upstairs over the Fitness Center. ====================================================================== TIPS ====================================================================== HIDING THE WINDOWS TASKBAR Art Bergquist Based on inputs from the FoxShare ListServ, I came up with a program to hide/show the Windows task bar. The program would be useful, for example, in a POS (Point of Sale) application where users (read: employees) should not be able to switch out and play Solitaire, MineSweeper, etc. Here's the program: *------------------------------------------------- * WTASKBAR.PRG - Show or hide the Windows task bar * lParameters tlShowWindowsTaskBar(O) * Whether to show (.T.) or hide (.F.) the Windows task bar * * USAGE: * WTaskBar(.t.) && Show the Windows task bar * WTaskBar(.f.) && Hide the Windows task bar * WTaskBar() && Hide the Windows task bar * *------------------------------------------------- lparameters tlShowWindowsTaskBar declare integer FindWindow in user32.dll string, integer declare ShowWindow in user32.dll integer, integer lnHandleTaskBar = FindWindow("Shell_TrayWnd", 0) if tlShowWindowsTaskBar then ShowWindow(lnHandleTaskBar, 1) && Show Windows task bar * Bring this application back to the foreground DECLARE INTEGER SetForegroundWindow IN win32api INTEGER SET LIBRARY TO FoxTools.FLL && To access the MainHWnd() function * MainHWnd() returns the window handle (HWND) of the main VFP window SetForegroundWindow( MainHWnd() ) else ShowWindow(lnHandleTaskBar, 0) && Hide Windows task bar endif *------------------------------------------------- Unfortunately, I currently do not know how to intercept and in *both* Windows NT and Windows 95/98. Art Bergquist *--------------------------------------------------------------------- USING STORED PROCEDURES IN THE DBC by Steve Settimi You may think of the stored procedure file in a DBC as the place where Referential Integrity Rules are stored. It is, but it also serves as a public library in which any Function or Procedure may be kept. And being public, the code is always accessible. Put different code in different DBCs; it doesn't matter, it's all accessible if the DBC is open. (If it isn't open and you call on a procedure/function an error is generated.) Try this from the command window: CREATE data MyData MODIFY PROCEDURE "The Stored Procedures for MyData" window will now be open. Using the ol' Hello world maxim, with a twist, type in: PROCEDURE HelloWorld Messagebox("That's my line!!! OK?") ENDPROC Exit "The Stored Procedures for MyData" window, and from the command window type: HelloWorld() What's this good for? You can have a procedure that generates primary keys, or business rules, or any other task associated with the database, that is always available when the database is open. Let's say you set up procedures for record validation, field validation, table inserts and updates in your DBC, and have procedures that are called that do these methods (Business Rules). You can call on these rules from a form BEFORE commiting changes to the table, before validating control values, or before table updates or inserts. Preemptive tasking, to coin a term. Just put the procedure calls in the Database table designer for any field, table or view, then put the code in the Stored Procedures file. For instance, in a table called "foo", place in the RecordValidation option (inside DBC, modify table, under the "Table" tab, Record Validation Rule) the call: RecordValidation('foo'). Then in the Stored Procedures have a procedure called RecordValidation with a CASE statement for evey table in the DBC. Then with the CASE roll through the fields and apply your business logic. Things to remember: If the RecordValidation procedure is called upon natively by the DBC it must return .T. to validate or VFP will give you a nice message box telling you it doesn't. But with Preemptive Tasking, you call on this procedure in code before TableUpdate(), clean-up the user's wrong-doing or the like, and then when the Record Validation rule actually fires there will be no complaint. Steve Settimi *--------------------------------------------------------------------- ADDING A VFP DATABASE TO SQL SERVER Microsoft HOWTO: Add a FoxPro Database to SQL Server as a Linked Server The information in this article applies to: Microsoft Visual FoxPro for Macintosh, version 3.0b Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0, 5.0a, 6.0 Microsoft SQL Server version 7.0 SUMMARY SQL Server 7.0 allows the addition of external data sources as linked servers. This feature provides access to distributed, heterogeneous queries against OLE DB data sources. This article shows how to programmatically add and query a Visual FoxPro data source as a linked server from Visual FoxPro. MORE INFORMATION sp_addlinkedserver is a new stored procedure introduced in SQL Server 7.0. sp_addlinkedserver creates a linked server, which allows access to distributed, heterogeneous queries against OLE DB data sources. The syntax for adding a linked server from Transact - SQL is: sp_addlinkedserver [@server =] 'server', [@srvproduct =] 'product_name', [@provider =] 'provider_name', [@datasrc =] 'data_source', [@location =] 'location', [@provstr =] 'provider_string', [@catalog =] 'catalog' [@server =] 'server' Is the name of the linked server to create with sp_addlinkedserver. [@srvproduct =] 'product_name' Is the product name of the OLE DB data source to add as a linked server. [@provider =] 'provider_name' Is the unique provider identifier of the OLE DB provider corresponding to the data source. [@datasrc =] 'data_source' Is the name of the data source, as interpreted by the OLE DB provider. [@location =] 'location' Is the location of or path to the database as interpreted by the OLE DB provider. [@provstr =] 'provider_string' Is the OLE DB provider-specific. [@catalog =] 'catalog' Is the catalog to be used when making a connection to the OLE DB provider. The following code snippet adds the Visual FoxPro database Testdata.DBC from the SAMPLES\DATA directory to SQL Server as a linked server. NOTE: This code snippet assumes that Visual FoxPro and SQL Server are being run on the same machine. Source_Path=IIF(VAL(SUBSTR(VERSION(),15,2))=6,HOME(2),HOME()+"SAMPLES\") Connect_String='DRIVER={SQL Server};' + ; 'SERVER=MY_SERVER;DATABASE=PUBS;UID=SA;PWD=' gnConnHandle=SQLSTRINGCONN(Connect_String) IF gnConnHandle > 0 * Create a command string to pass to SQL Server via SQLExec SQLCommand="sp_addlinkedserver 'VFP','','MSDASQL',NULL,NULL,"+ ; "'DRIVER={Microsoft Visual FoxPro Driver};" + ; "SourceDB="+Source_Path+"DATA\TESTDATA.DBC;SourceType=DBC;NULL'" * CREATE the LINKED Server" Create_Linked_Server=SQLExec(gnConnHandle,SQLCommand) IF Create_Linked_Server > 0 * The linked server was successfully created * Run the query =RunQuery() ELSE * The Linked Server either already exists or the command failed. * Test for existence of linked server with aerror() =AERROR(s_failed) IF "VFP' ALREADY EXISTS."$UPPER(s_failed[1,2]) * The linked server exists, so run the query =RunQuery() ELSE * The linked server doesn't exist, so display a message =MESSAGEBOX(s_failed[1,2],32,'Failed') ENDIF ENDIF =SQLDISCONN(gnConnHandle) ENDIF PROCEDURE RunQuery SQLCommand="SELECT * FROM OPENQUERY(VFP,'SELECT * FROM CUSTOMER')" QRYVal=SQLExec(gnConnHandle,SQLCommand,'SQLRESULTS') IF QRYVal > 0 SELECT SQLResults BROW ELSE =AERROR(L_Server) =MESSAGEBOX(L_Server[1,2],32,'Query Failed') ENDIF RETURN After running the code snippet, open SQL Server Enterprise Manager and expand the Linked Servers node. Note that a linked server named VFP has been added. REFERENCES For more information about sp_addlinkedserver, search for "sp_addlinkedserver" in the Transact - SQL Reference Help file. (c) Microsoft Corporation 1999, All Rights Reserved. Contributions by John Desch, Microsoft Corporation ====================================================================== OTHER STUFF ====================================================================== CUSTOMIZING THE BSOD - FOR REAL! Dan Covill [A couple of months ago I ran a parody article about customizing the infamous Blue Screen Of Death. (The theory being that people see it so much it's only fair to let them set it up the way they prefer!) Well, life imitates art - somebody's actually done it!] http://www.pla-netx.com/linebackn/news/bsodprop.zip http://www.pla-netx.com/linebackn/news/bsod.html "Are you tired of the same old blue screen of death? Well say good-bye blue screen and hello to green screen, or purple screen, or black screen of death! Just download this simple little utility called BSOD Properties and select your favorite color. This program makes use of some old Windows 3.1 options in the system.ini file that have been long forgotten, but are still present in Windows 9x." [Excerpted from the weekly e-mail newsletter "Lockergnome". Check it out at . DC] ---------------------------------------------------------------------- SOLUTIONS CONSULTING GROUP Solutions Consulting Group, at 6540 Lusk Blvd, is the host for our Sorrento Mesa meetings. But who are they, and what do they do? "Since its inception in 1993, Solutions Consulting Group has grown to more than 40 employees with over 65 active clients throughout Southern California. We are a Microsoft Certified Solution Provider Partner and a member of the Oracle Business Alliance Program." They do: Corporate Application Development Data Warehousing Network Services They work in FoxPro, VFP, VB, Access, SQL, and Oracle. They are looking for more employees and they do use contractors as well; contact Armando Andrade at if you're interested. For More Information... --------------------------Administrivia------------------------------- This newsletter is a service to members of the FoxPro Developers Network of San Diego (FPDN). The editor (Dan Covill) is solely responsible for the content, Barbara Peisch does the distribution. E-mail the editor YOUR tips, comments, complaints, and rebuttals. Editor: Dan Covill 858-272-2448 Board of Directors: Eric Lendvai - President 760-439-6617 Art Bergquist - Vice Pres 760-740-0428 Claude Nikula - Secretary 619-615-6318 Barbara Peisch - Treasurer 760-729-9607 Randy Barber - Director 619-670-7542 Steve Settimi - Director 619-262-5883 ----------------------------------------------------------------------