Solved

Capture text from other hWnd.

Posted on 1997-09-01
2
311 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now