home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / olympus / ik32_15t / vb4.shr / commands.bas < prev    next >
Encoding:
BASIC Source File  |  1996-09-04  |  7.2 KB  |  243 lines

  1. Attribute VB_Name = "IKCommands"
  2. Option Explicit
  3.     
  4. '***Used for IKOD_GetScreenDepth***
  5. Private Const CCHDEVICENAME = 8
  6. Private Const CCHFORMNAME = 8
  7.  
  8. Type DEVMODE
  9.     dmDeviceName As String * CCHDEVICENAME
  10.     dmSpecVersion As Integer
  11.     dmDriverVersion As Integer
  12.     dmSize As Integer
  13.     dmDriverExtra As Integer
  14.     dmFields As Long
  15.     dmOrientation As Integer
  16.     dmPaperSize As Integer
  17.     dmPaperLength As Integer
  18.     dmPaperWidth As Integer
  19.     dmScale As Integer
  20.     dmCopies As Integer
  21.     dmDefaultSource As Integer
  22.     dmPrintQuality As Integer
  23.     dmColor As Integer
  24.     dmDuplex As Integer
  25.     dmYResolution As Integer
  26.     dmTTOption As Integer
  27.     dmCollate As Integer
  28.     dmFormName As String * CCHFORMNAME
  29.     dmUnusedPadding As Integer
  30.     dmBitsPerPel As Integer
  31.     dmPelsWidth As Long
  32.     dmPelsHeight As Long
  33.     dmDisplayFlags As Long
  34.     dmDisplayFrequency As Long
  35. End Type
  36.  
  37. Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As DEVMODE) As Long
  38. Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
  39. Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
  40. Sub GetFont(Picbuf As Control, CommonDialog As Control)
  41. On Error GoTo Cancel_Click
  42.     CommonDialog.FontName = Picbuf.Font.Name
  43.     CommonDialog.FontSize = Picbuf.Font.Size
  44.     CommonDialog.ShowFont
  45.     Picbuf.Font.Name = CommonDialog.FontName
  46.     Picbuf.Font.Size = CommonDialog.FontSize
  47.     Picbuf.Font.Bold = CommonDialog.FontBold
  48.     Picbuf.Font.Italic = CommonDialog.FontItalic
  49.     Picbuf.Font.Strikethrough = CommonDialog.FontStrikethru
  50.     Picbuf.Font.Underline = CommonDialog.FontUnderline
  51.     Exit Sub
  52.     
  53. Cancel_Click:
  54.     If Err.Number = 32755 Then
  55.         Exit Sub
  56.     Else
  57.         MsgBox Err.Description
  58.     End If
  59. End Sub
  60. Function GetBlue(ByVal RGBColor As Long) As Integer
  61.     Dim ColorComponentValue As Integer
  62.     ColorComponentValue = RGBColor \ 65536
  63.  
  64.     If ColorComponentValue < 0 Or ColorComponentValue > 255 Then
  65.         MsgBox "Assertion Falure:" + Chr(13) + "ColorComponentValue < 0 or > 255.  Invalid value of:" + Str(ColorComponentValue)
  66.     End If
  67.  
  68.     GetBlue = ColorComponentValue
  69. End Function
  70.  
  71.  
  72. Function GetColor(CommonDialog As Object) As Long
  73.     On Error GoTo Cancel_Click
  74.     CommonDialog.CancelError = True
  75.     CommonDialog.ShowColor
  76.     GetColor = CommonDialog.Color
  77.     Exit Function
  78.  
  79. Cancel_Click:
  80.     If Err.Number = 32755 Then
  81.         Exit Function
  82.     Else
  83.         MsgBox Err.Description
  84.     End If
  85. End Function
  86.  
  87. Function getGreen(RGBColor As Long) As Integer
  88.     Dim ColorComponentValue As Integer
  89.     ColorComponentValue = (RGBColor And 65535) \ 256
  90.  
  91.     If ColorComponentValue < 0 Or ColorComponentValue > 255 Then
  92.         MsgBox "Assertion Falure:" + Chr(13) + "ColorComponentValue < 0 or > 255.  Invalid value of:" + Str(ColorComponentValue)
  93.     End If
  94.  
  95.     getGreen = ColorComponentValue
  96. End Function
  97.  
  98.  
  99. Function getRed(RGBColor As Long) As Integer
  100.     Dim ColorComponentValue As Integer
  101.     ColorComponentValue = RGBColor And 255
  102.  
  103.     If ColorComponentValue < 0 Or ColorComponentValue > 255 Then
  104.         MsgBox "Assertion Falure:" + Chr(13) + "ColorComponentValue < 0 or > 255.  Invalid value of:" + Str(ColorComponentValue)
  105.     End If
  106.  
  107.     getRed = ColorComponentValue
  108. End Function
  109.  
  110.  
  111. Sub ExitProgram()
  112.     End
  113. End Sub
  114.  
  115.  
  116.  
  117.  
  118. Function GetScreenColorDepth() As Integer
  119.     Const BitsPixel = 12
  120.     Dim TempDevMode As DEVMODE
  121.     Dim ColorDepth, hDC, RetVar As Integer
  122.  
  123.     hDC = CreateDC("DISPLAY", "", "", TempDevMode)
  124.     ColorDepth = (GetDeviceCaps(hDC, BitsPixel))
  125.     RetVar = DeleteDC(hDC)
  126.  
  127.     GetScreenColorDepth = ColorDepth
  128. End Function
  129.  
  130.  
  131.  
  132. Sub LoadImage(Picbuf As Control, CommonDialog As Control)
  133.     
  134.     CommonDialog.DialogTitle = "Load Image"
  135.     CommonDialog.Filter = "all files|*.*|picture files|*.bmp;*.dib;*.jpg;*.pcx;*.png;*.tga;*.tif;*.fif|BMP|*.bmp|DIB|*.dib|JPEG|*.jpg|PCX|*.pcx|PNG|*.png|Targa|*.tga|TIFF|*.tif|FIF|*.fif"
  136.     CommonDialog.FilterIndex = 2
  137.     CommonDialog.InitDir = App.Path + "\..\Images\"
  138.     On Error GoTo Cancel_Click
  139.     CommonDialog.CancelError = True
  140.     CommonDialog.ShowOpen
  141.     Picbuf.Filename = CommonDialog.Filename
  142.     Picbuf.Load
  143.     Exit Sub
  144.  
  145. Cancel_Click:
  146.     If Err.Number = 32755 Then
  147.         Exit Sub
  148.     Else
  149.         MsgBox Err.Description
  150.     End If
  151. End Sub
  152. Sub SaveImage(Picbuf As Control, CommonDialog As Control)
  153.     Dim strFileExtension As String
  154.     
  155.     CommonDialog.DialogTitle = "Save Image"
  156.     CommonDialog.Filter = "TIFF|*.tif|Targa|*.tga|BMP|*.bmp|GIF|*.gif|DIB|*.dib|PCX|*.pcx|JPEG|*.jpg|FIF|*.fif|PNG|*.png"
  157.        
  158.     'this code sets the index for the CMDialog
  159.     If Picbuf.ImageFormat = 0 Then
  160.         'The following should work, but does not because the Right Function is not working correctly
  161.         'strFileExtension = UCase(Right(Picbuf.Filename, 3))
  162.         strFileExtension = UCase(Mid(Picbuf.Filename, Len(Picbuf.Filename) - 2, 3))
  163.     Else
  164.     strFileExtension = Picbuf.ImageFormat
  165.     End If
  166.     
  167.     Select Case strFileExtension
  168.         Case "TIF", 1
  169.             CommonDialog.FilterIndex = 1
  170.         Case "TGA", 2
  171.             CommonDialog.FilterIndex = 2
  172.         Case "BMP", 3
  173.             CommonDialog.FilterIndex = 3
  174.         Case "GIF", 4
  175.             CommonDialog.FilterIndex = 4
  176.         Case "DIB", 5
  177.             CommonDialog.FilterIndex = 5
  178.         Case "PCX", 6
  179.             CommonDialog.FilterIndex = 6
  180.         Case "JPG", 7
  181.             CommonDialog.FilterIndex = 7
  182.         Case "PNG", 8
  183.             CommonDialog.FilterIndex = 9
  184.         Case Else
  185.             CommonDialog.FilterIndex = 3
  186.     End Select
  187.     
  188.     
  189.     On Error GoTo Cancel_Click
  190.     CommonDialog.CancelError = True
  191.     CommonDialog.ShowSave
  192.     strFileExtension = UCase(Mid(CommonDialog.Filename, Len(CommonDialog.Filename) - 2, 3))
  193.     If Picbuf.ImageFormat = 0 Then
  194.         Select Case strFileExtension
  195.             Case "TIF"
  196.                 Picbuf.ImageFormat = 1
  197.             Case "TGA"
  198.                 Picbuf.ImageFormat = 2
  199.             Case "BMP"
  200.                 Picbuf.ImageFormat = 3
  201.             Case "GIF"
  202.                 Picbuf.ImageFormat = 4
  203.             Case "DIB"
  204.                 Picbuf.ImageFormat = 5
  205.             Case "PCX"
  206.                 Picbuf.ImageFormat = 6
  207.             Case "JPG"
  208.                 Picbuf.ImageFormat = 7
  209.                 If Picbuf.WriteCompression = 0 Then
  210.                     Picbuf.WriteCompression = 65
  211.                 End If
  212.             Case "FIF"
  213.                 Picbuf.ImageFormat = 9
  214.             Case "PNG"
  215.                 Picbuf.ImageFormat = 10
  216.         End Select
  217.     End If
  218.     Picbuf.Filename = CommonDialog.Filename
  219.     Picbuf.Store
  220.     Picbuf.ImageFormat = 0
  221.     Picbuf.WriteCompression = 0
  222.     Exit Sub
  223.  
  224. Cancel_Click:
  225.     If Err.Number = 32755 Then
  226.         Exit Sub
  227.     Else
  228.         MsgBox Err.Description
  229.     End If
  230. End Sub
  231.  
  232.  
  233.  
  234.  
  235. Sub SetSelect(Picbuf As Object, intLeft As Integer, intTop As Integer, intWidth As Integer, intHeight As Integer)
  236.     Picbuf.SelectTop = intTop
  237.     Picbuf.SelectLeft = intLeft
  238.     Picbuf.SelectWidth = intWidth
  239.     Picbuf.SelectHeight = intHeight
  240. End Sub
  241.  
  242.  
  243.