Страница: 1 | 2 | 3 |
|
Вопрос: Внедрение в другую программу
|
Добавлено: 25.06.07 22:34
|
|
Автор вопроса: «0опай» | ICQ: Два, потом нуль, дальше-девять-шесть-девять-семь.
|
Допустим, есть некое приложение. Мне нужно добавить в него объект (кнопку) и привязать к нему свой код. Как, и можно ли это сделать на Visual Basic?
Ответить
|
Номер ответа: 1 Автор ответа: «0опай»
ICQ: Два, потом нуль, дальше-девять-шесть-девять-семь.
Вопросов: 4 Ответов: 20
|
Профиль | | #1
|
Добавлено: 25.06.07 22:37
|
Просьба не оставлять ответов типа:
Можно ли МожноКак Не знаю.
Ответить
|
Номер ответа: 4 Автор ответа: EUGY
Вопросов: 0 Ответов: 454
|
Профиль | | #4
|
Добавлено: 26.06.07 00:04
|
вот для начала, поиздевайся над калькулятором
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function CreateWindowEx Lib "user32" 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
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
Private Declare Function UpdateWindow Lib "user32" ( ByVal hwnd As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" ( ByVal hwnd As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000
Private Const WS_CLIPCHILDREN = &H2000000
Private Const WS_CLIPSIBLINGS = &H4000000
Private Const GWL_WNDPROC = (-4)
Private Sub Command1_Click()
Dim yorik As Long
Dim mybut1 As Long
yorik = FindWindow(vbNullString, "Калькулятор"
If (yorik = 0) Then
Call Shell("calc.exe", vbNormalFocus)
yorik = FindWindow(vbNullString, "Калькулятор"
End If
If yorik Then
Me.Hide
MsgBox "Бедный Йорик, Ща мы ему подложим кнопку!"
mybut1 = CreateWindowEx(0, "BUTTON", "Йорик, Must Die", WS_CLIPCHILDREN Or WS_CLIPSIBLINGS Or WS_CHILD Or WS_VISIBLE, 2, 2, 150, 50, yorik, 0, App.hInstance, 0)
Call SetWindowPos(mybut1, 0, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Call SetWindowPos(yorik, -1, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Call SetForegroundWindow(yorik)
Else
MsgBox "Йорика не видели? Ушел, сука!"
End If
Me.Show
End Sub
Ответить
|
Номер ответа: 6 Автор ответа: EUGY
Вопросов: 0 Ответов: 454
|
Профиль | | #6
|
Добавлено: 26.06.07 00:50
|
Обработка - как два байта переслать
Валяю дурака дальше.
Private Sub Command1_Click()
Dim yorik As Long
Dim mybut1 As Long
yorik = FindWindow(vbNullString, "Калькулятор"
If (yorik = 0) Then
Call Shell("calc.exe", vbNormalFocus)
yorik = FindWindow(vbNullString, "Калькулятор"
End If
If yorik Then
Me.Hide
MsgBox "Бедный Йорик, Ща мы ему подложим кнопку!"
mybut1 = CreateWindowEx(0, "BUTTON", "Йорик, Must Die", WS_CLIPCHILDREN Or WS_CLIPSIBLINGS Or WS_CHILD Or WS_VISIBLE, 2, 2, 150, 50, yorik, 0, App.hInstance, 0)
Call SetWindowPos(mybut1, 0, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Call SetWindowPos(yorik, -1, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Call SetForegroundWindow(yorik)
'--------------
Call SetProp(mybut1, "GRANDMA", GetWindowLong(mybut1, GWL_WNDPROC))
SetWindowLong mybut1, GWL_WNDPROC, AddressOf win_proc
Else
MsgBox "Йорика не видели? Ушел, сука!"
End If
Me.Show
End Sub
'----------------в модуле
Public Function win_proc( ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_LBUTTONUP
MsgBox "qwerty"
End Select
win_proc = CallWindowProc(GetProp(hwnd, "GRANDMA" , hwnd, Msg, wParam, lParam)
End Function
опускаю декларации.
И если этот, мною написанный маразм, кого-нибудь из новичков заставит мыслить своими мозгами, буду только рад.
Ответить
|
Номер ответа: 12 Автор ответа: EUGY
Вопросов: 0 Ответов: 454
|
Профиль | | #12
|
Добавлено: 26.06.07 09:02
|
Допустим, есть некое приложение. Мне нужно добавить в него объект (кнопку) и привязать к нему свой код. Как, и можно ли это сделать на Visual Basic?
Выложу это прости-господи еще раз, чуть причесав.
Злобные насмешки, унижающие достоинство, приветствуются.
' SUB MAIN
Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function CreateWindowEx Lib "user32" 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 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
'Public Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function SetForegroundWindow Lib "user32" ( ByVal hwnd As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( ByVal hwnd As Long, ByVal nIndex As Long) As Long
'Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
'Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
'Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function SetProp Lib "user32" Alias "SetPropA" ( ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Public Declare Function DefWindowProc Lib "user32" Alias " efWindowProcA" ( ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function ShowWindow Lib "user32" ( ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function GetProp Lib "user32" Alias "GetPropA" ( ByVal hwnd As Long, ByVal lpString As String) As Long
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
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" ( ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Public Declare Function GetParent Lib "user32" ( ByVal hwnd As Long) As Long
Public Declare Function CloseWindow Lib "user32" ( ByVal hwnd As Long) As Long
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOMOVE = &H2
Public Const WS_CHILD = &H40000000
Public Const WS_VISIBLE = &H10000000
Public Const WS_CLIPCHILDREN = &H2000000
Public Const WS_CLIPSIBLINGS = &H4000000
Public Const GWL_WNDPROC = (-4)
Public Const WM_LBUTTONUP = &H202
Sub Main()
Dim yorik As Long
Dim mybut1 As Long
yorik = FindWindow(vbNullString, "Калькулятор" '
If (yorik = 0) Then
Call Shell("calc.exe", vbNormalFocus)
yorik = FindWindow(vbNullString, "Калькулятор"
End If
If yorik Then
mybut1 = CreateWindowEx(0, "BUTTON", "Éîðèê, Must Die", WS_CLIPCHILDREN Or WS_CLIPSIBLINGS Or WS_CHILD Or WS_VISIBLE, 2, 2, 150, 50, yorik, 0, App.hInstance, 0)
Call SetWindowPos(mybut1, 0, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Call SetWindowPos(yorik, -1, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Call SetProp(mybut1, "GRANDMA", GetWindowLong(mybut1, GWL_WNDPROC))
Call SetWindowLong(mybut1, GWL_WNDPROC, AddressOf win_proc)
Call SetForegroundWindow(yorik)
Else
MsgBox "Éîðèêà íå âèäåëè? Óøåë, ñóêà!"
End If
End Sub
Public Function win_proc( ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_LBUTTONUP
Call MessageBox(GetParent(hwnd), "Éîðèê, Must Die", "qwerty", 0)
End Select
win_proc = CallWindowProc(GetProp(hwnd, "GRANDMA" , hwnd, Msg, wParam, lParam)
End Function
Ответить
|
Страница: 1 | 2 | 3 |
Поиск по форуму