home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples5 / ch09 / stockbms.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  6.3 KB  |  180 lines

  1. VERSION 5.00
  2. Begin VB.Form StockBMS 
  3.    Caption         =   "Stock Bitmaps and Icons Viewer"
  4.    ClientHeight    =   2985
  5.    ClientLeft      =   1125
  6.    ClientTop       =   1485
  7.    ClientWidth     =   4065
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    ForeColor       =   &H80000008&
  18.    LinkMode        =   1  'Source
  19.    LinkTopic       =   "Form1"
  20.    PaletteMode     =   1  'UseZOrder
  21.    ScaleHeight     =   2985
  22.    ScaleWidth      =   4065
  23.    Begin VB.PictureBox Picture2 
  24.       BackColor       =   &H00FFFF80&
  25.       Height          =   855
  26.       Left            =   1560
  27.       ScaleHeight     =   55
  28.       ScaleMode       =   3  'Pixel
  29.       ScaleWidth      =   83
  30.       TabIndex        =   2
  31.       Top             =   1920
  32.       Width           =   1275
  33.    End
  34.    Begin VB.PictureBox Picture1 
  35.       BackColor       =   &H00FFFFFF&
  36.       Height          =   855
  37.       Left            =   240
  38.       ScaleHeight     =   825
  39.       ScaleWidth      =   1065
  40.       TabIndex        =   1
  41.       Top             =   1920
  42.       Width           =   1095
  43.    End
  44.    Begin VB.ListBox List1 
  45.       Height          =   1200
  46.       Left            =   240
  47.       TabIndex        =   0
  48.       Top             =   360
  49.       Width           =   3615
  50.    End
  51. Attribute VB_Name = "StockBMS"
  52. Attribute VB_GlobalNameSpace = False
  53. Attribute VB_Creatable = False
  54. Attribute VB_PredeclaredId = True
  55. Attribute VB_Exposed = False
  56. Option Explicit
  57. ' Copyright 
  58.  1997 by Desaware Inc. All Rights Reserved
  59. '   Initialize the list box
  60. Private Sub Form_Load()
  61.     ' Load the listbox with entries for each stock
  62.     ' bitmap and icon
  63.     List1.AddItem "OBM_CLOSE = 32754"
  64.     List1.AddItem "OBM_UPARROW = 32753"
  65.     List1.AddItem "OBM_DNARROW = 32752"
  66.     List1.AddItem "OBM_RGARROW = 32751"
  67.     List1.AddItem "OBM_LFARROW = 32750"
  68.     List1.AddItem "OBM_REDUCE = 32749"
  69.     List1.AddItem "OBM_ZOOM = 32748"
  70.     List1.AddItem "OBM_RESTORE = 32747"
  71.     List1.AddItem "OBM_REDUCED = 32746"
  72.     List1.AddItem "OBM_ZOOMD = 32745"
  73.     List1.AddItem "OBM_RESTORED = 32744"
  74.     List1.AddItem "OBM_UPARROWD = 32743"
  75.     List1.AddItem "OBM_DNARROWD = 32742"
  76.     List1.AddItem "OBM_RGARROWD = 32741"
  77.     List1.AddItem "OBM_LFARROWD = 32740"
  78.     List1.AddItem "OBM_MNARROW = 32739"
  79.     List1.AddItem "OBM_COMBO = 32738"
  80.     List1.AddItem "OBM_UPARROWI = 32737"
  81.     List1.AddItem "OBM_DNARROWI = 32736"
  82.     List1.AddItem "OBM_RGARROWI = 32735"
  83.     List1.AddItem "OBM_LFARROWI = 32734"
  84.     List1.AddItem "OBM_OLD_CLOSE = 32767"
  85.     List1.AddItem "OBM_SIZE = 32766"
  86.     List1.AddItem "OBM_OLD_UPARROW = 32765"
  87.     List1.AddItem "OBM_OLD_DNARROW = 32764"
  88.     List1.AddItem "OBM_OLD_RGARROW = 32763"
  89.     List1.AddItem "OBM_OLD_LFARROW = 32762"
  90.     List1.AddItem "OBM_BTSIZE = 32761"
  91.     List1.AddItem "OBM_CHECK = 32760"
  92.     List1.AddItem "OBM_CHECKBOXES = 32759"
  93.     List1.AddItem "OBM_BTNCORNERS = 32758"
  94.     List1.AddItem "OBM_OLD_REDUCE = 32757"
  95.     List1.AddItem "OBM_OLD_ZOOM = 32756"
  96.     List1.AddItem "OBM_OLD_RESTORE = 32755"
  97.     List1.AddItem "IDI_APPLICATION = 32512"
  98.     List1.AddItem "IDI_HAND = 32513"
  99.     List1.AddItem "IDI_QUESTION = 32514"
  100.     List1.AddItem "IDI_EXCLAMATION = 32515"
  101.     List1.AddItem "IDI_ASTERISK = 32516"
  102.     List1.AddItem "IDI_WINLOG = 32517"
  103. End Sub
  104. '   Just display the current object
  105. Private Sub List1_Click()
  106.     ShowObject
  107. End Sub
  108. '  When redrawing the picture control, show the currently
  109. '   selected object (if any)
  110. Private Sub Picture1_Paint()
  111.     ShowObject
  112. End Sub
  113. '   Paints the stock icon or bitmap in picture1
  114. '   Retrieve a stock bitmap or icon for the selected list box
  115. '   entry. Draws the bitmap or icon on the picture control.
  116. Private Sub ShowObject()
  117.     Dim ShadowDC&
  118.     Dim isbm%
  119.     Dim param$
  120.     Dim idlong&
  121.     Dim objhandle&, oldobject&
  122.     Dim di&
  123.     Dim bm As BITMAP
  124.     ' Be sure there is a valid entry
  125.     If List1.ListIndex < 0 Then Exit Sub
  126.     Picture1.Cls    ' Clear the picture control
  127.     Picture2.Cls
  128.     param$ = List1.Text
  129.     ' Find out if it's a bitmap or an icon
  130.     If Left$(param$, 3) = "OBM" Then isbm% = -1
  131.     ' Extract the id value to use
  132.     idlong& = Val(Mid$(param$, InStr(param$, "=") + 1))
  133.     If isbm% Then   ' It's a stock bitmap
  134.         
  135.         ' Create a memory device context compatible with
  136.         ' the picture control
  137.         ShadowDC& = CreateCompatibleDC&(Picture1.hdc)
  138.         
  139.         ' Load the bitmap
  140.         objhandle& = LoadBitmapBynum(0, idlong&)
  141.         
  142.         ' Retrieve the height and width of the bitmap
  143.         di = GetObjectAPI(objhandle, Len(bm), bm)
  144.         
  145.         ' Select the bitmap into the memory DC, keeping
  146.         ' a handle to the prior bitmap.
  147.         oldobject = SelectObject(ShadowDC, objhandle)
  148.         ' BitBlt the bitmap into the picture control,
  149.         ' offset by 2 pixels from the upper left corner
  150.         ' (just to make it look better)
  151.         di = BitBlt(Picture1.hdc, 2, 2, bm.bmWidth, bm.bmHeight, ShadowDC&, 0, 0, SRCCOPY)
  152.         ' Select the bitmap OUT of the memory DC
  153.         di = SelectObject(ShadowDC, oldobject)
  154.         ' and delete it (yes - even though they are system
  155.         ' bitmaps - this doesn't destroy them, just releases
  156.         ' your private copy of the bitmap.
  157.         di = DeleteObject(objhandle)
  158.         
  159.         Picture2.CurrentX = 2
  160.         Picture2.CurrentY = 2
  161.         Picture2.Print "N/A"
  162.         ' Finally, delete the memory DC
  163.         di = DeleteDC(ShadowDC)
  164.     Else    ' It's an icon - a much easier process
  165.         ' Get the stock icon
  166.         objhandle& = LoadIconBynum(0, idlong&)
  167.         
  168.         ' Draw it directly onto the picture control
  169.         di = DrawIcon(Picture1.hdc, 2, 2, objhandle&)
  170.         
  171.         
  172.         ' Now try loading it as in image
  173.         
  174.         objhandle& = LoadImageBynum(0, idlong&, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR Or LR_DEFAULTSIZE Or LR_SHARED)
  175.         
  176.         di = DrawIconEx(Picture2.hdc, 0, 0, objhandle&, Picture2.ScaleWidth, Picture2.ScaleHeight, 0, 0, DI_NORMAL)
  177.         
  178.     End If
  179. End Sub
  180.