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 


C++ Help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
The0neThe0nly
Expert Cheater
Reputation: 0

Joined: 08 Dec 2009
Posts: 119
Location: In a box

PostPosted: Sat Feb 04, 2012 8:47 am    Post subject: C++ Help Reply with quote

I'm creating a console application that should create a child window on a desired process. I am trying my best to get it to work. The program runs fine, but does not create a window. I am a beginner to C++.

Code:
// Attempt 5.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <stdio.h>

using namespace std;

HINSTANCE hInst;
 
int main ()
{
   system("Title Hack");
 
   HWND hWnd = FindWindow(0, "Roblox - [Place1]"); // Finds the window
 
   if (hWnd == 0)
   {
      cout << "Could not Locate Window. It must be Place 1. Or you may have opened this before opening Place 1." << endl;
   }
   else
   {
      DWORD process;
      GetWindowThreadProcessId(hWnd, &process);
      HANDLE mainprocess = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, process); // Gives MASSIVE access to the process.
      if (!mainprocess)
      {
         cout << "Could not locate process" << endl;
      }
      else
      {
            CreateWindowEx(NULL, "Window", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPCHILDREN, 0, 0, 500, 380, hWnd, NULL, hInst, NULL);
            CreateWindowEx(-32744, "BUTTON", "Explorer", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 0, 377, 500, 20, hWnd, NULL, hInst, NULL);
      }
      CloseHandle(mainprocess);
      }
   system("pause");
   return 0;
}
Back to top
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Sat Feb 04, 2012 2:59 pm    Post subject: Reply with quote

You don't need the process Handle I guess. In the CreateWindow(ex) API call, check the HWND parent paramter. If you use the Parent window from the other process it should work.

EDIT: You should Register a class first to for creating the dialog


Last edited by NoMercy on Sat Feb 04, 2012 3:39 pm; edited 1 time in total
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Feb 04, 2012 3:01 pm    Post subject: Reply with quote

You need to define a class for your child window to use or it wont be created.

Also your second CreateWindow call to create the button is incorrect, that is attempting to add the button to the main window, not your child window.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
The0neThe0nly
Expert Cheater
Reputation: 0

Joined: 08 Dec 2009
Posts: 119
Location: In a box

PostPosted: Mon Feb 06, 2012 3:55 pm    Post subject: Reply with quote

My new code:

Code:
// Attempt 5.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <io.h>
#include <string>
#include <sstream>
#include <vector>

using std::vector;

using namespace std;

HINSTANCE hInst;
HWND hWnd;
HWND hWndHax;
HWND ExplorerButton;

CRITICAL_SECTION cs;
HANDLE lsEvent;

bool APIENTRY DllMain(HMODULE hModule, DWORD ulReason, LPVOID lpReserved)
{
        hInst = (HINSTANCE)hModule;
       
        //Get rid of compiler warnings since we do not use this parameter.
        UNREFERENCED_PARAMETER(lpReserved);
       
        //If we are attaching to a process.
        if (ulReason == DLL_PROCESS_ATTACH)
        {
                //Do no need the thread-based attach/detach messages in this DLL.
                DisableThreadLibraryCalls(hModule);
        }
       
        //Signal for Loading/Unloading
       
        return (true);
}
 
int main ()
{
   system("Title The0neThe0nly");
 
   HWND hWnd = FindWindow(0, "Roblox - [Place1]"); // Finds the window
 
   if (hWnd == 0)
   {
      cout << "Could not Locate Window. It must be Place 1. Or you may have opened this before opening Place 1." << endl;
   }
   else
   {
      DWORD process;
      GetWindowThreadProcessId(hWnd, &process);
      HANDLE mainprocess = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, process); // Gives MASSIVE access to the process.
      if (!mainprocess)
      {
         cout << "Could not locate process" << endl;
      }
      else
      { // -32744 is the Explorer ID
      ExplorerButton = CreateWindowEx(-32744, "BUTTON", "Explorer", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 0, 377, 500, 20, hWndHax, NULL, hInst, NULL);
         cout << "By The0neThe0nly" << endl;
      hWndHax = CreateWindowEx(NULL, "Hax", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPCHILDREN, 0, 0, 500, 380, hWnd, NULL, hInst, NULL);

                     ShowWindow(ExplorerButton, SW_SHOW);
                        ShowWindow(hWndHax, SW_SHOW);
                        SetFocus(hWndHax);

      }
      CloseHandle(mainprocess);
      }
   system("pause");
   return 0;
}


Quote:
You need to define a class for your child window to use or it wont be created.


How do I do that?

EDIT: I accidentally mixed in some code from other projects, sorry about that.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Feb 06, 2012 4:13 pm    Post subject: Reply with quote

RegisterClass or RegisterClassEx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633586%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633587%28v=vs.85%29.aspx

You'll need to register the class then use the new class name when you create your child window.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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