• Vui lòng đọc nội qui diễn đàn để tránh bị xóa bài viết
  • Tìm kiếm trước khi đặt câu hỏi

Add Form Style Properties to Controls

Các thủ thuật liên quan đến việc xử lý ứng dụng, biểu mẫu và control
Hình đại diện của người dùng
clarkkent
Mạnh Thường Quân
Mạnh Thường Quân
Bài viết: 1641
Ngày tham gia: T.Tư 16/04/2008 11:25 am
Đến từ: Chợ Lách - Bến Tre
Been thanked: 31 time
Liên hệ:

Add Form Style Properties to Controls

Gửi bàigửi bởi clarkkent » T.Bảy 11/07/2009 9:28 am

Thủ thuật: Add Form Style Properties to Controls
Tác giả: Sưu tầm
Mô tả: This module will add to a control a system-properties, like Title-Bar, SysMenu, MaxBox, MinBox, Sizable BorderStyle, and more. Help is contained within the module's comments. This is a good sample for learning how to set the style of windows.



Module

Mã: Chọn hết

  1. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  2. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  3. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  4. Private Const SWP_NOSIZE = &H1
  5. Private Const SWP_NOZORDER = &H4
  6. Private Const SWP_NOMOVE = &H2
  7. Private Const SWP_DRAWFRAME = &H20
  8. Private Const GWL_STYLE = (-16)
  9. Private Const WS_THICKFRAME = &H40000
  10. Private Const WS_DLGFRAME = &H400000
  11. Private Const WS_POPUP = &H80000000
  12. Private Const WS_CAPTION = &HC00000
  13. Private Const WS_SYSMENU = &H80000
  14. Private Const WS_MINIMIZEBOX = &H20000
  15. Private Const WS_MAXIMIZEBOX = &H10000
  16. Private Const WS_MINIMIZE = &H20000000
  17. Private Const WS_MAXIMIZE = &H1000000
  18. '-----------------------------------------------
  19. '-- This module written by Daniel Cohen-Gindi --
  20. '-------- D.C.G. Software - 053-903083 ---------
  21. '-Warning: You must copy the module and give it-
  22. '----to you friends, Change it like you want.---
  23. '---- (Sorry about the errors in my text, ------
  24. '--------------  I'm from Israel) --------------
  25. '-----------------------------------------------
  26. '---------This module will give you some--------
  27. '------------effects for your program-----------
  28. '-----------------------------------------------
  29. '----------Use this module like this:-----------
  30. '------CControl.ControlSize(Command1, True)-----
  31. '-----Don't use one procedure two times in------
  32. '----------True mode or in False mode-----------
  33. '--Example: To enable the ControlCaption proc.--
  34. '--use like: ControlCaption(ControlName, True)--
  35. '-------------and to disable use:---------------
  36. '-----"ControlCaption(ControlName, False)"------
  37. '-----------------------------------------------
  38. '-----------------Have Fun !!-------------------
  39. '*******************************************
  40. ''ADDITIONAL NOTE FROM FREEVBCODE.COM
  41. 'FOR SOME CONTROLS, THESE FUNCTIONS WILL WORK, FOR SOME THEY WON'T
  42. 'IF THE CALLING FUNCTION NEEDS TO KNWO IF THEY WORK, CHANGE SUBS
  43. 'TO FUNCTIONS THAT RETURN TRUE IF ERR.LASTDLLERROR =0
  44.  
  45.  
  46.  
  47.  
  48. Public Sub ControlSize(ControlName As Control, SetTrue As Boolean)
  49. '* Sizable BorderStyle property for a Control *
  50.    
  51.     Dim dwStyle As Long
  52.     dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
  53.     If SetTrue Then
  54.       dwStyle = dwStyle Or WS_THICKFRAME
  55.     Else
  56.       dwStyle = dwStyle - WS_THICKFRAME
  57.     End If
  58.     dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
  59.     SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  60. End Sub
  61. Public Sub ControlDialog(ControlName As Control, SetTrue As Boolean)
  62. '* Fixed Dialog BorderStyle property for a Control *
  63.    
  64.     Dim dwStyle As Long
  65.     dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
  66.     If SetTrue Then
  67.       dwStyle = dwStyle Or WS_DLGFRAME
  68.     Else
  69.       dwStyle = dwStyle - WS_DLGFRAME
  70.     End If
  71.     dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
  72.     SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  73. End Sub
  74. Public Sub ControlModal(ControlName As Control, SetTrue As Boolean)
  75. '* Make a Control in Modal mode like "form.show 1" *
  76. '* so you can't switch to another control or unload the
  77. '* form until all control's modal are set to false
  78.    
  79.     Dim dwStyle As Long
  80.     dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
  81.     If SetTrue Then
  82.       dwStyle = dwStyle Or WS_POPUP
  83.     Else
  84.       dwStyle = dwStyle - WS_POPUP
  85.     End If
  86.     dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
  87.     SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  88. End Sub
  89. Public Sub ControlCaption(ControlName As Control, SetTrue As Boolean)
  90. '* Add a Title-bar like form to a Control *
  91. '* (from FreeVBCode.com (Great to combine with controlsize)
  92.  
  93.    
  94.     Dim dwStyle As Long
  95.     dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
  96.     If SetTrue Then
  97.       dwStyle = dwStyle Or WS_CAPTION
  98.     Else
  99.       dwStyle = dwStyle - WS_CAPTION
  100.     End If
  101.     dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
  102.     SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  103. End Sub
  104. Public Sub ControlSysMenu(ControlName As Control, SetTrue As Boolean)
  105. '* Enable the System-Menu for Control with Title-bar *
  106. '* Call ControlCaption First
  107.     Dim dwStyle As Long
  108.     dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
  109.     If SetTrue Then
  110.       dwStyle = dwStyle Or WS_SYSMENU
  111.     Else
  112.       dwStyle = dwStyle - WS_SYSMENU
  113.     End If
  114.     dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
  115.     SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  116. End Sub
  117. Public Sub ControlMinBox(ControlName As Control, SetTrue As Boolean)
  118. '* Enable the Minimize-Box for Control with Title-bar *
  119.  
  120.     Dim dwStyle As Long
  121.     dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
  122.     If SetTrue Then
  123.       dwStyle = dwStyle Or WS_MINIMIZEBOX
  124.     Else
  125.       dwStyle = dwStyle - WS_MINIMIZEBOX
  126.     End If
  127.     dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
  128.     SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  129. End Sub
  130. Public Sub ControlMaxBox(ControlName As Control, SetTrue As Boolean)
  131. '* Enable the Maximize-Box for Control with Title-bar *
  132.  
  133.  
  134.     Dim dwStyle As Long
  135.     dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
  136.     If SetTrue Then
  137.       dwStyle = dwStyle Or WS_MAXIMIZEBOX
  138.     Else
  139.       dwStyle = dwStyle - WS_MAXIMIZEBOX
  140.     End If
  141.     dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
  142.     SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  143. End Sub
  144. Public Sub ControlMinimize(ControlName As Control, SetTrue As Boolean)
  145. '* Minimize a Control *
  146.  
  147.  
  148.     Dim dwStyle As Long
  149.     dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
  150.     If SetTrue Then
  151.       dwStyle = dwStyle Or WS_MINIMIZE
  152.     Else
  153.       dwStyle = dwStyle - WS_MINIMIZE
  154.     End If
  155.     dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
  156.     SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  157. End Sub
  158. Public Sub ControlMaximize(ControlName As Control, SetTrue As Boolean)
  159. '* Maximize a Control *
  160.  
  161.     Dim dwStyle As Long
  162.     dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
  163.     If SetTrue Then
  164.       dwStyle = dwStyle Or WS_MAXIMIZE
  165.     Else
  166.       dwStyle = dwStyle - WS_MAXIMIZE
  167.     End If
  168.     dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
  169.     SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  170. End Sub


• Hôm bây: www.tinsoftware.com ^ ^
Cố gắng lên...

Quay về “[VB] Ứng dụng - Form và Control”

Đang trực tuyến

Đang xem chuyên mục này: Không có thành viên nào trực tuyến.0 khách