Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Create Controls at RunTime
[ All Languages » VB »  Api]

Total Hit ( 4749)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


API Declarations

Click here to copy the following block
'API Calls
Public Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Public Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nindex As Long, ByVal dwnewlong As Long) As Long
Public Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, lParam As Long) As Long
Public Declare Function DefWindowProc Lib "user32.dll" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'API Constants
Public Const WS_CHILD = &H40000000
Public Const WS_THICKFRAME = &H40000
Public Const WS_VISIBLE = &H10000000
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const GWL_WNDPROC = (-4)

Module

Click here to copy the following block
'Create a Module named Module1

'Address of the original WindowProc of the Button
Public myOldhWndProc As Long

'CreateButton...Create a new button with resize capabilities and install a event handler for the button
'frm : Form that will contain the button (Parent)
'Caption : Button Caption
'Left , Top, Width, Height : Size (in pixels) of the button
'OnClick : Address of the new events handler procedure
'OldHWndProc : Address of the old events handler procedure, this parameter will be
' returned by the sub to use it in the event handler proc to call the old WindowProc
Public Sub CreateButton(frm As Form, Caption As String, Left As Long, Top As Long, Height As Long, Width As Long, OnClick As Long, ByRef OldhWndProc As Long)
  Dim hWnd As Long

  hWnd = CreateWindowEx(0&, "BUTTON", Caption, WS_VISIBLE Or WS_CHILD Or WS_THICKFRAME, Left, Top, Height, Width, frm.hWnd, 0&, App.hInstance, 0&)
  If hWnd And OnClick <> 0 Then
    'Set the new WindowProc to manage the button events
    OldhWndProc = SetWindowLong(hWnd, GWL_WNDPROC, OnClick)
  End If
End Sub

'New WindowProc to manage button's events
Public Function MyWindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, lParam As Long) As Long
  'OnLeftButtonUp
  If uMsg = WM_LBUTTONUP Then
    'Make a sound
    Beep
  End If
  'Call the old WindowProc for the button
  MyWindowProc = CallWindowProc(myOldhWndProc, hWnd, uMsg, wParam, lParam)
End Function

Usage

Click here to copy the following block
'Make a form with a command button named Command1 as default.
'Place the following code in Form1 code window:
Private Sub Command1_Click()
  CreateButton Me, "Button", 5, 5, 300, 100, AddressOf Module1.MyWindowProc, myOldhWndProc
End Sub
' This will create a resizable button :))


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.