Game hall principle: Embed other EXE interface programs into your own program interface to run

Source: Internet
Author: User
Preface:No system has learned Win32 and is often surprised by the Shell Effect of windows. I have always wanted to achieve this kind of game hall effect, but I cannot go deep. Yesterday, I had the chance to perform a test. After three hours, I finally figured out the truth and listed it as follows to honor the same person.Results:
HANDLE handle;//process handleHWND apphwnd;//window handle/*************Global functions for hosting******************///Function to enumerate all windows.int CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param){  DWORD pID;  DWORD TpID = GetWindowThreadProcessId(hwnd, &pID);//get process id  if (TpID == (DWORD)param)  {    apphwnd=hwnd;//hwnd is the window handle    return false;  }  return true;}//Functio to start a orocess and return the process handleHANDLE StartProcess(LPCTSTR program, LPCTSTR args){  HANDLE hProcess = NULL;  PROCESS_INFORMATION processInfo;  STARTUPINFO startupInfo;  ::ZeroMemory(&startupInfo, sizeof(startupInfo));  startupInfo.cb = sizeof(startupInfo);  startupInfo.dwFlags = STARTF_USESHOWWINDOW;  startupInfo.wShowWindow = SW_HIDE;  if(::CreateProcess(program, (LPTSTR)args,      NULL,  // process security     NULL,  // thread security     FALSE, // no inheritance     0,     // no startup flags     NULL,  // no special environment     NULL,  // default startup directory     &startupInfo,     &processInfo))  {     Sleep(1000);    ::EnumWindows(&EnumWindowsProc, processInfo.dwThreadId);//Iterate all windows    hProcess = processInfo.hProcess;  }  return hProcess;}void CXXXXXDlg::OnButton1() {  CRect rect;  GetClientRect(&rect);  handle=StartProcess("C:\\WINDOWS\\system32\\mspaint.exe","");  if(apphwnd!=NULL)  {    ::SetParent(apphwnd,m_hWnd);    SetWindowLong(apphwnd, GWL_STYLE, WS_VISIBLE);    ::MoveWindow(apphwnd, rect.left, rect.top,rect.right, rect.bottom, true);  }  else  {    MessageBox("Cannot find Window");  }} 

Intermediate process:

1. At that time, I had a special liking for ShellExecute. CreateProcess did not test the method of hiding it immediately after creation, so I hoped to use shellexecuteex for window retrieval.

In this way, you must obtain the window from the Process Handle obtained by shellexecuteex. After enumeration and traversal, you can find that the process ID is unique, but the handles opened each time are different.

Two hours later, I had to return to my thoughts and rethink how CreateProcess creates a hidden process. Soon I found that it could work.

2. the painful process is always painful. Only the painful person can gradually accumulate and reduce the pain and turn grief into joy.

Legacy problems:

If you encounter a program without a window handle, this method obviously won't work. What should we do?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.