临时记录

 

linux捕捉异常: signal函数 

 

HANDLE handle;//process handle

HWND 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 process and return the process handle

HANDLE StartProcess(LPCTSTR program, LPCTSTR args)

{

 

HANDLE hProcess = NULL;

PROCESS_INFORMATION processInfo;

STARTUPINFO startupInfo;

::ZeroMemory(&startupInfo, sizeof(startupInfo));

startupInfo.cb = sizeof(startupInfo);

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))

{ /* success */

            Sleep(5000);

             ::EnumWindows(&EnumWindowsProc, processInfo.dwThreadId);//Iterate all windows

     hProcess = processInfo.hProcess;

} /* success */

return hProcess;

}

 

/**********************************************************/

//handle for host menu

void CHostMSPaintDlg::OnActionHostmspaint()

{

    CRect rect;

    GetClientRect(&rect);//get our dialog size into rect

 

    handle=StartProcess("C:\\WINDOWS\\system32\\mspaint.exe", "");//Start ms paint

    if(apphwnd!=NULL)//check for window handle

    {

        ::SetParent(apphwnd,m_hWnd);//set parent of ms paint to our dialog.

        SetWindowLong(apphwnd, GWL_STYLE, WS_VISIBLE);//eraze title of ms paint window.

        //Positioning ms paint.

        ::MoveWindow(apphwnd, rect.left, rect.top,rect.right, rect.bottom, true);

            

    }

    else//no window for our process

        MessageBox("Cannot find Window");    

}

 

//handle for kill process menu.

void CHostMSPaintDlg::OnActionKillprocess()

{

    TerminateProcess(handle,0);    //kill the process using handle

}

 

 

宏使用

 

#include <stdio.h>

 

#define chSTR2(x) #x

#define chSTR(x) chSTR2(x)

#define chMSG(desc) (__FILE__ "(" chSTR(__LINE__) "):" #desc)

 

int main(int argc, _TCHAR* argv[])

{

printf("%s \n" , chMSG(hello));

return 0;

}

posted on 2017-06-15 21:50  Waaaaaall-E  阅读(148)  评论(0编辑  收藏  举报

导航