Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: Помогите с кнопкой!!! Добавлено: 07.12.08 05:02  

Автор вопроса:  Mc.WOLF
Я уже писал раньше, но толком на языке Visual Basic никто не подсказал как добавить свою кнопку к всем окнам WINDOWS (XP)???
Зариние спасибо!

Ответить

  Ответы Всего ответов: 3  

Номер ответа: 1
Автор ответа:
 VerhoLom



Вопросов: 20
Ответов: 285
 Профиль | | #1 Добавлено: 07.12.08 16:58
Это поначалу надо изучить что такое хуки, потом установить хук WH_GETMESSAGE (например) с системной областью видимости (как это Window Blinds делает) и рисовать свою кнопку. Где-то так...

Ответить

Номер ответа: 2
Автор ответа:
 Father



Вопросов: 0
Ответов: 159
 Профиль | | #2 Добавлено: 08.12.08 04:12
но толком на языке Visual Basic никто не подсказал

Странный ты человек..., не обижайся :)
Вот я, например, знаю как реализовать это.
Но для полноценного примера надо накорябать на вскидку 500-600 строк кода.
Написать длл с хуком, сделать корректный вызов ее сервисов из exe, предусмотреть прорисовку при разных темах винды.
Масса мышиной возни с неклиентской областью окон.
И все это ради примера на VB.

Ну разве что побаловаться c одним:
  1.  
  2. Option Explicit
  3. Private Sub Form_Load()
  4.    Call SetProp(hwnd, "Father", GetWindowLong(hwnd, GWL_WNDPROC))
  5.    Call SetWindowLong(hwnd, GWL_WNDPROC, AddressOf myProc)
  6. End Sub
  7.  
  8. '///////////  module
  9.  
  10. Option Explicit
  11. Public Type POINTAPI
  12.         x As Long
  13.         y As Long
  14. End Type
  15. Public Type RECT
  16.         Left As Long
  17.         Top As Long
  18.         Right As Long
  19.         Bottom As Long
  20. End Type
  21. Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  22. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  23. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  24. Public Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
  25. Public Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
  26. Public Declare Function DrawFrameControl Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long
  27. Public Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
  28. Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  29. Public Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
  30. Public 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
  31. Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
  32. Public Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
  33. Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  34. Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  35.  
  36. Public Const VK_LBUTTON = &H1
  37. Public Const SWP_FRAMECHANGED = &H20
  38. Public Const SWP_NOMOVE = &H2
  39. Public Const SWP_NOSIZE = &H1
  40. Public Const SWP_NOACTIVATE = &H10
  41. Public Const SWP_NOZORDER = &H4
  42.  
  43. Public Const WM_NCLBUTTONDBLCLK = &HA3
  44. Public Const WM_NCLBUTTONDOWN = &HA1
  45. Public Const WM_NCLBUTTONUP = &HA2
  46. Public Const WM_NCPAINT = &H85
  47. Public Const GWL_WNDPROC = (-4)
  48.  
  49.  
  50. Public Function myProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  51.     
  52.     Dim hdc As Long
  53.     Dim rc As RECT, rcwnd As RECT
  54.     Dim pt As POINTAPI
  55.     Dim inrect As Boolean
  56.         
  57.     rc.Left = 150
  58.     rc.Right = 180
  59.     rc.Top = 7
  60.     rc.Bottom = 20
  61.     
  62.     Select Case Msg
  63.     Case WM_NCLBUTTONDOWN, WM_NCLBUTTONUP, WM_NCLBUTTONDBLCLK
  64.         pt.x = LWORD(lParam)
  65.         pt.y = HWORD(lParam)
  66.         Call GetWindowRect(hwnd, rcwnd)
  67.         pt.x = pt.x - rcwnd.Left
  68.         pt.y = pt.y - rcwnd.Top
  69.         inrect = PtInRect(rc, pt.x, pt.y)
  70.     End Select
  71.     
  72.     If inrect Then
  73.         Select Case Msg
  74.         Case WM_NCLBUTTONDBLCLK
  75.             Form1.Caption = "WM_LBUTTONDOWN"
  76.             updateframe hwnd
  77.         Case WM_NCLBUTTONDOWN
  78.             Form1.Caption = "WM_LBUTTONDOWN"
  79.             updateframe hwnd
  80.         Case WM_NCLBUTTONUP
  81.             Form1.Caption = "WM_LBUTTONUP"
  82.             updateframe hwnd
  83.         End Select
  84.         Exit Function
  85.    End If
  86.     
  87.     myProc = CallWindowProc(GetProp(hwnd, "Father"), hwnd, Msg, wParam, lParam)
  88.     
  89.     Select Case Msg
  90.     Case WM_NCPAINT
  91.         hdc = GetWindowDC(hwnd)
  92.         Call GetCursorPos(pt)
  93.         Call GetWindowRect(hwnd, rcwnd)
  94.         pt.x = pt.x - rcwnd.Left
  95.         pt.y = pt.y - rcwnd.Top
  96.         inrect = PtInRect(rc, pt.x, pt.y)
  97.         Call DrawFrameControl(hdc, rc, 4, IIf(GetAsyncKeyState(VK_LBUTTON) And inrect, 528, 16))
  98.         Call ReleaseDC(hwnd, hdc)
  99.     End Select
  100.  
  101. End Function
  102.  
  103. Sub updateframe(hwnd As Long)
  104.    Call SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_NOACTIVATE)
  105. End Sub
  106.  
  107. Public Function LWORD(param As Long) As Long
  108. LWORD = param And &HFFFF&
  109. End Function
  110.  
  111. Public Function HWORD(param As Long) As Long
  112. HWORD = param \ &H10000 And &HFFFF&
  113. End Function



Не спалось......... :)

Ответить

Номер ответа: 3
Автор ответа:
 Mc.WOLF



Вопросов: 26
Ответов: 84
 Профиль | | #3 Добавлено: 08.12.08 18:32
СПС....... :-)

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам