Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Need to detect the properties of any object on an application window.

Need to detect the properties of any object on an application window.

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kartikdasani
    wrote on last edited by
    #1

    Need a way to detect the properties of the text of any object on an application window example the displayed name of a button or a tab, label etc. Is there a means to get properties like : 1. name of the font 2. color of the font 3. size of the font 4. bold/italic/regular etc..

    C _ C E 4 Replies Last reply
    0
    • K kartikdasani

      Need a way to detect the properties of the text of any object on an application window example the displayed name of a button or a tab, label etc. Is there a means to get properties like : 1. name of the font 2. color of the font 3. size of the font 4. bold/italic/regular etc..

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      not really. remember, a window can draw on itself using any font, with any set of attributes, at any time. and it doesn't have to keep track of any of that.

      image processing toolkits | batch image processing

      K 1 Reply Last reply
      0
      • C Chris Losinger

        not really. remember, a window can draw on itself using any font, with any set of attributes, at any time. and it doesn't have to keep track of any of that.

        image processing toolkits | batch image processing

        K Offline
        K Offline
        kartikdasani
        wrote on last edited by
        #3

        How about the current set of properties for example : the page contains a listview and the text of the listview items is set at a particular set of properties font,size,color etc. Now can we get the properties of the currently displayed text in the listview.

        C 1 Reply Last reply
        0
        • K kartikdasani

          How about the current set of properties for example : the page contains a listview and the text of the listview items is set at a particular set of properties font,size,color etc. Now can we get the properties of the currently displayed text in the listview.

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          sure, if the author of the control wants to store and report all the font usage for that control, you'll be able to get it. but in general, there's no way to know which fonts a window has used.

          image processing toolkits | batch image processing

          1 Reply Last reply
          0
          • K kartikdasani

            Need a way to detect the properties of the text of any object on an application window example the displayed name of a button or a tab, label etc. Is there a means to get properties like : 1. name of the font 2. color of the font 3. size of the font 4. bold/italic/regular etc..

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            As Chris said, it is not guaranteed to get what you want. A window or control has an associated device context and a device context has an associated font. However, when a window draws text it can change this. You can get the currently associated font using the GetTextMetrics[^] function. But this may not be the expected result.

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++)

            Polymorphism in C

            1 Reply Last reply
            0
            • K kartikdasani

              Need a way to detect the properties of the text of any object on an application window example the displayed name of a button or a tab, label etc. Is there a means to get properties like : 1. name of the font 2. color of the font 3. size of the font 4. bold/italic/regular etc..

              C Offline
              C Offline
              Code o mat
              wrote on last edited by
              #6

              You could try experimenting with API hooking, however, this might prove to be quite a challange, if possible at all, and it might or might not produce the required result. You could try hooking the GetDC[^], GetWindowDC[^], BeginPaint[^]... (and probably their counterparts also, ReleaseDC, EndPaint, ...) and the kinds, also DrawText[^], DrawTextEx[^], TextOut[^], ..., keep track of the connection between the Device Contexts and window handles, querying the font information at the right places (e.g. like when DrawText is called). Check out this article: API hooking revealed[^] for more info on API hooking. The hooking part itself is somewhat easier if you try to hook things in your own process, no need to 'Inject' a DLL, you can simply load it. Btw, why do you need that information? Just curious here...

              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > //TODO: Implement signature here<

              1 Reply Last reply
              0
              • K kartikdasani

                Need a way to detect the properties of the text of any object on an application window example the displayed name of a button or a tab, label etc. Is there a means to get properties like : 1. name of the font 2. color of the font 3. size of the font 4. bold/italic/regular etc..

                E Offline
                E Offline
                Eugen Podsypalnikov
                wrote on last edited by
                #7

                In general case, except the discovering of the font color :) :

                void TryGetFontInfo(CWnd* pcWnd)
                {
                if (pcWnd->GetSafeHwnd()) {
                CFont* pcFont(pcWnd->GetFont());
                if (pcFont->GetSafeHandle()) {
                LOGFONT sLF = {0}; // see its fields at MSDN
                pcFont->GetLogFont(&sLF);
                // analyze the fields content now :)
                }
                }
                }

                They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups