1 / 23

Windows Software Development Lecture 9

Windows Software Development Lecture 9. MIS288 Instructor – Larry Langellier. Where Are We?. Last Lecture Creating an ActiveX Control Create an ActiveX control from constituent controls Understand design time and run time when developing ActiveX controls

talbot
Download Presentation

Windows Software Development Lecture 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Windows Software DevelopmentLecture 9 MIS288 Instructor – Larry Langellier

  2. Where Are We? • Last Lecture • Creating an ActiveX Control • Create an ActiveX control from constituent controls • Understand design time and run time when developing ActiveX controls • Create ActiveX controls that support Property Pages • Tonight – Understanding the Windows Application Programming Interface • Programming the Windows Registry • Dynamic Link Libraries • Executing other programs from VB

  3. Introduction to the Registry • Replacement for .ini files • Stores machine hardware and software configuration • User list • … and just about anything else

  4. Registry Structure • Divided into sections • HKEY_CLASSES_ROOT - software configuration settings - Points to HKEY_LOCAL_MACHINE • HKEY_LOCAL_MACHINE - contains the machine configuration • Divided into Hardware and Software sections • HKEY_CURRENT_USER - profile of the current user • HKEY_CURRENT_CONFIG - current system configuration

  5. VB Registry Functions • GetSetting retrieves a registry setting • SaveSetting writes a registry setting • Reading and writing the complete registry requires DLL calls • VB writes to a protected Registry area so no danger exists of corrupting critical information • HKEY_USERS\.Default\Software\VB and VBA Program Settings • To read and write from other Registry locations, you must use WinAPI functions

  6. GetSetting Example pstrSetting = GetSetting _ (App.Title, _ "section", _ "key", _ "setting") Application Name Registry Section Registry Key Value

  7. SaveSetting Example SaveSetting _ (App.Title, _ "section", _ "key", _ "setting") Application Name Registry Section Registry Key Value

  8. DeleteSetting Function • Removes key/value pair, section, or application settings • Example – Ch16_C.vbp • Recently Opened Files first • Form_Load • Form_Unload • mnuFileOpen_Click DeleteSetting App.Title, "Files", "File1" DeleteSetting App.Title, "Files" DeleteSetting App.Title

  9. RegEdit • Not available from Start menu so as to hide from ordinary users – type RegEdit from the Run menu • Locate Registry information • Edit Registry sections / keys • Be careful

  10. Manual Server Registration • RegSvr32 registers and unregisters servers • Register • RegSvr32servername • Unregister • RegSvr32 /u servername

  11. Dynamic Link Libraries (DLLs) • Windows Application Programming Interface (API) made up of callable dynamic link libraries • Programmer interface into operating system functions • Used to perform tasks not supported by Visual Basic

  12. Static Linking vs Dynamic Linking • Static • All program code contained in executable • Dynamic • Program stores a reference to external libraries • Linking occurs dynamically at run time hence the name

  13. Declaring a DLL Function • Library name must be made known to Visual Basic • Function in that library must also be made known • Declare statement does this • Syntax • DeclareFunctionnameLib“libname” [Alias “aliasname”] [(arglist)] AsType • name is the name used by VB program code • libname contains name of DLL • aliasname contains name of the function as named inside the dll • arglist contains the function arguments

  14. DLL Function Declarations (cont.) • Example: • Uses of aliases • simplify names • allow VB to use functions with illegal characters • Functions with leading underscores • override VB functions • Beep Declare Function SetWindowPos _ Lib "user32" _ (ByVal hwnd As Long, _ ByVal hWndInsertAfter As Long, _ ByVal x As Long, _ ByVal y As Long, _ ByVal cx As Long, _ ByVal cy As Long, _ ByVal wFlags As Long) As Long

  15. DLL Function Arguments • Usually passed by value • Correct data types are critical • Accuracy of return type is also critical • C / Visual Basic data types

  16. API Text Viewer • API Text Viewer helps to locate: • function names • constants • types • Start Menu • MS VS 6.0 Tools • Load Text File • Common\Tools\WinAPI\Win32API.txt • Uses clipboard to copy and paste function prototypes to VB

  17. Using DLL’s • Public Declare restricted to standard modules • Private Declare can be used in form modules • Create a wrapper procedure in a standard module to hide the DLL from other programmers • Example Public Sub SetTop(frm As Form) Dim plngFlags As Long, plngResult As Long plngFlags = SWP_NOSIZE Or SWP_NOMOVE frm.Show plngResult = SetWindowPos(frm.hWnd, _ HWND_TOPMOST, 0, 0, 0, 0, plngFlags) End Sub

  18. ByRef and ByVal • Most DLL arguments passed by value (ByVal) • When passing strings ByVal, Visual Basic passes a pointer to the string • Suggest using Fixed length strings and manually terminate with null byte Chr(0) • Cannot pass string properties directly • Example • SetTop in API.BAS module

  19. Making Temporary Files • Many programs use scratch / temporary files • File names must be unique • GetTempPathA gets Windows temp directory • GetTempFileNameA gets a unique file name

  20. Temporary File Wrapper Public Function GetTempFile() As String Dim pstrPrefix As String * 4 Dim pstrPath As String * 255 Dim pstrFileName As String * 1024 Dim pintSize As Integer Dim plngSize As Long pstrPrefix = "VBT" & Chr(0) pintSize = GetTempPathA(255, pstrPath) plngSize = GetTempFileNameA(pstrPath, _ pstrPrefix, 0, pstrFileName) GetTempFile = pstrFileName End Function Fixed length strings Null terminate

  21. Passing Properties • Properties cannot be passed directly • Create a variable of the proper type and store the property value Dim pstrTempPath As String * 255 pstrTempPath = Text1.Text & Chr(0) pintSize = GetTempPath(255, pstrTempPath)

  22. Executing Other Programs • Shell function runs executable programs • Syntax • Shell (pathname,windowstyle) • pathname contains program to execute • windowstyle determines initial appearance • Example On Error Resume Next Dim pintID As Long cdl1.Filter = "Executable files (*.exe)|*.exe" cdl1.ShowOpen pintID = Shell(cdl1.filename, vbNormalFocus)

  23. What Next? • Next Week • Spring Break!!! • Following Week • Read Chapter 15 (Section B) – HTML Help • Creating and compiling an HTML Help System • Connecting the help system to an application • Midterm Project is due at the end of class

More Related