Skip to content

Instantly share code, notes, and snippets.

@k4m4r82
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4m4r82/b9fb7ea4f2e30a3dcac2 to your computer and use it in GitHub Desktop.
Save k4m4r82/b9fb7ea4f2e30a3dcac2 to your computer and use it in GitHub Desktop.
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hwnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_COMMAND As Long = &H111
Private Const WM_SETTEXT As Long = &HC
Private Const WM_KEYDOWN As Long = &H100
Private Const VK_RETURN As Long = &HD
Private Const TCM_SETCURFOCUS As Long = &H1330&
Private Const CONST_DELAY As Long = 200
Private Sub ymChatSend(ByVal hwndYMMainClass As Long, ByVal msgToSend As String)
Dim hwndCConvWndBase As Long
Dim hwndYIMInputWindow As Long
'urutkan kelas yg harus dilalui untuk membalas pesan yang masuk
'Y!M 11 : CTabbedIMHost -> CConvWndBase -> YIMInputWindow
hwndCConvWndBase = FindWindowEx(hwndYMMainClass, 0&, "CConvWndBase", vbNullString)
hwndYIMInputWindow = FindWindowEx(hwndCConvWndBase, 0&, "YIMInputWindow", vbNullString)
If hwndYIMInputWindow <> 0 Then
Call SendMessageByString(hwndYIMInputWindow, WM_SETTEXT, 0&, msgToSend)
Call SendMessage(hwndYIMInputWindow, WM_KEYDOWN, VK_RETURN, 0&) 'otomatis menekan tombol Send
End If
End Sub
Private Sub cmdTestSendInstantMsg_Click()
Dim hwndYMMainClass As Long
Dim YHandle As Long
Dim hMain As Long
Dim hSub As Long
Dim SelectItemID As Long
Dim hwndMsgrBuddyTab As Long
Dim hWndInstantMsg As Long
Dim hwnd32770 As Long
Dim hwndEdit As Long
Dim i As Integer
Dim ymIDTarget As String
Dim ymMsg As String
YHandle = FindWindow("YahooBuddyMain", vbNullString)
hMain = GetMenu(YHandle)
hSub = GetSubMenu(hMain, 2)
' cek dialog Send Instant Message
hWndInstantMsg = FindWindow("#32770", "Send an Instant Message")
ymIDTarget = "k4m4r82"
ymMsg = "Tes ngirim pesan via Instant Message"
If hWndInstantMsg = 0 Then ' klo dialog Send Instant Message belum diaktfkan
SelectItemID = GetMenuItemID(hSub, 0&)
PostMessage YHandle, WM_COMMAND, SelectItemID, 0& ' akses menu send instant message
Do While hWndInstantMsg = 0
hWndInstantMsg = FindWindow("#32770", "Send an Instant Message")
DoEvents
Loop
Do While hwndMsgrBuddyTab = 0
hwndMsgrBuddyTab = FindWindowEx(hWndInstantMsg, 0&, "MsgrBuddyTab", vbNullString)
DoEvents
Loop
' fokus ke tab other contact
For i = 1 To 30
SendMessage hwndMsgrBuddyTab, TCM_SETCURFOCUS, 1&, 0&
DoEvents
Next i
' cek class #32770, karna objek text untuk mengetikkan YM ID merupakan child dari class ini
hwnd32770 = FindWindowEx(hWndInstantMsg, 0&, "#32770", vbNullString)
hwndEdit = FindWindowEx(hwnd32770, 0&, "Edit", vbNullString)
' tulis target YM ID
Call SendMessageByString(hwndEdit, WM_SETTEXT, 0&, ymIDTarget)
' tekan tombol enter
PostMessage hwndEdit, WM_KEYDOWN, VK_RETURN, 0&
' tunggu sebentar
Call modWaitApi.MsgWaitObj(CONST_DELAY)
' kirim pesan
hwndYMMainClass = FindWindow("CTabbedIMHost", vbNullString)
Call ymChatSend(hwndYMMainClass, ymMsg)
Else
hwndMsgrBuddyTab = FindWindowEx(hWndInstantMsg, 0&, "MsgrBuddyTab", vbNullString)
' fokus ke tab other contact
SendMessage hwndMsgrBuddyTab, TCM_SETCURFOCUS, 1&, 0&
' cek class #32770, karna objek text untuk mengetikkan YM ID merupakan child dari class ini
hwnd32770 = FindWindowEx(hWndInstantMsg, 0&, "#32770", vbNullString)
hwndEdit = FindWindowEx(hwnd32770, 0&, "Edit", vbNullString)
' tulis target YM ID
Call SendMessageByString(hwndEdit, WM_SETTEXT, 0&, ymIDTarget)
' tekan tombol enter
PostMessage hwndEdit, WM_KEYDOWN, VK_RETURN, 0&
' tunggu sebentar
Call modWaitApi.MsgWaitObj(CONST_DELAY)
hwndYMMainClass = FindWindow("CTabbedIMHost", vbNullString)
Call ymChatSend(hwndYMMainClass, ymMsg)
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment