Page 1 of 1

Running Windows Informations (Windows)

Posted: Fri Jan 08, 2010 2:56 pm
by RASHAD
I tried to get the best method to identify any running process but I just came to conclusion
that no of any method I tried is perfect
Here you will get
1-Window Handle
2-Window Caption Text
3-Window Class Name
4-Window Style

for parent and child too
I found for ex. that control panel and programs and features and system for win 7 have the same Window Class Name

For test run any prog. then run this code and point the mouse cursor to the running application caption
Wait for few seconds and you will get the informations
Please try and comment

Code: Select all


      WindowText$ = Space(100)
      ClassName$ = Space(100)
      ParentWindowText$ = Space(100)
      ParentClassName$ = Space(100)
      ModuleFileName$ = Space(255)
      
    While a <> 100
          a = a + 1
          GetCursorPos_(@cp.point)                                                            ; Get cursor position      
          hWndOver = WindowFromPoint_(cp\y << 32 + cp\x)                                      ; Get window cursor is over
          Delay(50)
    Wend    
      If hWndOver <> hWndLast                                                                 ; If changed update display
         hWndLast = hWndOver                                                                  ; Save change
         MessageRequester("Window Handle: ","Window Handle   : "+Str(hWndOver))               ; Display window handle

         r = GetWindowText_(hWndOver, @WindowText$, 100)                                      ; Window text
         MessageRequester("Window Text: ","Window Text  : "+Left(WindowText$, r))

         r = GetClassName_(hWndOver, @ClassName$, 100)                                        ; Window Class
         MessageRequester("Window Class Name: ","Window Class Name  : " + Left(ClassName$, r))

         lWindowStyle = GetWindowLong_(hWndOver, #GWL_STYLE)                                  ; Window Style
         MessageRequester("Window Style: " ,"Window Style  : " + Str(lWindowStyle))

         ; Get handle of parent window:
         hWndParent = GetParent_(hWndOver)

         ; If there is a parent get more info:
         If hWndParent <> 0
            ; Get ID of window:
            wID = GetWindowLong_(hWndOver,#GWL_ID)
            MessageRequester("Window ID Number  : ","Window ID Number  : " + Str(wID))
            MessageRequester("Parent Window Handle  : ","Parent Window Handle  : " + Str(hWndParent))

            ; Get the text of the Parent window:
            r = GetWindowText_(hWndParent, @ParentWindowText$, 100)
            MessageRequester("Parent Window Text  : " ,"Parent Window Text  : " + Left(ParentWindowText$, r))

            ; Get the class name of the parent window:
            r = GetClassName_(hWndParent, @ParentClassName$, 100)
            MessageRequester("Parent Window Class Name  : ","Parent Window Class Name  : " + Left(ParentClassName$, r))
         Else
            ; Update fields when no parent:
            MessageRequester("Window ID Number  : ","Null")
            MessageRequester("Parent Window Handle  : ","Null")
            MessageRequester("Parent Window Text : ","Nothing")
            MessageRequester("Parent Window Class Name: ","Nothing")
         EndIf

;          ; Get window instance:
;          hInstance = GetWindowLong_(hWndOver, #GWL_HINSTANCE)
;          MessageRequester("Module : ",Str(hInstance))
;          ; Get module file name:
;          r = GetModuleFileName_(hInstance, @ModuleFileName$, 255)
;          MessageRequester("Module : ","Module : " + Left(ModuleFileName$, r))
;          ;MessageRequester("Module : ",Str(r))
     EndIf
     
Have fun

Re: Running Windows Informations (Windows)

Posted: Fri Jan 08, 2010 4:50 pm
by rsts
Seems to work fine here.

Win 7 pb 4.4 final.

Very nice :D

cheers

Re: Running Windows Informations (Windows)

Posted: Fri Jan 08, 2010 8:31 pm
by Rook Zimbabwe
Greatis Windose -- Google for it and use to check values! 8)

Re: Running Windows Informations (Windows)

Posted: Fri Jan 08, 2010 9:15 pm
by RASHAD
@rsts hi
Thank you very much for your post

@Rook hi
You have a big problem
Nothing is OK with you even AVATAR movie
The values are OK it is the same I am using MS API only in Greatise it is in Hex while in my code it is in Dec
This code to be used inside the programes by the programmer
If we will use Ext utility to check our req. and another utility to convert bet different formats
and another utility to edit and so on
so it is better to ask Fred to close PureBasic Project
please do something useful to the forum

Re: Running Windows Informations (Windows)

Posted: Sun Jan 10, 2010 4:03 am
by Rook Zimbabwe
Wow RASHAD... nice FLAME!

I don't have any problems...

You can convert hex to dec or use the hex values straight.

lay off the personal attacks as I WAS helping :evil:

Re: Running Windows Informations (Windows)

Posted: Sun Jan 10, 2010 5:31 am
by RASHAD
@Rook hi
If you want to help give me bugs to correct or sugesstions to add or remove any part of the code
that will be much appreciated
But do't blame me for something I am not the only one who did it
Or attack without any reasons
I do't have a criminal mind so I do't know if any member of the forum will use me for any no good purpose
If I feel that I can answer any one so I do
Now I have a feeling that some people here think that I have a bad temper
No I do't afterall if I am wrong or you are wrong please accept my apology

Re: Running Windows Informations (Windows)-Update

Posted: Sun Jan 10, 2010 5:44 am
by RASHAD
Now it is much easier
Run any prog. or programes
Run this piece of code before or after it doe't matter
Point the mouse cursor to any part of the prog
Press the Left Control Key to get the information
You can do that as long as you wish
Press Esc to quit

We have The Window Handle so we can do a lot like getting the window position and dimensions
by using GetWindowRect_() and so on

Have fun

Code: Select all


      WindowText$ = Space(100)
      ClassName$ = Space(100)
      ParentWindowText$ = Space(100)
      ParentClassName$ = Space(100)
      ModuleFileName$ = Space(255)    
    Repeat
    While (GetAsyncKeyState_(#VK_LCONTROL) & $8000 <> 32768)
      If GetAsyncKeyState_(#VK_ESCAPE) & $8000 = 32768
          End       
      EndIf
    Wend    
          GetCursorPos_(@cp.point)                                                            ; Get cursor position      
          hWndOver = WindowFromPoint_(cp\y << 32 + cp\x)                                      ; Get window cursor is over
   
       If   hWndOver <> hWndLast                                                              ; If changed update display
            hWndLast = hWndOver                                                               ; Save change
                                                               
         Mes_1$ = "Window Handle           : "+Str(hWndOver)               ; Display window handle
         
         r = GetWindowText_(hWndOver, @WindowText$, 100)                                      ; Window text
         Mes_2$ = "Window Text                : "+Left(WindowText$, r)
         
         r = GetClassName_(hWndOver, @ClassName$, 100)                                        ; Window Class
         Mes_3$ ="Window Class Name   : " + Left(ClassName$, r)
         
         lWindowStyle = GetWindowLong_(hWndOver, #GWL_STYLE)                                  ; Window Style
         Mes_4$ = "Window Style               : " + Str(lWindowStyle)
         
         ; Get handle of parent window:
         hWndParent = GetParent_(hWndOver)

         ; If there is a parent get more info:
             If hWndParent <> 0
                ; Get ID of window:
                wID = GetWindowLong_(hWndOver,#GWL_ID)
                Mes_5$ = "Window ID Number  : " + Str(wID)
                Mes_6$ = "Parent Window Handle  : " + Str(hWndParent)
    
                ; Get the text of the Parent window:
                r = GetWindowText_(hWndParent, @ParentWindowText$, 100)
                Mes_7$ = "Parent Window Text  : " + Left(ParentWindowText$, r)
    
                ; Get the class name of the parent window:
                r = GetClassName_(hWndParent, @ParentClassName$, 100)
                Mes_8$ = "Parent Window Class Name  : " + Left(ParentClassName$, r)
             Else
                ; Update fields when no parent:
                Mes_9$ = "Window ID Number  : Null"
                Mes_A$ = "Parent Window Handle  : Null"
                Mes_B$ = "Parent Window Text : Nothing"
                Mes_C$ = "Parent Window Class Name: Nothing"
             EndIf
            MessageRequester("Window Information",Mes_1$+#LF$+Mes_2$+#LF$+Mes_3$+#LF$+Mes_4$+#LF$+Mes_5$+#LF$+Mes_6$+#LF$+Mes_7$+#LF$+Mes_8$+#LF$+Mes_9$+#LF$+Mes_A$+#LF$+Mes_B$+#LF$+Mes_C$+#LF$,#MB_ICONEXCLAMATION)

;          ; Get window instance:
;          hInstance = GetWindowLong_(hWndOver, #GWL_HINSTANCE)
;          MessageRequester("Module : ",Str(hInstance))
;          ; Get module file name:
;          r = GetModuleFileName_(hInstance, @ModuleFileName$, 255)
;          MessageRequester("Module : ","Module : " + Left(ModuleFileName$, r))
;          ;MessageRequester("Module : ",Str(r))
      ;GetAsyncKeyState_(#VK_LBUTTON)
      EndIf
 ForEver     

Re: Running Windows Informations (Windows)

Posted: Sun Jan 10, 2010 5:19 pm
by RASHAD
Update :
1- Fixed some minor bugs
2- Press F10 to get the spec. of the windows under cursor
3- Press F11 to get the dim. of the windows under cursor
4- Press F12 to get the color of the pixel under cursor
5- Press Exc to quit

Code: Select all

      WindowText$ = Space(100)
      ClassName$ = Space(100)
      ParentWindowText$ = Space(100)
      ParentClassName$ = Space(100)
      ModuleFileName$ = Space(255)    
    Repeat
    While (GetAsyncKeyState_(#VK_F10) & $8000 <> 32768) And (GetAsyncKeyState_(#VK_F11) & $8000 <> 32768) And (GetAsyncKeyState_(#VK_F12) & $8000 <> 32768)

      If GetAsyncKeyState_(#VK_ESCAPE) & $8000 = 32768
          End       
      EndIf
    Wend
    
          GetCursorPos_(@cp.point)                                                            ; Get cursor position      
          hWndOver = WindowFromPoint_(cp\y << 32 + cp\x)                                      ; Get window cursor is over
          
   If GetAsyncKeyState_(#VK_F10) & $8000 = 32768   
                                                               
         Mes_1$ = "Window Handle           : "+Str(hWndOver)                                  ; Display window handle
         
         r = GetWindowText_(hWndOver, @WindowText$, 100)                                      ; Window text
         Mes_2$ = "Window Text                : "+Left(WindowText$, r)
         
         r = GetClassName_(hWndOver, @ClassName$, 100)                                        ; Window Class
         Mes_3$ ="Window Class Name   : " + Left(ClassName$, r)
         
         lWindowStyle = GetWindowLong_(hWndOver, #GWL_STYLE)                                  ; Window Style
         Mes_4$ = "Window Style               : " + Str(lWindowStyle)
         
         ; Get handle of parent window:
         hWndParent = GetParent_(hWndOver)

         ; If there is a parent get more info:
             If hWndParent <> 0
                ; Get ID of window:
                wID = GetWindowLong_(hWndOver,#GWL_ID)
                Mes_5$ = "Window ID Number  : " + Str(wID)
                Mes_6$ = "Parent Window Handle  : " + Str(hWndParent)
    
                ; Get the text of the Parent window:
                r = GetWindowText_(hWndParent, @ParentWindowText$, 100)
                Mes_7$ = "Parent Window Text  : " + Left(ParentWindowText$, r)
    
                ; Get the class name of the parent window:
                r = GetClassName_(hWndParent, @ParentClassName$, 100)
                Mes_8$ = "Parent Window Class Name  : " + Left(ParentClassName$, r)
             Else
                ; Update fields when no parent:
                Mes_5$ = "Window ID Number  : Null"
                Mes_6$ = "Parent Window Handle  : Null"
                Mes_7$ = "Parent Window Text : Nothing"
                Mes_8$ = "Parent Window Class Name: Nothing"
             EndIf
            MessageRequester("Window Information",Mes_1$+#LF$+Mes_2$+#LF$+Mes_3$+#LF$+Mes_4$+#LF$+Mes_5$+#LF$+Mes_6$+#LF$+Mes_7$+#LF$+Mes_8$+#LF$,#MB_ICONEXCLAMATION)
            
       ElseIf GetAsyncKeyState_(#VK_F11) & $8000 = 32768
       
            GetWindowRect_(hWndOver,@w.RECT)
            MessageRequester("","X Pos : "+Str(w\left)+#LF$+"Y Pos : "+Str(w\top)+#LF$+"Window Width : "+Str(w\right - w\left)+#LF$+"Window Height : "+Str(w\bottom - w\top)+#LF$,#MB_ICONEXCLAMATION)
       
       ElseIf GetAsyncKeyState_(#VK_F12) & $8000 = 32768
       
            hdc = GetDC_(0)
            PColor = GetPixel_(hdc, cp\x, cp\y)
            Red = Red(PColor)
            Green = Green(PColor)
            Blue = Blue(PColor)
            Pixelc$ = RSet(Hex(Red), 2, "0") + RSet(Hex(Green), 2, "0") + RSet(Hex(Blue), 2, "0")
            MessageRequester("","Pixel Color : " + Pixelc$+#LF$+"Pixel Color : RGB("+Str(Red)+","+Str(Green)+","+Str(Blue)+")"+#LF$)
      EndIf
 ForEver