Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Enumerating windows

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Aug 03, 2009 12:17 pm    Post subject: Enumerating windows Reply with quote

How can I get a list or preferably an array of active HWNDs and also how do I get window name by HWND?
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Mon Aug 03, 2009 12:22 pm    Post subject: Reply with quote

Use EnumWindows() to enumerate all the windows and to get the window name just use GetWindowText().
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Aug 03, 2009 3:33 pm    Post subject: Reply with quote

here you go void ma boi i know how you like your copypasta : )



Code:
#include <iostream>
   using namespace std;
#include <tchar.h>
#include <windows.h>
#include <conio.h>

BOOL CALLBACK EnumFunc (HWND, LPARAM);

int _tmain(int argc, _TCHAR* argv[])
{
  EnumWindows( (WNDENUMPROC)&EnumFunc, 0 );

  while( !_kbhit() )
    Sleep(100);

  return 0;
}

BOOL CALLBACK EnumFunc( HWND hWnd, LPARAM lParam )
{
  TCHAR szString[256];

  ZeroMemory( szString, sizeof(szString) );
  if ( GetWindowText( hWnd, (LPWSTR)&szString, 256 ) )
  {
    wprintf( szString );
    wprintf(L"\n");
  }

  return true;
}


Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Aug 03, 2009 4:13 pm    Post subject: Reply with quote

Slugsnack wrote:
here you go void ma boi i know how you like your copypasta : )

Code:
#include <iostream>
   using namespace std;
#include <tchar.h>
#include <windows.h>
#include <conio.h>

BOOL CALLBACK EnumFunc (HWND, LPARAM);

int _tmain(int argc, _TCHAR* argv[])
{
  EnumWindows( (WNDENUMPROC)&EnumFunc, 0 );

  while( !_kbhit() )
    Sleep(100);

  return 0;
}

BOOL CALLBACK EnumFunc( HWND hWnd, LPARAM lParam )
{
  TCHAR szString[256];

  ZeroMemory( szString, sizeof(szString) );
  if ( GetWindowText( hWnd, (LPWSTR)&szString, 256 ) )
  {
    wprintf( szString );
    wprintf(L"\n");
  }

  return true;
}


Why are you including the iostream library without using any of it? Also don't include the whole std namespace, if you're not going to use all of it. I would prefer you typedefing the function instead of including the whole namespace.

Also... allocating memory in a callback without deleting it is... inefficient ;]

If we're using C++, we might as well use new and delete operators. Yo.

Code:
while( !_kbhit() )
    Sleep(100);
Mmm... stick to one header please. We use
Code:
_gettchar
in this bitch.

I only copypasta top notch snippets, yo.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Aug 03, 2009 4:38 pm    Post subject: Reply with quote

; wrote:
Why are you including the iostream library without using any of it? Also don't include the whole std namespace, if you're not going to use all of it.


i converted and simplified one of my old apps where i was using cout instead and forgot to take out the include. i think this was my second app after hello world originally.. in fact the existence of non-used includes makes no difference after generation. i mean it might take.. a few nanoseconds for the compiler to decide the code does not require that header, however after compilation the generated .exe is the same

in fact i was coding C style just in visual studio C++ but unfortunately it only lets me make .cpp files

; wrote:
I would prefer you typedefing the function instead of including the whole namespace.


if you're too incompetent to code the function yourself then you're going to have to make do with other people's half assed attempts. to be honest with you, you have no right to try to critique others' code when you are having problems with something that i did in less than 10 lines of actual code

; wrote:
Also... allocating memory in a callback without deleting it is... inefficient ;]


as for 'allocating memory' without deleting it.. i'm afraid you have dynamic memory allocation mixed up with local variables. local variables you see, are created on the stack and they are gotten rid of when a value is added to the end of the procedure to ESP. this is called callee stack cleanup. you can learn what stack cleanup means here :
http://en.wikipedia.org/wiki/X86_calling_conventions#Caller_clean-up

; wrote:
If we're using C++, we might as well use new and delete operators. Yo.


as for new/delete, yes you COULD use it but i thought it'd be better not to confuse you so i tried to make it as simple as possible, i'll add a version with comments if you like. on top of that, i'll repeat that i was coding C style

in fact though, the overhead for the new/delete is not necessarily going to save you many clock cycles since as i said before we are not really 'allocating' memory when we create a local variable. it's quite hard to explain but as you get more experienced you'll find it easier to understand

btw if you want to learn what a clock cycle is, there is a definition here :
http://en.wikipedia.org/wiki/Cycles_Per_Instruction

; wrote:
Code:
while( !_kbhit() )
    Sleep(100);
Mmm... stick to one header please. We use
Code:
_gettchar
in this bitch.


_gettchar is not the same as _kbhit. that is to say they have two different functions

you might want to google yourself for this one, i don't think it'll be as hard to find as the definition for clock cycle, good luck. do come back if you have trouble finding out though

; wrote:
I only copypasta top notch snippets, yo.


don't bite the hand that feeds you


Last edited by Slugsnack on Mon Aug 03, 2009 4:49 pm; edited 1 time in total
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Aug 03, 2009 4:42 pm    Post subject: Reply with quote

Slugsnack wrote:
i converted and simplified one of my old apps where i was using cout instead and forgot to take out the include. i think this was my second app after hello world. in fact the including of non-used includes makes no difference after generation. i mean it might take.. a few nanoseconds for my computer to decide that in fact i didn't use any of the functions there and then after compilation the generated .exe is the same

in fact i was coding C style just in visual studio C++ but unfortunately it only lets me make .cpp files

Quote:
I would prefer you typedefing the function instead of including the whole namespace

ever hear this phrase ?
Quote:
beggars can't be choosers


if you're too incompetent to code the function yourself then you're going to have to make do with other people's half assed attempts

as for 'allocating memory' without deleting it.. i'm afraid you have dynamic memory allocation mixed up with local variables. local variables you see, are created on the stack and they are gotten rid of when a value is added to the end of the procedure to ESP. this is called callee stack cleanup

as for new/delete, yes you COULD use it but i thought it'd be better not to confuse you so i tried to make it as simple as possible, i'll add a version with comments if you like. on top of that, i'll repeat that i was coding C style

in fact though, the overhead for the new/delete is not necessarily going to save you many clock cycles since as i said before we are not really 'allocating' memory when we create a local variable. it's quite hard to explain but as you get more experienced you'll find it easier to understand

_gettchar is not the same as _kbhit. that is to say they have two different functions.

my final remark to you void :

don't bite the hand that feeds you
Excuses excuses... Rolling Eyes lrn2troll plz
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Aug 03, 2009 4:50 pm    Post subject: Reply with quote

bad doggy, know your place







void : it is not your business to challenge better programmers than you. run off back to your hole and be happy you can leave with a copypasta code snippet
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Aug 03, 2009 5:44 pm    Post subject: Reply with quote

Slugsnack wrote:
bad doggy, know your place







void : it is not your business to challenge better programmers than you. run off back to your hole and be happy you can leave with a copypasta code snippet
Mmmm, you're so immature, nice talking to you. Wink
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Aug 03, 2009 9:16 pm    Post subject: Reply with quote

Can you two morons ever not stir up a shit storm?

Really, what the fuck. Go stroke your argument boners in PM.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites