gethwnd.c
来自「基于matlab的反演程序,用于地球物理勘探中射线追踪及偏移成像程序.」· C语言 代码 · 共 60 行
C
60 行
/*
GETHWND - Get the Windows handle (HWND) of a windows.
hwnd = gethwnd('<Begining of name of a window>')
Compiled with MEX :
mex gethwnd.c user32.lib shell32.lib
Based on code by J閞鬽e Lacaille @ Miriad Technologies (october 2002)
http://lacaille.jerome.online.fr
mailto:lacaille.jerome@online.fr
*/
#include "windows.h"
#include <math.h>
#include "mex.h"
static char name[256] ;
static unsigned long adr = 0 ;
/*****************************************************************************
* A callback called for each open windows (visible or not).
*****************************************************************************/
BOOL CALLBACK ForEachWindow( HWND hwnd, LPARAM lParam)
{
char windName[256];
GetWindowText(hwnd, windName, sizeof(windName));
if (!adr && (strlen(name)<=strlen(windName)) && !strncmp(name,windName,strlen(name)))
{
void *ptr = hwnd ;
adr = (unsigned long) ptr ;
return FALSE ; // Fini.
}
return TRUE ; // Encore.
}
/*****************************************************************************
* The mex entry point.
*****************************************************************************/
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if ((nrhs != 1) || !mxIsChar(prhs[0])) {
mexErrMsgTxt("gethwnd -- supply window name as argument 1.") ;
}
adr = 0 ;
mxGetString(prhs[0], name, sizeof(name));
if (name[0]) {
EnumWindows(ForEachWindow, (LPARAM) 0) ;
}
plhs[0] = mxCreateNumericMatrix(1, 1, mxUINT32_CLASS, 0);
*((unsigned int *) mxGetData(plhs[0])) = adr;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?