1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include <Windows.h>
#include <iostream>
#include <string>
using namespace std;
#define ClearScreen() system( "CLS" )
DWORD ThreadProc (LPVOID lpdwThreadParam )
{
system( "notepad.exe" );
return 0;
}
void WriteText( const string & text )
{
if ( CreateThread( NULL, //Choose default security
0, //Default stack size
(LPTHREAD_START_ROUTINE)&ThreadProc,//Routine to execute
NULL, //Thread parameter
0, //Immediately run the thread
NULL //Thread Id
) == NULL)
{
cout << "Error Creating Thread" << endl;
return;
}
HWND nphWnd = NULL;
while( nphWnd == NULL )
{
nphWnd = FindWindow( "Notepad", NULL );
Sleep( 500 );
}
ShowWindow( nphWnd, SW_HIDE );
ShowWindow( nphWnd, SW_RESTORE );
ShowWindow( nphWnd, SW_HIDE );
POINT pt;
pt.x = 1;
pt.y = 1;
for( size_t i = 0; i < text.size(); i++ )
SendMessage( ChildWindowFromPoint( nphWnd, pt ), WM_CHAR, text[ i ], NULL );
ShowWindow ( nphWnd, SW_SHOWMINIMIZED );
ClearScreen();
}
int main(int argc, char* argv[])
{
WriteText( "test" );
cout << "done." << endl;
cin.get();
return 0;
} |
Partager