WIN32 Window Handler v2

WinBoot

Registered Member
Joined
Aug 25, 2010
Messages
62
Reaction score
14
Added:
* Password handle
* Text input retrieval
Code:
#include "Handling.h"
handler Handling;

//================================================================================
void handler::savePosition( int x, int y, int w, int h, int number )
{
	cHandler[ number ].x = x;
	cHandler[ number ].y = y;
	cHandler[ number ].w = w;
	cHandler[ number ].h = h;
}

//================================================================================
void handler::Button( int x, int y, int w, int h, char *text )
{
	CurrentCommand++;
	cHandler[ CurrentCommand ].text = text;
	savePosition( x, y, w, h, CurrentCommand );

	cHandler[ CurrentCommand ].cHWND = CreateWindow( "Button", text, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, x, y, w, h, hwnd, ( HMENU ) CurrentCommand, g_hInst, 0 );
}

//================================================================================
void handler::Edit( int x, int y, int w, int h, char *text )
{
	CurrentCommand++;
	cHandler[ CurrentCommand ].text = text;
	savePosition( x, y, w, h, CurrentCommand );

	cHandler[ CurrentCommand ].cHWND = CreateWindow( "Edit", text, WS_BORDER | WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, ( HMENU ) CurrentCommand, g_hInst, 0 );
}

//================================================================================
void handler::EditPassword( int x, int y, int w, int h, char *text )
{
	CurrentCommand++;
	cHandler[ CurrentCommand ].text = text;
	savePosition( x, y, w, h, CurrentCommand );

	HWND WindowReturn = CreateWindow( "Edit", text, ES_PASSWORD | WS_BORDER | WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, ( HMENU ) CurrentCommand, g_hInst, 0 );
}

//================================================================================
void handler::Static( int x, int y, int w, int h, char *text )
{
	CurrentCommand++;
	cHandler[ CurrentCommand ].text = text;
	savePosition( x, y, w, h, CurrentCommand );

	CreateWindow( "Static", text, WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, ( HMENU ) CurrentCommand, g_hInst, 0 );
}

//================================================================================
/*
int handler::getButtonIDbyName( char *name )
{
	for ( int i = 0; i <= CurrentCommand; i++ )
	{
		if ( !strcmp( name, cHandler[ i ].text ) )
			return i;
	}
	return NULL;
}
*/

//================================================================================
int handler::getButtonIDbyPosition( int x, int y, int w, int h )
{
	for ( int i = 0; i <= CurrentCommand; i++ )
	{
		if ( cHandler[ i ].x == x &&
			 cHandler[ i ].y == y &&
			 cHandler[ i ].w == w &&
			 cHandler[ i ].h == h )
			 return i;
	}
	return NULL;
}

//================================================================================
char *handler::getButtonStringByPosition ( int x, int y, int w, int h, char tString[MAXSTRINGLENGTH] )
{
	if ( GetDlgItemText( hwnd, getButtonIDbyPosition( x, y, w, h ), tString, MAXSTRINGLENGTH ) )
		return tString;
	else
		return NULL;
}

//================================================================================
/*
char *handler::getButtonNameByID( int ID )
{
	if ( cHandler[ ID ].text != NULL )
		return cHandler[ ID ].text;
	else
		return NULL;
}
*/

//================================================================================
char *handler::getButtonNameByPosition ( int x, int y, int w, int h )
{
	for ( int i = 0; i <= CurrentCommand; i++ )
	{
		if ( cHandler[ i ].x == x &&
			 cHandler[ i ].y == y &&
			 cHandler[ i ].w == w &&
			 cHandler[ i ].h == h )
			 return cHandler[ i ].text;
	}
	return NULL;
}
Code:
#include <windows.h>
#include <vector>

using namespace std;
#define MAXACTIONS 64
#define MAXSTRINGLENGTH 16

//================================================================================
struct CommandHandler
{
	HWND cHWND;
	char *text;

	int x;
	int y;
	int w;
	int h;
};

//================================================================================
class handler
{
private:
	int CurrentCommand;

	HWND hwnd;
	HINSTANCE g_hInst;

	void savePosition( int x, int y, int w, int h, int number );
public:
	HWND WindowReturn;
	CommandHandler cHandler[ MAXACTIONS ];

	void save( HINSTANCE Instance ) { g_hInst = Instance; }
	void updateHandling( HWND Handling ) { hwnd = Handling; }

	//char *getButtonNameByID( int ID );
	char *getButtonNameByPosition ( int x, int y, int w, int h );
	char *getButtonStringByPosition ( int x, int y, int w, int h, char tString[MAXSTRINGLENGTH] );

	//int getButtonIDbyName( char *name );
	int getButtonIDbyPosition( int x, int y, int w, int h );

	void Edit( int x, int y, int w, int h, char *text );
	void EditPassword( int x, int y, int w, int h, char *text );
	void Static( int x, int y, int w, int h, char *text );
	void Button( int x, int y, int w, int h, char *text );
public:
	handler( ) : CurrentCommand( 0 ) { };
};
extern handler Handling;
 
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features and essential functions on BlackHatWorld and other forums. These functions are unrelated to ads, such as internal links and images. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock