Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Capture text from other hWnd.

Posted on 1997-09-01
2
Medium Priority
?
338 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 200 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

Industry Leaders: 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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

618 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