home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_2 / VB_MSG / NCFORM.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-07-19  |  3.7 KB  |  101 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "WM_NCPAINT Demo"
  4.    ClientHeight    =   3435
  5.    ClientLeft      =   2115
  6.    ClientTop       =   2325
  7.    ClientWidth     =   6420
  8.    Height          =   3840
  9.    Left            =   2055
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3435
  14.    ScaleWidth      =   6420
  15.    Top             =   1980
  16.    Width           =   6540
  17.    Begin VBMsg VBMsg1 
  18.       Height          =   420
  19.       Left            =   5970
  20.       MessageCount    =   NCFORM.FRX:0000
  21.       MessageList     =   NCFORM.FRX:0002
  22.       MessageTypes    =   0  'Selected Messages
  23.       PostDefault     =   0   'False
  24.       Top             =   2970
  25.       Width           =   420
  26.    End
  27.    Begin PictureBox picSysMenu 
  28.       AutoSize        =   -1  'True
  29.       Height          =   300
  30.       Left            =   5580
  31.       Picture         =   NCFORM.FRX:0200
  32.       ScaleHeight     =   270
  33.       ScaleWidth      =   270
  34.       TabIndex        =   0
  35.       Top             =   3060
  36.       Visible         =   0   'False
  37.       Width           =   300
  38.    End
  39.    Begin Label Label1 
  40.       Caption         =   "Notice the new System Menu bitmap.  Using VB Messenger, you can trap non-client area messages to change the look of Windows itself.  This sample traps WM_NCPAINT and WM_NCACTIVATE to detect when to draw the system menu bitmap.  Also, VB Messenger is used to change the behavior of the system menu.  By trapping the WM_NCLBUTTONDOWN message, you can allow the user to close a window simply by clicking the system menu once instead of twice."
  41.       Height          =   2025
  42.       Left            =   510
  43.       TabIndex        =   1
  44.       Top             =   660
  45.       Width           =   5355
  46.    End
  47. Option Explicit
  48. Sub DrawBitmapNCArea (hWindow As Integer, hbmp As Integer, cxLeft As Integer, cyTop As Integer)
  49.     Dim hdc%, hdcMem%
  50.     Dim bmp As BITMAP
  51.     Dim hbmpOld%
  52.     Dim lprect As RECT
  53.     Dim hinst%
  54.     Dim rc&
  55.     hinst = GetWindowWord(hWindow, GWW_HINSTANCE)
  56.     hdc = GetWindowDC(hWindow)
  57.     hdcMem = CreateCompatibleDC(hdc)
  58.     rc = APIGetObject(hbmp, Len(bmp), bmp)
  59.     hbmpOld = SelectObject(hdcMem, hbmp)
  60.     rc = BitBlt(hdc, cxLeft, cyTop, bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY)
  61.     rc = SelectObject(hdcMem, hbmpOld)
  62.     rc = DeleteDC(hdcMem)
  63.     rc = ReleaseDC(hWnd, hdc)
  64. End Sub
  65. Sub Form_Load ()
  66.     VBMsg1.SubClasshWnd = Form1.hWnd
  67. End Sub
  68. Sub VBMsg1_WindowMessage (hWindow As Integer, Msg As Integer, wParam As Integer, lParam As Long, RetVal As Long, CallDefProc As Integer)
  69.     'VB Messenger is setup to trap WM_NCPAINT, WM_NCACTIVATE and WM_NCLBUTTONDOWN
  70.     Select Case Msg
  71.         
  72.         Case WM_NCPAINT
  73.         
  74.             RetVal = DefWindowProc(hWindow, Msg, wParam, lParam)
  75.             
  76.             DrawBitmapNCArea hWindow, (picSysMenu.Picture), GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME)
  77.             CallDefProc = False
  78.         
  79.         Case WM_NCACTIVATE
  80.             If wParam = False Then
  81.                 RetVal = True
  82.             Else
  83.                 RetVal = DefWindowProc(hWindow, Msg, wParam, lParam)
  84.             End If
  85.             
  86.             DrawBitmapNCArea hWindow, (picSysMenu.Picture), GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME)
  87.             
  88.             CallDefProc = False
  89.         Case WM_NCLBUTTONDOWN
  90.         
  91.             If wParam = HTSYSMENU Then
  92.                 VBMsg1.wParam = 0
  93.                 VBMsg1.lParam = 0
  94.                 VBMsg1.PostMessage = WM_CLOSE
  95.                 CallDefProc = False
  96.                 Exit Sub
  97.             End If
  98.         
  99.     End Select
  100. End Sub
  101.