#include<windows.h>
#include "mex.h"
//传入1个参数或无参数。
//参数为1,则请求一次点击操作,截取点击窗口。
//参数为0或无参数,则截取整个屏幕。
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
bool bshowmatlab = false;
//mexPrintf("请用鼠标单击欲截取的窗口。\n");
if(nrhs==0)//对输入参数进行检验
bshowmatlab = false;
else if(nrhs>1)
mexErrMsgTxt("Need 1 argument or none!\n");
else if(!mxIsDouble(prhs[0]))
mexErrMsgTxt("The input argument must be a number!\n");
else if(*(double*)(mxGetData(prhs[0]))==0)
bshowmatlab=false;
else
bshowmatlab=true;
HWND DeskWnd;
if(bshowmatlab)
{
//检测鼠标点击
mexPrintf("请用鼠标单击欲截取的窗口。\n");
/* MSG msg;
for (int i=0;i<10;i++) {
Sleep(20);
if (GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
*/
while(!((!GetSystemMetric