Solved

Capture text from other hWnd.

Posted on 1997-09-01
2
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

739 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