K I just got this Idea that I want to implement into a program I downloaded. Yes the program is open source but I dont wanna compile it, I just want to sort of Inject?..

What I want to do is add a button to the program and have the button execute my own code without affecting itself..

I was thinking of making a program with a button and then setting the parent to the one I downloaded but then realized that my program will still be running.

If possible I would also like to resize the buttons that already exist on the program to make space for my own..

Does anyone have any idea how to go about this?? I dont need source code I just need to know how. If u do have source code then thats fine and always a plus but its not "NEEDED".

5 Years
Discussion Span
Last Post by triumphost

>> Yes the program is open source but I dont wanna compile

How do you expect to accomplish the goals you posted if you don't recompile the program???? :icon_eek:

#pragma once
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "user32.lib")
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <conio.h>
#include <string.h>
#include <string>
#include <sstream>
#include <cstdlib>


namespace Testing {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
			//TODO: Add the constructor code here

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
			if (components)
				delete components;
	private: System::Windows::Forms::Button^  button1;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->button1 = (gcnew System::Windows::Forms::Button());
			// button1
			this->button1->BackColor = System::Drawing::Color::Tan;
			this->button1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"button1.BackgroundImage")));
			this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 7, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0), true));
			this->button1->ForeColor = System::Drawing::Color::Gold;
			this->button1->Location = System::Drawing::Point(1, 1);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(27, 33);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Sc";
			this->button1->UseVisualStyleBackColor = false;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			this->button1->ParentChanged += gcnew System::EventHandler(this, &Form1::button1_ParentChanged);
			// Form1
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->AutoValidate = System::Windows::Forms::AutoValidate::EnablePreventFocusChange;
			this->ClientSize = System::Drawing::Size(30, 35);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedToolWindow;
			this->MaximizeBox = false;
			this->MinimizeBox = false;
			this->Name = L"Form1";
			this->ShowIcon = false;
			this->ShowInTaskbar = false;
			this->Text = L"SChat";
			this->WindowState = System::Windows::Forms::FormWindowState::Minimized;
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->VisibleChanged += gcnew System::EventHandler(this, &Form1::Form1_VisibleChanged);

#pragma endregion
	private: System::Void button1_ParentChanged(System::Object^  sender, System::EventArgs^  e) {
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 //MessageBox::Show("OMG IT WORKS");
				 HWND Simba = FindWindowW(0, L"Simba - Notepad");
				 ::SendMessage(Simba, WM_KEYDOWN, VK_RETURN,0);				 
				 keybd_event(VK_RETURN,0x1c,0 , 0);
				 keybd_event(VK_RETURN,0x1c, KEYEVENTF_KEYUP,0);*/ 

 void TypeStr(char *lpszString)
  char cChar;
  while((cChar=*lpszString++)) // loops through chars
	short vk=VkKeyScan(cChar); // keycode of char
	if((vk>>8)&1){keybd_event(VK_LSHIFT,0,0,0);} // hold shift if necessary
	keybd_event((unsigned char)vk,0,0,0); // key in
	keybd_event((unsigned char)vk,0,KEYEVENTF_KEYUP,0); // key out
	if((vk>>8)&1){keybd_event(VK_LSHIFT,0,KEYEVENTF_KEYUP,0);} // release shift if necessary
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
				 HWND Smart = FindWindowW(0, L"Program");
				 HWND Simba = FindWindowW(0, L"Firefox");


				 IntPtr ptr = button1->Handle;
				 HWND hButton = (HWND)ptr.ToPointer();

				 HWND sChat = FindWindowW(0, L"SChat");
				 ShowWindow(sChat, SW_HIDE);
				 SetParent(hButton, Smart);
				 button1->Location = System::Drawing::Point(528, 469);
	private: System::Void Form1_VisibleChanged(System::Object^  sender, System::EventArgs^  e) {

The above works for me so far.. It finds the window, Adds a button to it.. When the button is clicked, it does stuff.

How do I get it to detect when the window the button is on gets closed?? Like if the window with the button is closed, Then terminate my program.

P.S. I know guys :( I tried it with compiling the source but it just wont compile... I had to use Mingw32 and it kept saying Build Main [Error 1] or something like that.. And I just got tired of it so I thought u know, maybe there is a way? I tried ResHack but it doesnt detect the program properly.. so yeah.. the above is my only solution. Thank you for the replies. At least you replied unlike the other Load of ppl that saw the thread and couldnt even say that its impossible. So I appreciate the replies.. Any reply as long as it tells me something.

So is there a way to get my program to detect when the other program is closed?? And where do I add it?? I tried, I really did.. I put a do while loop but it kept not responding!

Edited by triumphost: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.