• Welcome to PlanetSquires Forums.
 

FBWinSpy - Preliminary work

Started by José Roca, June 06, 2017, 11:40:48 PM

Previous topic - Next topic

James Fuller

Jose,
  I have investigated this type of app previously and found not knowing the font name, size of the Window/Dialog/Control places them quite low on my must have utilities list.
Have you found (or created) an api that will give you this info?

James


José Roca

As the title of the thread says, it is a preliminary work. The code to retrieve and display information about the controls has not been yet implemented. I have posted it because I knew that Pierre would be interested. The others will have to wait.

José Roca

Quote from: James Fuller on June 10, 2017, 09:35:59 AM
Jose,
  I have investigated this type of app previously and found not knowing the font name, size of the Window/Dialog/Control places them quite low on my must have utilities list.
Have you found (or created) an api that will give you this info?

James

To get the size of a window is a piece of cake.

Regarding the font, there is not guarantee that this info can be obtainable, except for Windows standard controls. I will display it if the info is retrievable.

This function retrieves the font. See Remaks.


' ========================================================================================
' Retrieves the font used by the specified window.
' Parameters:
' - hwnd = Handle to the window.
' - lplfw = Pointer to a LOGFONTW stucture.
' Return value:
'   If the function succeeds, and lplfw is a valid pointer, the return value is the number
'   of bytes stored into the buffer.
'   If the function succeeds, and lplfw is NULL, the return value is the number of bytes
'   required to hold the information the function would store into the buffer.
'   If the function fails, the return value is zero.
' Remarks:
'    WM_GETFONT works fine cross-process, provided that the window you're sending it to
'    responds to this message. This is only guaranteed for standard Windows controls. If the
'    standard Windows control is using the system font, it returns NULL.
'    The WM_GETFONT message does not return a font handle if the message is sent to a dialog
'    box created by the DialogBoxParam, DialogBoxIndirectParam, CreateDialogParam, or
'    CreateDialogIndirectParam function.
'    A window can use an arbitrary font for rendering, or even multiple fonts.
' ========================================================================================
FUNCTION FBWS_GetFont (BYVAL hwnd AS HWND, BYVAL lplfw AS LOGFONTW PTR) AS LONG
   IF IsWindow(hwnd) = FALSE THEN EXIT FUNCTION
   DIM hFont AS HFONT = CAST(HFONT, SendMessageW(hwnd, WM_GETFONT, 0, 0))
   IF hFont = 0 THEN EXIT FUNCTION
   FUNCTION = GetObjectW(hFont, SIZEOF(LOGFONTW), lplfw)
END FUNCTION
' ========================================================================================



José Roca

Added information of the controls, including font name and point size if available.

Code reuploaded in the first post.

James Fuller

Jose,
  Thank you for the confirmation.
Now to be any use for DDT -> SDK (CWindow) you will need to add functionality to query the user for the font name and pont size for the Dialog and controls.
I had visions of doing this but lost interest.

James

José Roca

It already retrieves the font of the controls.

To retrieve the font used by the dialog, it's simply a matter of adding


   ' // Get the font, if available
   DIM lfw AS LOGFONTW
   IF FBWS_GetFont(hwndMain, @lfw) THEN
      TreeView_AddItem(hTreeView, __hMainWindowNode, NULL, "Font mame: " & lfw.lfFaceName)
      TreeView_AddItem(hTreeView, __hMainWindowNode, NULL, "Font point size: " & AfxGetFontPointSize(lfw.lfHeight))
   END IF


I have checked it and DDT dialogs respond to the WM_GETFONT message.

José Roca

#21
BTW I don't have any interest in translating DDT code to SDK. I'm allergic to dialogs in general and to DDT in particular.

At most, we could translate the GUI, but what is going to do with this the typical DDTer, without  much knowledge of SDK code (Pierre is an exception), with the rest of DDT code?

José Roca

Added menu information and other changes.

Code reuploaded in the first post.

José Roca

Added information about rebars and other changes.

Code reuploaded in the first post.

José Roca

Now it searches recursively if a child window or control (e.g. a tab control) has also children and displays full information.

Code reuploaded in the first post.

Pierre Bellisle

#25
Hey Jose,

On my machine, using Control-A in the "Code TAB" edit control will beep.
Also Control-E is assigned to "è" on my keyboard making the character to be inserted.
All seem's fine if I use the modified code, except that, of course, the code for "è" is not a valid solution

Is Control-E is standard for selection in Spanish? 

Pierre

' ========================================================================================
' Code text box window procedure
' ========================================================================================
FUNCTION FBWS_Edit_CodeView_WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

   SELECT CASE uMsg

#If 0 'Genuine Jose code
      CASE WM_KEYDOWN
         ' // If Ctrl+A or Ctrl+E pressed, select all the text
         IF wParam = VK_A OR wParam = VK_E THEN
            IF GetAsyncKeyState(VK_CONTROL) THEN
               PostMessage hwnd, EM_SETSEL, 0, -1
            END IF
         END IF

         ' // Eat the Escape key to avoid the page being destroyed
         IF wParam = VK_ESCAPE THEN EXIT FUNCTION

#Else 'Modified code
      CASE WM_CHAR
        SELECT CASE wParam
          CASE 1, 232 '1 = Control-A, 232 = è 
            'Using WM_CHAR/1 instead of WM_KEYDOWN/VK_A will not beep
            'On my keyboard Control-e give "è". So it add "è" to the text before selection
            SendMessage(hWnd, EM_SETSEL, 0, - 1) 'Select everything
            EXIT FUNCTION
        END SELECT

      CASE WM_KEYDOWN
         IF wParam = VK_ESCAPE THEN EXIT FUNCTION     
#EndIf

      CASE WM_DESTROY
         ' // REQUIRED: Remove control subclassing
         SetWindowLongPtrW hwnd, GWLP_WNDPROC, CAST(LONG_PTR, RemovePropW(hwnd, "OLDWNDPROC"))

   END SELECT

   ' // Default processing of Windows messages
   FUNCTION = CallWindowProcW(GetPropW(hwnd, "OLDWNDPROC"), hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


José Roca

#26
As I normally have my speaker off because of these annoying web pages with sound, I didn't have noticed the beep :)

Maybe better to use only


      CASE WM_CHAR
         SELECT CASE wParam
            CASE 1   ' // Ctrl+A
               SendMessage(hWnd, EM_SETSEL, 0, - 1) 'Select everything
               EXIT FUNCTION
         END SELECT


Otherwise, we can't use è.

> Is Control-E is standard for selection in Spanish?

Explorer and Notepad use it.

Pierre Bellisle

Hey,

The "è" is certainly no big deal for me, I might be the only one having it cause I got my own layout using MS-Keyboard-Layout-Creator.
It's not a french keyboard standard asignment, still other may have the letter "e" inserted with a beep.

This is interesting stuff, one more thing to take care about... :-) Comparison of shortcuts in English and Spanish

Pierre

José Roca

These differences came because they try to choose a shortcut that is easier to remember according the language of the user.

For example:

Ctrl+F (for English "Find"), Ctrl+B (for Spanish "Buscar")
Ctrl+O (for English "Open"), Ctrl+A (for Spanish "Abrir")
Ctrl+E (for English "All"), Ctrl+E (could have been Ctrl+T, for Spanish "Todo", but Ctrl+T is already used for "Tamaño", i.e. "Size")
Ctrl+U (for English "Underline"), Ctrl+S (for Spanish "Subrayado")
etc.

In Notepad, using the Spanish Windows version, to do a "Find" you have to use Ctrl+B (not Ctrl+F) and to select all Ctrl+E (not Ctrl-A).