home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form frm256PicBx
- AutoRedraw = -1 'True
- BackColor = &H00C0C0C0&
- BorderStyle = 1 'Fixed Single
- Caption = "256 Color VB Picture Box Demonstration"
- ClientHeight = 3090
- ClientLeft = 1080
- ClientTop = 1425
- ClientWidth = 7245
- Height = 3495
- Left = 1020
- LinkMode = 1 'Source
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 3090
- ScaleWidth = 7245
- Top = 1080
- Width = 7365
- Begin PictureBox PicPreviewSource
- AutoRedraw = -1 'True
- BackColor = &H00E0E0E0&
- Height = 18375
- Left = 360
- ScaleHeight = 1223
- ScaleMode = 3 'Pixel
- ScaleWidth = 1729
- TabIndex = 0
- Top = 3720
- Visible = 0 'False
- Width = 25965
- End
- Begin PictureBox PicScrollBarFiller
- BackColor = &H00004080&
- Height = 255
- Left = 6870
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 13
- Top = 2730
- Width = 255
- End
- Begin HScrollBar PicPreviewHScroll
- Height = 255
- Left = 4740
- Max = 100
- TabIndex = 12
- TabStop = 0 'False
- Top = 2730
- Width = 2145
- End
- Begin CommandButton pbPreview
- Caption = "&Preview"
- Height = 345
- Left = 2790
- TabIndex = 11
- Top = 2640
- Width = 1335
- End
- Begin DriveListBox cbDrives
- BackColor = &H00C0C0C0&
- Height = 315
- Left = 150
- TabIndex = 7
- Top = 2670
- Width = 2175
- End
- Begin VScrollBar PicPreviewVScroll
- Height = 2115
- Left = 6870
- TabIndex = 10
- TabStop = 0 'False
- Top = 630
- Width = 255
- End
- Begin PictureBox PicPreview
- BackColor = &H00E0E0E0&
- Height = 2115
- Left = 4740
- ScaleHeight = 139
- ScaleMode = 3 'Pixel
- ScaleWidth = 141
- TabIndex = 9
- Top = 630
- Width = 2145
- End
- Begin FileListBox lbFileList
- BackColor = &H00C0C0C0&
- Height = 1785
- Left = 2580
- Pattern = "*.bmp"
- TabIndex = 8
- Top = 630
- Width = 1785
- End
- Begin DirListBox lbDirList
- BackColor = &H00C0C0C0&
- Height = 1785
- Left = 120
- TabIndex = 6
- Top = 630
- Width = 2175
- End
- Begin CommandButton pbCancel
- Cancel = -1 'True
- Caption = "E&XIT"
- Height = 375
- Left = 5370
- TabIndex = 14
- Top = 90
- Width = 1005
- End
- Begin Label Label4
- BackColor = &H00C0C0C0&
- Caption = "D&rives"
- Height = 195
- Left = 150
- TabIndex = 2
- Top = 2460
- Width = 1215
- End
- Begin Label Label3
- BackColor = &H00C0C0C0&
- Caption = "&Bitmap Files"
- Height = 195
- Left = 2580
- TabIndex = 5
- Top = 420
- Width = 1515
- End
- Begin Label Label2
- BackColor = &H00C0C0C0&
- Caption = "&Directories"
- Height = 195
- Left = 120
- TabIndex = 4
- Top = 420
- Width = 1635
- End
- Begin Label labDirSelected
- BackColor = &H00C0C0C0&
- Height = 195
- Left = 1800
- TabIndex = 1
- Top = 120
- Width = 3315
- End
- Begin Label Label1
- BackColor = &H00C0C0C0&
- Caption = "Current Directory:"
- Height = 195
- Left = 120
- TabIndex = 3
- Top = 120
- Width = 1635
- End
- ' Handle to our dll
- Dim hDIBUtil As Integer
- ' Handle to a palette created for previewing a bitmap
- Dim hPalette As Integer
- ' Handle to a global memory area into which a DIB file has been read
- ' (for use with DIB utility routines)
- Dim hDIBBuffer As Integer
- ' A pointer to the actual memory buffer containing the DIB
- Dim lpDIBBuffer As Long
- Sub cbDrives_Change ()
- lbDirList.Path = cbDrives.Drive
- End Sub
- Sub Form_Load ()
- OldMousePtr% = Screen.MousePointer
- Screen.MousePointer = HOURGLASS
- 'Remove all but Move and Close from the system menu
- Set_ModalDlg_SysMenu frm256PicBx
- 'Set up starting directory
- StartingDir$ = CurDir$
- labDirSelected.Caption = StartingDir$
- cbDrives.Drive = StartingDir$
- lbDirList.Path = StartingDir$
- 'Set the color of the "filler" between scroll bars
- SBColors$ = GetProfileInfo("Colors", "ScrollBar")
- If (SBColors$ <> "") Then
- Idx% = InStr(SBColors$, " ")
- R% = Val(Left$(SBColors$, Idx% - 1))
- SBColors$ = Right$(SBColors$, Len(SBColors$) - Idx%)
- Idx% = InStr(SBColors$, " ")
- G% = Val(Left$(SBColors$, Idx% - 1))
- SBColors$ = Right$(SBColors$, Len(SBColors$) - Idx%)
- B% = Val(SBColors$)
- PicScrollbarFiller.BackColor = RGB(R%, G%, B%)
- End If
-
- ' Load the DIBUTIL library
- hDIBUtil = LoadLibrary("DIBUTIL.DLL")
- ' Since we haven't yet created a palette, initialize hPalette to
- ' null to indicate this
- hPalette = Null
- Screen.MousePointer = OldMousePtr%
- End Sub
- Sub Form_Unload (Cancel As Integer)
- ' if hPalette is not 0 then we've created a palette that
- ' should be deleted before we terminate the program
- If (hPalette <> Null) Then
- ReturnVal% = DeleteObject(hPalette)
- If (ReturnVal% = 0) Then
- MsgBox "(Form_Unload) Warning: Could not delete hPalette!"
- End If
- End If
- ' Allow Windows to unload our dll
- FreeLibrary hDIBUtil
- End Sub
- Function GetProfileInfo (Section$, KeyName$) As String
- Result$ = String$(255, 0)
- ResultLength% = GetProfileString(Section$, KeyName$, "", Result$, 255)
- GetProfileInfo = Left$(Result$, ResultLength%)
- End Function
- Sub lbDirList_Change ()
- labDirSelected.Caption = UCase$(lbDirList.Path)
- lbFileList.Path = lbDirList.Path
- End Sub
- Sub lbFileList_DblClick ()
- Call pbPreview_Click
- End Sub
- Sub lbFileList_PathChange ()
- lbFileList.ListIndex = -1
- End Sub
- Sub MovePic ()
- Dim SrcX, SrcY, DestX, DestY, DestWidth, DestHeight As Integer
- 'Set up bitblt parameters
- SrcX = PicPreviewHScroll.Value: SrcY = PicPreviewVScroll.Value
- DestX = 0: DestY = 0
- DestWidth = PicPreview.ScaleWidth
- DestHeight = PicPreview.ScaleHeight
- 'In case anyone has changed the palette since we last painted,
- 'realize it (again)
- ReturnVal% = RealizePalette(PicPreviewSource.hDC)
- ReturnVal% = RealizePalette(PicPreview.hDC)
- 'Blast the new picture into the preview picture box
- APIError% = BitBlt(PicPreview.hDC, DestX, DestY, DestWidth, DestHeight, PicPreviewSource.hDC, SrcX, SrcY, SRCCOPY)
- 'If the picture box has AutoRedraw on, it must be refreshed
- If (PicPreview.AutoRedraw) Then PicPreview.Refresh
- End Sub
- Sub pbCancel_Click ()
- Unload frm256PicBx
- End
- End Sub
- Sub pbPreview_Click ()
- Dim bmpWidth, bmpHeight As Long
- Dim ShowFiller As Integer
- 'Set an hourglass cursor
- OldMousePtr% = Screen.MousePointer
- Screen.MousePointer = HOURGLASS
- 'Clear any existing bitmaps
- PicPreview.Picture = LoadPicture()
- PicPreviewSource.Picture = LoadPicture()
- 'Any bitmap files in the listbox?
- If (lbFileList.ListCount < 1) Then
- MsgBox "Please select a Bitmap file before pressing the Preview button"
- GoTo FastExit
- End If
- 'If no bitmap file is selected, take the first one
- If lbFileList.ListIndex < 0 Then lbFileList.ListIndex = 0
- FName$ = lbDirList.List(lbDirList.ListIndex)
- If Right$(FName$, 1) <> "\" Then FName$ = FName$ + "\"
- FName$ = FName$ + lbFileList.List(lbFileList.ListIndex)
- 'Load the bitmap into memory and get its dimensions
- hDIBBuffer = DIBLoad(FName$)
- If (hDIBBuffer = Null) Then
- MsgBox "Error loading " + FName$ + "!"
- GoTo FastExit
- End If
- lpDIBBuffer = GlobalLock(hDIBBuffer)
- bmpWidth = DIBWidth(lpDIBBuffer)
- bmpHeight = DIBHeight(lpDIBBuffer)
- ReturnVal% = GlobalUnlock(hDIBBuffer)
- 'Set up bitblt parameters
- If (bmpWidth > PicPreview.ScaleWidth) Then
- DestWidth = PicPreview.ScaleWidth
- Else
- DestWidth = bmpWidth
- End If
- If (bmpHeight > PicPreview.ScaleHeight) Then
- DestHeight = PicPreview.ScaleHeight
- Else
- DestHeight = bmpHeight
- End If
- 'Set up the scroll bars
- ShowFiller = 0
- If DestWidth >= bmpWidth Then
- PicPreviewHScroll.Visible = False
- Else
- PicPreviewHScroll.Visible = True
- PicPreviewHScroll.Min = 0
- PicPreviewHScroll.Max = bmpWidth - DestWidth
- PicPreviewHScroll.SmallChange = DestWidth / 10
- PicPreviewHScroll.LargeChange = DestWidth / 2
- PicPreviewHScroll.Value = 0
- ShowFiller = ShowFiller + 1
- PicPreviewHScroll.Refresh
- End If
- If DestHeight >= bmpHeight Then
- PicPreviewVScroll.Visible = False
- Else
- PicPreviewVScroll.Visible = True
- PicPreviewVScroll.Visible = True
- PicPreviewVScroll.Min = 0
- PicPreviewVScroll.Max = bmpHeight - DestHeight
- PicPreviewVScroll.SmallChange = DestHeight / 10
- PicPreviewVScroll.LargeChange = DestHeight / 2
- PicPreviewVScroll.Value = 0
- PicPreviewVScroll.Refresh
- ShowFiller = ShowFiller + 1
- End If
- If (ShowFiller = 2) Then
- PicScrollbarFiller.Visible = True
- Else
- PicScrollbarFiller.Visible = False
- End If
- 'If we have previously created a palette, delete it now
- If (hPalette <> Null) Then
- ReturnVal% = DeleteObject(hPalette)
- If (ReturnVal% = 0) Then
- MsgBox "(pbPreview_Click) Warning: Could not delete hPalette!"
- End If
- End If
- 'Create a new palette for this bitmap
- hPalette = CreateDIBPalette(hDIBBuffer)
- ' Make sure DC containing the persistent image has the right palette
- hOldPalette% = SelectPalette(PicPreviewSource.hDC, hPalette, False)
- ReturnVal% = RealizePalette(PicPreviewSource.hDC)
- ' Make sure the picture box DC has the right palette
- hOldPalette% = SelectPalette(PicPreview.hDC, hPalette, False)
- ReturnVal% = RealizePalette(PicPreview.hDC)
- 'Lock the memory block
- lpDIBBuffer = GlobalLock(hDIBBuffer)
- ' Create a Device Dependent Bitmap
- hBitmap% = CreateDIBitmap(PicPreviewSource.hDC, lpDIBBuffer, CBM_INIT, FindDIBBits(lpDIBBuffer), lpDIBBuffer, DIB_RGB_INFO)
- ' Create a memory DC from which we can bitblt the image. Select in and
- ' realize the palette, then select in the ddb
- hCompatDC% = CreateCompatibleDC(PicPreviewSource.hDC)
- 'hOldPalette% = SelectPalette(hCompatDC%, hPalette, FALSE)
- 'ReturnVal% = RealizePalette(hCompatDC%)
- hPrevBmp% = SelectObject(hCompatDC%, hBitmap%)
- 'Blast the image into our hidden picture box
- Success% = BitBlt(PicPreviewSource.hDC, 0, 0, bmpWidth, bmpHeight, hCompatDC%, 0, 0, SRCCOPY)
- 'Free up resources we no longer need
- ReturnVal% = DeleteDC(hCompatDC%)
- If (ReturnVal% = 0) Then
- MsgBox "(pbPreview_Click) Warning: Could not delete hComptDC%!"
- End If
- ReturnVal% = DeleteObject(hBitmap%)
- If (ReturnVal% = 0) Then
- MsgBox "(pbPreview_Click) Warning: Could not delete hBitmap%!"
- End If
- 'release previously allocated memory
- Success% = GlobalUnlock(hDIBBuffer)
- Success% = GlobalFree(hDIBBuffer)
- hDIBBuffer = Null
- 'Now fill in the scrollable picture box
- Call MovePic
- FastExit:
- 'Restore the cursor
- Screen.MousePointer = OldMousePtr%
- End Sub
- Sub PicPreviewHScroll_Change ()
- Call MovePic
- End Sub
- Sub PicPreviewVScroll_Change ()
- Call MovePic
- End Sub
- Sub Set_ModalDlg_SysMenu (A_Form As Form)
- ' Obtain the handle to the forms System menu
- '
- HSysMenu = GetSystemMenu(A_Form.hWnd, 0)
- ' Remove all but the MOVE and CLOSE options. The menu items
- ' must be removed starting with the last menu item to prevent
- ' the menu items from taking on new position values as other
- ' menu items are being removed.
- '
- R = RemoveMenu(HSysMenu, 8, MF_BYPOSITION) 'Switch to
- R = RemoveMenu(HSysMenu, 7, MF_BYPOSITION) 'Separator
- R = RemoveMenu(HSysMenu, 5, MF_BYPOSITION) 'Separator
- R = RemoveMenu(HSysMenu, 4, MF_BYPOSITION) 'Maximize
- R = RemoveMenu(HSysMenu, 3, MF_BYPOSITION) 'Minimize
- R = RemoveMenu(HSysMenu, 2, MF_BYPOSITION) 'Size
- R = RemoveMenu(HSysMenu, 0, MF_BYPOSITION) 'Restore
- End Sub
-