Results 1 to 19 of 19

Thread: How to get list of programs

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269

    How to get list of programs

    How do I get a list of programs running. I need to know if one program is running, WinDVD4. Does it have a special id or something. The best way would be if I could just get a list and get my prog to run through this list and to find WinDVD4 in it (shouldnt be hard)/

    What code do I need or is there a bas file out there to do this.

    Thanks ppl.

    Oh and what I need then is to be able to change the length \ width of it to any pixels I want by typing those in.

    Can I do all this through the mighty basic.

    Thanks

  2. #2
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    You can use the FindWindow API to find the handle, or hWnd of the DVD program. You just need to know the class name, which you can find using a program called Spy++ that comes with Visual Studio. There is also a free program to do this on http://www.patorjk.com/ if you don't have VS. Next, you will need to find out to how to modify the metrics of a window, once you have the window handle, it won't take much to modify it using the appropriate API calls.
    <removed by admin>

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Practical Example...

    Copy/paste this into a module
    VB Code:
    1. Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    2. 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
    3. Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
    4.  
    5. Private Const WM_GETTEXT = &HD
    6.  
    7. Private aCaptions() As String
    8. Private lCount As Long
    9.  
    10. Public Function GetAllCaptions() As Variant
    11.     lCount = 0
    12.     Call EnumWindows(AddressOf EnumWindowsProc, 0&)
    13.     If lCount Then ReDim Preserve aCaptions(lCount - 1)
    14.     GetAllCaptions = IIf(lCount, aCaptions, Array())
    15. End Function
    16.  
    17. Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    18.     Dim sBuffer As String * 260
    19.     If IsWindowVisible(hwnd) Then
    20.         ReDim Preserve aCaptions(lCount)
    21.         aCaptions(lCount) = Left(sBuffer, SendMessage(hwnd, WM_GETTEXT, 260, ByVal sBuffer))
    22.         If Len(Trim(aCaptions(lCount))) Then lCount = lCount + 1
    23.     End If
    24.     EnumWindowsProc = hwnd
    25. End Function
    Copy/paste this to the declarations section of a form with a Listbox (List1) and a button (Command1)
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim vCaps As Variant
    3.     Dim lIndex As Long
    4.    
    5.     vCaps = GetAllCaptions()
    6.     List1.Clear
    7.     For lIndex = 0 To UBound(vCaps)
    8.         List1.AddItem vCaps(lIndex)
    9.     Next
    10. End Sub

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269
    WOW

    Thanks so much for that code

    Gonna try it out

    hope I will be able to change the window size.

    KT

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269
    OK

    Got the list of programs working

    But better yet that findwindow works great

    OK so I have this now



    hwnd = FindWindow("WinDVDClass", vbNullString)

    I get hwnd as "1100" when WinDVD is running. Great

    I did a search for changing the metrics but again it doesnt seem to be on the forums.

    Anyone know how to do it.

    I have to say a massive thank you to all who have helped me out.

    Hope I can get this final thing now.

  6. #6
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    What kind of "metrics" are you trying to change?
    Please rate my post.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269
    I need to be able to change another programs width and length (window that is).

    I have its info but what is the api code to do this

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269
    Anyone know about window length, height changing or what api code is needed.

    KT

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Private Declare Sub 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)

    SetWindowPos me.hwnd, 0, 100,100,200,200,0 'makes the window at 100,100, with the w/h at 200/200
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269
    OMFG you guys are good, really good

    Excellent man, not too buggy.....

    One more thing my prog needs now.

    Just one more and my prog is happy.

    Will post later.....

    Thankx man

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269
    Worked absolutely brilliantly

    One more thing if you know it

    Now I need to get the positon and width height of that program. I can set it now but now need to get what it is.

    Thanks so much

    I wonder is it possible to change the caption of the program I am changing res. Wouldnt mind putting my own little progs name in there.

    Windvd tweaked by WinDVD Tweaker

    Eh!!

  12. #12
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long


    Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type

    Dim RCT as RECT

    GetWindowRect me.hwnd, RCT

    'then access it using RCT.left,right,top,bottom. width is right - left, height is bottom - top
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269
    Unbelievable!

    Thanks man

    lol

  14. #14
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Originally posted by King_Tweaker
    I wonder is it possible to change the caption of the program I am changing res. Wouldnt mind putting my own little progs name in there.
    Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" ( _
    ByVal hwnd As Long, _
    ByVal lpString As String) As Long

    hwnd = Window
    lpString = New Caption
    Please rate my post.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269
    I have one problem

    Those all worked great but now

    i have a button to move the window one pixel say up. When I click it, my prog loses focus so I added in

    form1.setfocus after the move.

    When someone needs to press this button many times the display looks kind of crappy, switching from the prog to mine.

    Is there a way to get my prog to be always on top of this program so this wont be a problem.

    KT

  16. #16
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    use this flag in the last parameter of SetWindowPos

    Const SWP_NOACTIVATE = &H10
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269
    OMG man you did it again

    Made me go OMFG this guy is good.

    Tanks a million.

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    269
    Can anyone give me a way to read what sizes Windows is using for Window Border and Title Bar because of course I am trying to change the size of the inside window and not the outside one (+borders etcetc..)

    thanks

    KT

  19. #19
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190
    its a great exemple

    works fine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width