Solved

Capture text from other hWnd.

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SetCurrentDirectory path limit 7 94
computer science syllabus 3 52
Dialogbox API leak? 18 62
Header of docx file 17 60
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

760 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

20 Experts available now in Live!

Get 1:1 Help Now