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 / samples4 / ch09 / stockbms.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  6.3 KB  |  181 lines

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