Solved

Highlighted word in any Browser?

Posted on 2000-04-13
17
175 Views
Last Modified: 2010-05-02
If there is a highlighted word in any Broswer like Netscape or IE, can I defined that word from my VB program?
0
Comment
Question by:Anos
  • 10
  • 6
17 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2713025
this is assuming your app has the focus and the browser in question is hidden but has a certain word highlighted?
0
 

Author Comment

by:Anos
ID: 2713070
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.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2713091
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"
0
 

Author Comment

by:Anos
ID: 2713442
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.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2713472
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.

0
 

Author Comment

by:Anos
ID: 2713477
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
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2713478
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.

0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2713501
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.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:Anos
ID: 2713511
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
0
 

Author Comment

by:Anos
ID: 2713522
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?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2713537
ok then just use sendkeys:

SendKeys "%{TAB}"
SendKeys "^C"
SendKeys "%{TAB}"
0
 

Author Comment

by:Anos
ID: 2713551
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?
0
 

Author Comment

by:Anos
ID: 2713575
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?
0
 

Author Comment

by:Anos
ID: 2713598
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?
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 100 total points
ID: 2713767
Private Sub Command1_Click()
    Clipboard.Clear
    Me.Hide
    DoEvents
    SendKeys "^c"
    DoEvents
    Me.Show
    Text1.SetFocus
    SendKeys "^v"
End Sub
0
 

Author Comment

by:Anos
ID: 2713851
Thanx Erick37, thats work fine with me :-)
0
 

Author Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now