Link to home
Start Free TrialLog in
Avatar of Anos
Anos

asked on

Highlighted word in any Browser?

If there is a highlighted word in any Broswer like Netscape or IE, can I defined that word from my VB program?
Avatar of AzraSound
AzraSound
Flag of United States of America image

this is assuming your app has the focus and the browser in question is hidden but has a certain word highlighted?
Avatar of Anos
Anos

ASKER

Yes the browser is active/focus on, its not either minimized or hidden. suppose like you highlight a word in Netscape and then you click a bottom in your VB program that can work with that highlighted word in Browser.
well in order to click your button, that means your app would gain focus, and the browser would lose focus. upon clicking your button you would need to set focus back to the browser for an instance to have enough time to copy the highlighted word to the clipboard.  you should be able to just copy using sendkeys.

SendKeys "^C"
Avatar of Anos

ASKER

Yes you are right? but I guess I read a method work like ALT+TAB .. so once the bottom clicked we apply that ALT+TAB thing so the focus will return to the browser again and we can do what we want !!?? what do u think of this? .. I guess this is not big problem .. the problem how I can just define the highlighted word in netscape?? coz we dont have a control to that Browser. I dont know if there is any method can handle this??

Thanx again AzraSound ;-)

Waiting for Answers.
if you know the title of the window exactly (e.g. Netscape - Home) then you can show the window with this code.  This is a simple app i wrote to hide and show other windows on your computer:

'PLACE TWO COMMAND BUTTONS AND A TEXTBOX ON YOUR FORM
'CODE REQUIRES EXACT WINDOW TITLE IN ORDER TO FUNCTION
'*****************************************************
'
'
'MODULE CODE
'
'
'*****************************************************

DefLng A-Z

Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long

Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

'-- Constants for ShowWindow()
Public Const SW_HIDE = 0
Public Const SW_NORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10


'*****************************************************
'
'
'FORM CODE
'
'
'*****************************************************


Private Function FindShellWindow() As Long
    Dim hWnd As Long
    On Error Resume Next

    hWnd = FindWindow(CLng(0), Text1.Text)

    If hWnd <> 0 Then
        FindShellWindow = hWnd
    End If

End Function

Private Sub HideShowWindow(ByVal hWnd As Long, _
    Optional ByVal Hide As Boolean = False)
    Dim lngShowCmd As Long
    On Error Resume Next

    If Hide = True Then
        lngShowCmd = SW_HIDE
    Else
        lngShowCmd = SW_SHOW
    End If

    Call ShowWindow(hWnd, lngShowCmd)

End Sub

Private Sub Command1_Click()
    Dim hWnd As Long
    On Error Resume Next

    '-- Find the window we're
    ' looking for and then hide it
    hWnd = FindShellWindow()

    If hWnd <> 0 Then
        Call HideShowWindow(hWnd)
    End If
Private Sub Command2_Click()
    Dim hWnd As Long
    On Error Resume Next

    hWnd = FindShellWindow()

    If hWnd <> 0 Then
        Call HideShowWindow(hWnd, True)
    End If

End Sub

Private Sub Form_Load()
    Command1.Caption = "Show Window"
    Command2.Caption = "Hide Window"
    Text1.Text = "Enter name of window you wish to hide/show"
End Sub

After showing the window try sending keys to it as i mentioned previously to copy the highlighted text and then bring your app back to the top using the same principles as bringing netscape to the top.  this may not be the most efficient way but its all i can think of right now.

Avatar of Anos

ASKER

What I need now I guess is how I can tell my VB program to do the ALT+TAB thing? can you help me plz
if you know the title of the window exactly (e.g. Netscape - Home) then you can show the window with this code.  This is a simple app i wrote to hide and show other windows on your computer:

'PLACE TWO COMMAND BUTTONS AND A TEXTBOX ON YOUR FORM
'CODE REQUIRES EXACT WINDOW TITLE IN ORDER TO FUNCTION
'*****************************************************
'
'
'MODULE CODE
'
'
'*****************************************************

DefLng A-Z

Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long

Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

'-- Constants for ShowWindow()
Public Const SW_HIDE = 0
Public Const SW_NORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10


'*****************************************************
'
'
'FORM CODE
'
'
'*****************************************************


Private Function FindShellWindow() As Long
    Dim hWnd As Long
    On Error Resume Next

    hWnd = FindWindow(CLng(0), Text1.Text)

    If hWnd <> 0 Then
        FindShellWindow = hWnd
    End If

End Function

Private Sub HideShowWindow(ByVal hWnd As Long, _
    Optional ByVal Hide As Boolean = False)
    Dim lngShowCmd As Long
    On Error Resume Next

    If Hide = True Then
        lngShowCmd = SW_HIDE
    Else
        lngShowCmd = SW_SHOW
    End If

    Call ShowWindow(hWnd, lngShowCmd)

End Sub

Private Sub Command1_Click()
    Dim hWnd As Long
    On Error Resume Next

    '-- Find the window we're
    ' looking for and then hide it
    hWnd = FindShellWindow()

    If hWnd <> 0 Then
        Call HideShowWindow(hWnd)
    End If
Private Sub Command2_Click()
    Dim hWnd As Long
    On Error Resume Next

    hWnd = FindShellWindow()

    If hWnd <> 0 Then
        Call HideShowWindow(hWnd, True)
    End If

End Sub

Private Sub Form_Load()
    Command1.Caption = "Show Window"
    Command2.Caption = "Hide Window"
    Text1.Text = "Enter name of window you wish to hide/show"
End Sub

After showing the window try sending keys to it as i mentioned previously to copy the highlighted text and then bring your app back to the top using the same principles as bringing netscape to the top.  this may not be the most efficient way but its all i can think of right now.

the problem with alt tab is that you never really know how many times you need to send the alt tab combination.  if you have many windows open you may have to send it 10 times.  if its the only other open window you only have to send it once.  so its not very reliable.
Avatar of Anos

ASKER

What I need now I guess is how I can tell my VB program to do the ALT+TAB thing? can you help me plz
Avatar of Anos

ASKER

Thanx for the Code, but I dont think it will help coz as you know the Window title is not always the same, but about the ALT+TAB .. no it will help coz we just want to implement it once .. Imagine this .. he just highlight a word and then click on my VB program botton .. so it will be the next window in buffer .. so just one ALT+TAB will return the focus to the desired Window. right?
ok then just use sendkeys:

SendKeys "%{TAB}"
SendKeys "^C"
SendKeys "%{TAB}"
Avatar of Anos

ASKER

Thanx for the Code, but I dont think it will help coz as you know the Window title is not always the same, but about the ALT+TAB .. no it will help coz we just want to implement it once .. Imagine this .. he just highlight a word and then click on my VB program botton .. so it will be the next window in buffer .. so just one ALT+TAB will return the focus to the desired Window. right?
Avatar of Anos

ASKER

the SendKeys "%{TAB}"  is not working, are you sure of it, I also tried it before you gave me this comand, I dont know why? you can please try and tell me? try the set of code you wrote up and highlight and word in netscape then try to run the code . and then try to paste? its not giving what we want?
Avatar of Anos

ASKER

the SendKeys "%{TAB}"  is not working, are you sure of it, I also tried it before you gave me this comand, I dont know why? you can please try and tell me? try the set of code you wrote up and highlight and word in netscape then try to run the code . and then try to paste? its not giving what we want?
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Anos

ASKER

Thanx Erick37, thats work fine with me :-)
Avatar of Anos

ASKER

AzraSound .. Thanx alot for your HELP I really appreciate what you have done ;-) .. you deserve the Points .. but .... u know ;-) Thanx again anyway :-)