Solved

Capture text from other hWnd.

Posted on 1997-09-01
2
320 Views
Last Modified: 2008-02-26
Does anybody have a solution MSVC 4.1 of getting text from hWnd in other applications, like spy++. I would be grateful if the solutioncode is not made in classes or objects.
Remeber to make the code as simply as possible otherwise this question gave me nothing. Thank you!
0
Comment
Question by:andla
2 Comments
 

Accepted Solution

by:
jag earned 100 total points
ID: 1168559
If I understand your question right, you can call 'EnumDesktopWindows' and pass it a callback function which will be called n times where n is the number of windows that are children of the desktop.

You will get a lot of windows that you cant see for things like the communications thread for dial-up networking and things that are just running in the background that you are not normally aware of.

When you get the window handle you want, you can recusively do an 'EnumChildWindows' on the handles that you select to finally get the window you want.

Finally you can do a 'GetWindowText' on the handle to copy the text somewhere usefull.

This method works for all text that is not user drawn.

Justin
0
 
LVL 1

Author Comment

by:andla
ID: 1168560
*/I think this is new for me. Kan you help me out with this program. I put the enum...() in the message loop. I was trying to catch a message with no succes of finding one. Please help me out.

/*



#define ENUM 1234
#include<windows.h>
#include "resource.h"

HWND hwdialog;

LRESULT CALLBACK FonsterProcedur(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK DlgProc(HWND hw,UINT msg,WPARAM wp,LPARAM lp);
LRESULT CALLBACK WndProc(HWND hw,UINT msg,WPARAM wp, LPARAM lp);

WINAPI WinMain(HINSTANCE denna,HINSTANCE innan,LPSTR cmd,int mode)
{
      WNDCLASSEX wc;
      wc.hInstance=denna;
      wc.hbrBackground=(HBRUSH)GetStockObject(LTGRAY_BRUSH);
      wc.hCursor=LoadCursor(0,IDC_ARROW);
      wc.hIcon=LoadIcon(0,IDI_APPLICATION);
      wc.hIconSm=LoadIcon(0,IDI_APPLICATION);
      wc.lpszMenuName=0;
      wc.lpszClassName="plutten";
      wc.cbClsExtra=0;
      wc.cbWndExtra=0;
      wc.cbSize=sizeof(WNDCLASSEX);
      wc.lpfnWndProc=FonsterProcedur;
      wc.style=CS_DBLCLKS;

      if(!RegisterClassEx(&wc)) return 0;

      HWND hw;
      hw=CreateWindowEx
            (
            WS_EX_WINDOWEDGE,
            "plutten",
            "titel",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            HWND_DESKTOP,
            0,
            denna,
            0
    );

      ShowWindow(hw,mode);

      MSG msg;

      while(GetMessage(&msg,0,0,0))
            {

                  TranslateMessage(&msg);
                  DispatchMessage(&msg);
                  EnumDesktopWindows(HWND_DESKTOP,(DLGPROC)DlgProc,ENUM);
            }
return msg.wParam;
}



LRESULT CALLBACK FonsterProcedur(HWND hw,UINT msg,WPARAM wp,LPARAM lp)
{
HINSTANCE hi;


            switch (msg)
            {
            case WM_LBUTTONDOWN:
                  hi=(HINSTANCE)GetWindowLong(hw,GWL_HINSTANCE);
                  hwdialog=CreateDialog(hi,"IDD_DIALOG1",hw,(DLGPROC)DlgProc);
                  ShowWindow(hwdialog,SW_SHOW);
                  break;


            case WM_DESTROY:
                  PostQuitMessage(0);
                  break;


        default:
            return DefWindowProc(hw,msg,wp,lp);
            break;
            }
      return 0;
}

BOOL CALLBACK DlgProc(HWND hw,UINT msg,WPARAM wp,LPARAM lp)
{
      
  switch (msg)
            {
            //case WM_MESSAGE: ???
                  if(lp==ENUM)//
                  {
                        char txt[50];
                        GetWindowText(hw,txt,50);
                        if (strlen(txt)>0)
                        {
                              SetWindowText(hw,txt);
                              int n;
                              for(n=0;n<10000000;n++);
                        }
                  }
                  break;
            case WM_COMMAND:

                  switch(LOWORD(wp))
                  {
            
                  case IDCANCEL:
                        SetFocus(hwdialog=GetNextWindow(hw,GW_HWNDNEXT));
                        DestroyWindow(hw);
                        break;
                  
                  case IDC_CHECK1:
                           SetWindowText(hw,"Du klickade på CHECKBOX.");
                        break;
                  case IDC_CHECK3:
                       SetWindowText(hw,"Du klickade på STATE3.");
                        break;
                  case IDC_CHECK2:
                        if(IsDlgButtonChecked(hw,IDC_CHECK2))
                              SetWindowText(hw,"Den är förbockad");
                        if(!IsDlgButtonChecked(hw,IDC_CHECK2))
                              SetWindowText(hw,"Den är avbockad.");
                        break;
                  case IDC_CHECK4:
                        if(IsDlgButtonChecked(hw,IDC_CHECK4))
                              SetWindowText(hw,"Den är förbockad");
                        if(!IsDlgButtonChecked(hw,IDC_CHECK4))
                              SetWindowText(hw,"Den är avbockad.");
                        if(IsDlgButtonChecked(hw,IDC_CHECK4)==2)
                              SetWindowText(hw,"Den är obestämd.");

                        break;


                  }
            break;

            default:
                  return FALSE;
                  break;
            }
      return TRUE;

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C language IDE – Compilers installation 14 75
Dynamically allocate memory 9 64
Unresolved External Symbols 3 109
C++ help/ Toy problem 19 31
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question