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. find window

find window

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 3 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.
  • A Offline
    A Offline
    Alt F4
    wrote on last edited by
    #1

    What is the easiest way to find and send info to any window containing a certain string? such as, if i wanted to find any window that has a title containing "- Notepad" and send the current time and date to the bottom...

    M A 2 Replies Last reply
    0
    • A Alt F4

      What is the easiest way to find and send info to any window containing a certain string? such as, if i wanted to find any window that has a title containing "- Notepad" and send the current time and date to the bottom...

      M Offline
      M Offline
      Mumiozol
      wrote on last edited by
      #2

      If you want to find one window: HWND FindWindow( LPCTSTR lpClassName, // class name LPCTSTR lpWindowName // window name ); If you want to search for all: HWND GetNextWindow( HWND hWnd, // handle to current window UINT wCmd // direction ); int GetWindowText( HWND hWnd, // handle to window or control LPTSTR lpString, // text buffer int nMaxCount // maximum number of characters to copy ); Mickey :)

      1 Reply Last reply
      0
      • A Alt F4

        What is the easiest way to find and send info to any window containing a certain string? such as, if i wanted to find any window that has a title containing "- Notepad" and send the current time and date to the bottom...

        A Offline
        A Offline
        Antti Keskinen
        wrote on last edited by
        #3

        You can search for a window handle or a CWnd object by using the FindWindow-function. When the call returns, you have either a pointer to CWnd representing this window (MFC version) or the window's HWND (API version). Then you can use this HWND e.g. to change window title by using SetWindowText-function, or if you use the MFC-version, you can use the CWnd to mess around with the window just as if you would have created it yourself. Change status bar, toolbar, menu, layout, minimize, maximize etc etc What exactly is it that you want to do with the current time and date ? Should the target window display this on it's status bar ? Or draw it somewhere else inside it ? Want to hijack a window's Device Context ? Explain. The 'Send the current time and date to the bottom' isn't very informative :D -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

        A 1 Reply Last reply
        0
        • A Antti Keskinen

          You can search for a window handle or a CWnd object by using the FindWindow-function. When the call returns, you have either a pointer to CWnd representing this window (MFC version) or the window's HWND (API version). Then you can use this HWND e.g. to change window title by using SetWindowText-function, or if you use the MFC-version, you can use the CWnd to mess around with the window just as if you would have created it yourself. Change status bar, toolbar, menu, layout, minimize, maximize etc etc What exactly is it that you want to do with the current time and date ? Should the target window display this on it's status bar ? Or draw it somewhere else inside it ? Want to hijack a window's Device Context ? Explain. The 'Send the current time and date to the bottom' isn't very informative :D -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

          A Offline
          A Offline
          Alt F4
          wrote on last edited by
          #4

          well, basically i want to add the current time and date to the bottom of the page in all open notepad windows, save and close them.... to remember where i left off at, and what date/time i was reading it.... but this is just for knowledge.. im not going to make a nice program out of it... just experimenting :-/

          A 1 Reply Last reply
          0
          • A Alt F4

            well, basically i want to add the current time and date to the bottom of the page in all open notepad windows, save and close them.... to remember where i left off at, and what date/time i was reading it.... but this is just for knowledge.. im not going to make a nice program out of it... just experimenting :-/

            A Offline
            A Offline
            Antti Keskinen
            wrote on last edited by
            #5

            Ahh ok. Let's create a general outline of the solution to this problem. 1. Find the window 2. Enumerate the views of this window 3. With each view, access the underlying document 4. Get this document's CString, and append the current date and time to the end. 5. Force window to save all it's open documents/views. For a specific, Notepad-only solution, the outline is a bit different, because Notepad doesn't have any real views: it has one HUGE edit control. Now, some code pieces. With the MFC-way, of course :) // Create a new CWnd object CWnd* pNotepadWin = new CWnd; // Attach it to Notepad // Use Microsoft SPY to determine the class name of Notepad's window HWND hwndNotepad = ::FindWindow( ClassName, NULL ) ); if ( hwndNotepad ) { pNotepadWin->Attach( hwndNotepad ); } else { delete pNotepadWin; return FALSE; } Now we have the CWnd representation of the Notepad window. // Create a CWnd pointer CWnd* pNotepadEdit; // Get the first child window of Notepad Window pNotepadEdit = pNotepadWin->GetTopWindow(); // If the window has no children (It is not Notepad then !) if ( !pNotepadEdit ) { // Detach our CWnd from the Notepad. pNotepadWin->Detach(); // Delete it delete pNotepadWin; return FALSE; } // Enumeration: Find a child window which qualifies as an edit control bool bContinue = true; while ( bContinue ) { // Variables CString strName; // Get this window's class name ::GetClassName(pNotepadEdit->m_hWnd, (LPTSTR) strName, 20); // Is it an edit control ? if ( strName.CompareNoCase("Edit") == 0 ) bContinue = false; // Nope, so try to get the next one pNotepadEdit = pNotepadEdit->GetNextWindow(GW_HWNDNEXT); if ( !pNotepadEdit ) { // No more child windows bContinue = false; } } Phew. That was some coding. But now we have the CWnd of the edit control inside Notepad. After this, it's easy to use 'GetWindowText' and 'SetWindowText' to append the current date and time to the edit control's contents. Perhaps I should turn this into an article :D -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

            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