home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code2 / vb_msg / ncform.frm < prev    next >
Text File  |  1993-07-19  |  4KB  |  119 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. End
  48. Option Explicit
  49.  
  50. Sub DrawBitmapNCArea (hWindow As Integer, hbmp As Integer, cxLeft As Integer, cyTop As Integer)
  51.  
  52.     Dim hdc%, hdcMem%
  53.     Dim bmp As BITMAP
  54.     Dim hbmpOld%
  55.     Dim lprect As RECT
  56.     Dim hinst%
  57.     Dim rc&
  58.     
  59.     hinst = GetWindowWord(hWindow, GWW_HINSTANCE)
  60.     hdc = GetWindowDC(hWindow)
  61.     hdcMem = CreateCompatibleDC(hdc)
  62.     
  63.     rc = APIGetObject(hbmp, Len(bmp), bmp)
  64.     hbmpOld = SelectObject(hdcMem, hbmp)
  65.     rc = BitBlt(hdc, cxLeft, cyTop, bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY)
  66.     rc = SelectObject(hdcMem, hbmpOld)
  67.     
  68.     rc = DeleteDC(hdcMem)
  69.     rc = ReleaseDC(hWnd, hdc)
  70.  
  71. End Sub
  72.  
  73. Sub Form_Load ()
  74.  
  75.     VBMsg1.SubClasshWnd = Form1.hWnd
  76.  
  77. End Sub
  78.  
  79. Sub VBMsg1_WindowMessage (hWindow As Integer, Msg As Integer, wParam As Integer, lParam As Long, RetVal As Long, CallDefProc As Integer)
  80.  
  81.     'VB Messenger is setup to trap WM_NCPAINT, WM_NCACTIVATE and WM_NCLBUTTONDOWN
  82.     
  83.     Select Case Msg
  84.         
  85.         Case WM_NCPAINT
  86.         
  87.             RetVal = DefWindowProc(hWindow, Msg, wParam, lParam)
  88.             
  89.             DrawBitmapNCArea hWindow, (picSysMenu.Picture), GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME)
  90.  
  91.             CallDefProc = False
  92.         
  93.         Case WM_NCACTIVATE
  94.  
  95.             If wParam = False Then
  96.                 RetVal = True
  97.             Else
  98.                 RetVal = DefWindowProc(hWindow, Msg, wParam, lParam)
  99.             End If
  100.             
  101.             DrawBitmapNCArea hWindow, (picSysMenu.Picture), GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME)
  102.             
  103.             CallDefProc = False
  104.  
  105.         Case WM_NCLBUTTONDOWN
  106.         
  107.             If wParam = HTSYSMENU Then
  108.                 VBMsg1.wParam = 0
  109.                 VBMsg1.lParam = 0
  110.                 VBMsg1.PostMessage = WM_CLOSE
  111.                 CallDefProc = False
  112.                 Exit Sub
  113.             End If
  114.         
  115.     End Select
  116.  
  117. End Sub
  118.  
  119.