亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? zclient.c

?? zemax與matlab調(diào)用程序
?? C
字號:
// Zclient: ZEMAX client template program
// Originally written by Kenneth Moore June 1997
// Copyright 1997-2001 Kenneth Moore
//
// Normally, none of this code needs to be modified. Simply include this file and
// compile and link with the code that contains "UserFunction".
// The zclient program is responsible for establishing communication
// with the ZEMAX server. All data from ZEMAX can be obtained by calling
// PostRequestMessage or PostArrayTraceMessage with the item name and a buffer to hold the data.
//
// Zclient will call UserFunction when the DDE communication link is established and ready.
// Zclient will automatically terminate the connection when UserFunction returns.
//
// Version 1.1 modified to support Array ray tracing September, 1997
// Version 1.2 modified for faster execution October, 1997
// Version 1.3 modified for faster execution November, 1997
// Version 1.4 modified to fix memory leak January, 1998
// Version 1.5 modified to add support for long path names and quotes November, 1998
// Version 1.6 modified to fix missing support for long path names and quotes in MakeEmptyWindow March, 1999
// Version 1.7 modified to fix memory leak in WM_DDE_ACK, March 1999
// Version 1.8 modified to add E-field data to DDERAYDATA for ZEMAX 10.0, December 2000
// Version 1.9 modified PostRequestMessage and PostArrayTraceMessage to return -1 if data failed (usually because of a timeout) or 0 otherwise, April 2001

#include <windows.h>
#include <dde.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "mex.h"

#define WM_USER_INITIATE (WM_USER + 1)
#define DDE_TIMEOUT 5000

typedef struct
	{
   double x, y, z, l, m, n, opd, intensity;
	double Exr, Exi, Eyr, Eyi, Ezr, Ezi;
	int wave, error, vigcode, want_opd;
	}DDERAYDATA;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
void WaitForData(HWND hwnd);
char *GetString(char *szBuffer, int n, char *szSubString);
void remove_quotes(char *s);
int  PostRequestMessage(char *szItem, char *szBuffer);
int  PostArrayTraceMessage(char *szBuffer, DDERAYDATA *RD);
void CenterWindow(HWND hwnd);
void UserFunction(char *szCommandLine);
void MakeEmptyWindow(int text, char *szAppName, char *szOptions);
void Get_2_5_10(double cmax, double *cscale);

/* global variables used by the client code */
char szAppName[] = "ZemaxClient";
int GotData, ngNumRays;
char szGlobalBuffer[5000], szCommandLine[260];
HINSTANCE globalhInstance;
HWND hwndServer, hwndClient;
DDERAYDATA *rdpGRD = NULL;


int CALLBACK LibMain(HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
{
        //if (wHeapSize > 0)
        //   UnlockDate (0);    //Unlocks the data segment of the library.
		globalhInstance = hInstance;
        return 1;
}




//int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)

void mexFunction(
    int nlhs, mxArray *plhs[],
    int nrhs, const mxArray *prhs[])

{
HWND       hwnd;
MSG        msg;
WNDCLASSEX wndclass;

wndclass.cbSize        = sizeof (wndclass);
wndclass.style         = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc   = WndProc;
wndclass.cbClsExtra    = 0;
wndclass.cbWndExtra    = 0;
wndclass.hInstance     = globalhInstance;
wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName  = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION);
RegisterClassEx (&wndclass);

// globalhInstance = hPrevInstance;

// strcpy(szCommandLine, szCmdLine);

hwnd = CreateWindow (szAppName, "ZEMAX Client", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, globalhInstance, NULL);
UpdateWindow (hwnd);
SendMessage (hwnd, WM_USER_INITIATE, 0, 0L);

while (GetMessage (&msg, NULL, 0, 0))
	{
   TranslateMessage (&msg);
   DispatchMessage (&msg);
   }
// return msg.wParam;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
ATOM          aApp, aTop, aItem;
DDEACK        DdeAck;
DDEDATA      *pDdeData;
GLOBALHANDLE  hDdeData;
WORD          wStatus;
UINT          uiLow, uiHi;

switch (iMsg)
	{
   case WM_CREATE :
		hwndServer = 0;
      return 0;

	case WM_USER_INITIATE :
   	/* find ZEMAX */
      aApp = GlobalAddAtom ("ZEMAX");
      aTop = GlobalAddAtom ("RayData");
		SendMessage (HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM) hwnd, MAKELONG (aApp, aTop));

		/* delete the atoms */
      GlobalDeleteAtom (aApp);
      GlobalDeleteAtom (aTop);

      /* If no response, terminate */
      if (hwndServer == NULL)
      	{
		   MessageBox (hwnd, "Cannot communicate with ZEMAX!", "Hello?", MB_ICONEXCLAMATION | MB_OK);
         DestroyWindow(hwnd);
         return 0;
         }

		hwndClient = hwnd;

      UserFunction("c:\\Temp\\Stuff.txt");

      /* terminate the DDE connection */
   	PostMessage(hwndServer, WM_DDE_TERMINATE, (WPARAM) hwnd, 0L);
      hwndServer = NULL;

      /* now TERMINATE! */
      DestroyWindow(hwnd);
      return 0;

   case WM_DDE_DATA :
   	/* here comes the data! */
      // wParam -- sending window handle
      // lParam -- DDEDATA memory handle & item atom
      UnpackDDElParam(WM_DDE_DATA, lParam, &uiLow, &uiHi);
      FreeDDElParam(WM_DDE_DATA, lParam);
		hDdeData  = (GLOBALHANDLE) uiLow;
      pDdeData = (DDEDATA *) GlobalLock (hDdeData);
      aItem     = (ATOM) uiHi;

      // Initialize DdeAck structure
      DdeAck.bAppReturnCode = 0;
      DdeAck.reserved       = 0;
      DdeAck.fBusy          = FALSE;
      DdeAck.fAck           = FALSE;

      // Check for matching format, put the data in the buffer
      if (pDdeData->cfFormat == CF_TEXT)
      	{       
         /* get the data back into RD */
			if (rdpGRD) memcpy(rdpGRD, (DDERAYDATA *) pDdeData->Value, (ngNumRays+1)*sizeof(DDERAYDATA));
			else strcpy(szGlobalBuffer, (char *) pDdeData->Value);
         }

      GotData = 1;
		GlobalDeleteAtom (aItem);

      // Acknowledge if necessary
      if (pDdeData->fAckReq == TRUE)
      	{
         wStatus = *((WORD *) &DdeAck);
         if (!PostMessage ((HWND) wParam, WM_DDE_ACK, (WPARAM) hwnd, PackDDElParam (WM_DDE_ACK, wStatus, aItem)))
         	{
				if (hDdeData)
					{
					GlobalUnlock (hDdeData);
					GlobalFree (hDdeData);
					}
            return 0;
            }
         }

      // Clean up
		GlobalUnlock (hDdeData);
      if (pDdeData->fRelease == TRUE || DdeAck.fAck == FALSE) GlobalFree (hDdeData);
      return 0;

   case WM_DDE_ACK:
   	/* we are receiving an acknowledgement */
      /* the only one we care about is in response to the WM_DDE_INITIATE; otherwise free just the memory */
      if (hwndServer == NULL)
      	{
			uiLow = (UINT) NULL;
			uiHi = (UINT) NULL;
         UnpackDDElParam(WM_DDE_ACK, lParam, &uiLow, &uiHi);
         FreeDDElParam(WM_DDE_ACK, lParam);
         hwndServer = (HWND) wParam;
         if (uiLow) GlobalDeleteAtom((ATOM) uiLow);
         if (uiHi) GlobalDeleteAtom((ATOM) uiHi);
         }
		else
			{
			HWND dummy;
			uiLow = (UINT) NULL;
			uiHi = (UINT) NULL;
         UnpackDDElParam(WM_DDE_ACK, lParam, &uiLow, &uiHi);
         FreeDDElParam(WM_DDE_ACK, lParam);
         dummy = (HWND) wParam;
         if (uiLow) GlobalDeleteAtom((ATOM) uiLow);
         if (uiHi) GlobalDeleteAtom((ATOM) uiHi);
			}
   	return 0;

   case WM_DDE_TERMINATE :
   	PostMessage(hwndServer, WM_DDE_TERMINATE, (WPARAM) hwnd, 0L);
      hwndServer = NULL;
      return 0;

   case WM_PAINT :
   	{
      PAINTSTRUCT ps;
   	BeginPaint(hwnd, &ps);
      EndPaint(hwnd, &ps);
      }
      return 0;

   case WM_CLOSE :
   	PostMessage(hwndServer, WM_DDE_TERMINATE, (WPARAM) hwnd, 0L);
   	break;             // for default processing

   case WM_DESTROY :
   	PostQuitMessage(0);
      return 0;
   }
   return DefWindowProc(hwnd, iMsg, wParam, lParam);
}

void WaitForData(HWND hwnd)
{
int sleep_count;
MSG msg;
DWORD dwTime;
dwTime = GetCurrentTime();
GotData = 0;
sleep_count = 0;
#if(0)
while ( (GetCurrentTime() - dwTime < DDE_TIMEOUT) && !GotData)
	{
   while (PeekMessage (&msg, hwnd, WM_DDE_FIRST, WM_DDE_LAST, PM_REMOVE))
   	{
      DispatchMessage (&msg);
      }
   /* Give the server a chance to respond */
   Sleep(0);
   }
#else

while (!GotData)
	{
   while (PeekMessage (&msg, hwnd, WM_DDE_FIRST, WM_DDE_LAST, PM_REMOVE))
   	{
      DispatchMessage (&msg);
      }
   /* Give the server a chance to respond */
   Sleep(0);
   sleep_count++;
   if (sleep_count > 10000)
   	{
      if (GetCurrentTime() - dwTime > DDE_TIMEOUT) return;
      sleep_count = 0;
      }
   }

#endif
}

char * GetString(char *szBuffer, int n, char *szSubString)
{
int i, j, k;
char szTest[5000];

szSubString[0] = '\0';
i = 0;
j = 0;
k = 0;
while (szBuffer[i] && (k <= n) )
	{
   szTest[j] = szBuffer[i];

   if (szBuffer[i] == '"')
   	{

      i++;
      j++;
      szTest[j] = szBuffer[i];

      /* we have a double quote; keep reading until EOF or another double quote */
      while(szBuffer[i] != '"' && szBuffer[i])
      	{
	      i++;
   	   j++;
		   szTest[j] = szBuffer[i];
         }
      }

   if (szTest[j] == ' ' || szTest[j] == '\n' || szTest[j] == '\r' || szTest[j] == '\0' || szTest[j] == ',')
   	{
      szTest[j] = '\0';
      if (k == n)
      	{
         strcpy(szSubString, szTest);
			return szSubString;
         }
      k++;
      j = -1;
      }
   i++;
   j++;
   }

szTest[j] = '\0';
if (k == n) strcpy(szSubString, szTest);

return szSubString;
}

int PostRequestMessage(char *szItem, char *szBuffer)
{
ATOM aItem;

aItem = GlobalAddAtom(szItem);

/* clear the buffers */
szGlobalBuffer[0] = '\0';
szBuffer[0] = '\0';

if (!PostMessage(hwndServer, WM_DDE_REQUEST, (WPARAM) hwndClient, PackDDElParam(WM_DDE_REQUEST, CF_TEXT, aItem)))
	{
   MessageBox (hwndClient, "Cannot communicate with ZEMAX!", "Hello?", MB_ICONEXCLAMATION | MB_OK);
   GlobalDeleteAtom(aItem);
   return -1;
   }

WaitForData(hwndClient);
strcpy(szBuffer, szGlobalBuffer);

if (GotData) return 0;
else return -1;
}

int PostArrayTraceMessage(char *szBuffer, DDERAYDATA *RD)
{
ATOM aItem;
HGLOBAL hPokeData;
DDEPOKE * lpPokeData;
long numbytes;
int numrays;


if (RD[0].opd > 4)
	{
	/* NSC Rays */
	numrays = (int)RD[0].opd - 5;
	}
else
	{
	/* sequential rays */
	numrays = RD[0].error;
	}

/* point to where the data is */
rdpGRD = RD;
ngNumRays = numrays;

numbytes = (1+numrays)*sizeof(DDERAYDATA);
hPokeData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (LONG) sizeof(DDEPOKE) + numbytes);
lpPokeData = (DDEPOKE *) GlobalLock(hPokeData);
lpPokeData->fRelease = TRUE;
lpPokeData->cfFormat = CF_TEXT;
memcpy(lpPokeData->Value, RD, numbytes);

/* clear the buffers */
szGlobalBuffer[0] = '\0';
szBuffer[0] = '\0';

aItem = GlobalAddAtom("RayArrayData");
GlobalUnlock(hPokeData);
if (!PostMessage(hwndServer, WM_DDE_POKE, (WPARAM) hwndClient, PackDDElParam(WM_DDE_POKE, (UINT) hPokeData, aItem)))
	{
   MessageBox (hwndClient, "Cannot communicate with ZEMAX!", "Hello?", MB_ICONEXCLAMATION | MB_OK);
   GlobalDeleteAtom(aItem);
	GlobalFree(hPokeData);
   return -1;
   }
GlobalDeleteAtom(aItem);

WaitForData(hwndClient);
strcpy(szBuffer, szGlobalBuffer);

/* clear the pointer */
rdpGRD = NULL;

if (GotData) return 0;
else return -1;
}

void MakeEmptyWindow(int text, char *szAppName, char *szOptions)
{
char szOutputFile[260], szModuleName[260], szBuffer[5000];
FILE *output;

/* get the output file name */
GetString(szCommandLine, 2, szOutputFile);

/* get the module name */
GetModuleFileName(globalhInstance, szModuleName, 255);

if ((output = fopen(szOutputFile, "wt")) == NULL)
	{
   /* can't open the file!! */
   return;
   }

if (text)
	{
   fputs("System is invalid, cannot compute data.\n",output);
   fclose(output);
	/* create a text window. Note we pass back the filename, module name, and activesurf as a single setting parameter. */
   sprintf(szBuffer,"MakeTextWindow,\"%s\",\"%s\",\"%s\",%s", szOutputFile, szModuleName, szAppName, szOptions);
   PostRequestMessage(szBuffer, szBuffer);
   }
else
	{
   fputs("NOFRAME\n",output);
   fputs("TEXT \"System is invalid, cannot compute data.\" .1 .5\n",output);
   fclose(output);
   sprintf(szBuffer,"MakeGraphicWindow,\"%s\",\"%s\",\"%s\",1,%s", szOutputFile, szModuleName, szAppName, szOptions);
   PostRequestMessage(szBuffer, szBuffer);
   }
}

void CenterWindow(HWND hwnd)
{
RECT rect;
int newx, newy;
GetWindowRect(hwnd, &rect);
newx = (GetSystemMetrics(SM_CXSCREEN) - (rect.right  - rect.left))/2;
newy = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom -  rect.top))/2;
SetWindowPos(hwnd, HWND_TOP, newx, newy, 0, 0, SWP_NOSIZE);
}

void Get_2_5_10(double cmax, double *cscale)
{
int i;
double temp;
if (cmax <= 0)
	{
	*cscale = .00001;
	return;
	}
*cscale = log10(cmax);
i = 0;
for (; *cscale < 0; i--) *cscale = *cscale + 1;
for (; *cscale > 1; i++) *cscale = *cscale - 1;
temp = 10;
if (*cscale < log10(5.0)) temp = 5;
if (*cscale < log10(2.0)) temp = 2;
*cscale = temp * pow(10, (double) i );
}

void remove_quotes(char *s)
{
int i=0;
/* remove the first quote if it exists */
if (s[0] == '"')
	{
	while (s[i])
		{
		s[i] = s[i+1];
		i++;
		}
	}
/* remove the last quote if it exists */
if (strlen(s) > 0)
	{
	if (s[strlen(s)-1] == '"') s[strlen(s)-1] = '\0';
	}
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产美女在线精品| 欧美亚洲综合在线| 麻豆免费看一区二区三区| 亚洲福利一区二区三区| 亚洲一区二区三区国产| 亚洲国产一区二区视频| 亚洲国产成人av网| 婷婷综合五月天| 日韩电影免费在线观看网站| 亚洲成av人影院在线观看网| 五月综合激情婷婷六月色窝| 亚洲一区中文日韩| 日韩精品1区2区3区| 日韩成人av影视| 日本亚洲视频在线| 精品一区精品二区高清| 韩国三级电影一区二区| 成人美女视频在线看| www.成人在线| 欧洲视频一区二区| 欧美理论在线播放| 一区二区三区自拍| 亚洲一区二区精品久久av| 亚洲成在人线免费| 极品美女销魂一区二区三区 | 国产激情视频一区二区三区欧美| 国产一区二区三区视频在线播放| 国产成人在线观看| 91毛片在线观看| 欧美日韩一区在线| 精品日韩一区二区三区| 国产精品久久久久久久久久久免费看| 亚洲女爱视频在线| 免费xxxx性欧美18vr| 国产精品亚洲午夜一区二区三区| jlzzjlzz亚洲日本少妇| 欧美性生活大片视频| 日韩欧美的一区二区| 国产欧美日韩另类一区| 一级日本不卡的影视| 麻豆精品久久精品色综合| 国产成人午夜高潮毛片| 欧美综合亚洲图片综合区| 91精品国产色综合久久不卡电影 | 看电视剧不卡顿的网站| 丰满亚洲少妇av| 欧美视频一二三区| 久久久www成人免费毛片麻豆| 亚洲人成精品久久久久久| 日韩av中文字幕一区二区| 国产不卡免费视频| 欧美裸体bbwbbwbbw| 国产精品人人做人人爽人人添| 亚洲一区在线视频| 国产精品乡下勾搭老头1| 欧美四级电影在线观看| 久久精品视频在线免费观看| 一级特黄大欧美久久久| 国产成人精品免费网站| 欧美日韩三级视频| 中文字幕成人av| 看国产成人h片视频| 色婷婷一区二区| 久久精品网站免费观看| 日本v片在线高清不卡在线观看| 成人精品国产一区二区4080| 日韩一卡二卡三卡国产欧美| 亚洲欧美日韩国产另类专区 | 欧美电视剧在线看免费| 一区二区三区欧美视频| 懂色av噜噜一区二区三区av| 91精品欧美一区二区三区综合在| 中文字幕日韩一区二区| 国产自产v一区二区三区c| 欧美日韩国产另类一区| 1024成人网| 国产成人精品亚洲日本在线桃色 | 亚洲视频在线一区二区| 色偷偷88欧美精品久久久| 国产亚洲精品久| 日韩1区2区3区| 欧美视频在线一区二区三区| 中文字幕一区二区三区在线观看| 激情小说欧美图片| 欧美一区二视频| 午夜久久福利影院| 欧美日韩综合在线| 一级做a爱片久久| 日本韩国精品在线| 中文字幕日韩精品一区| 成人黄色片在线观看| 久久精品亚洲精品国产欧美| 精品一区中文字幕| 精品国产乱码久久久久久夜甘婷婷 | 日韩一级完整毛片| 日韩av电影免费观看高清完整版 | 日本不卡的三区四区五区| 欧美色图在线观看| 亚洲一区二区五区| 欧美在线视频全部完| 亚洲欧美一区二区三区国产精品| 成人精品视频一区二区三区尤物| 久久亚洲影视婷婷| 国产精品影视网| 久久久亚洲欧洲日产国码αv| 久久国产视频网| 精品国产亚洲一区二区三区在线观看| 日韩精品五月天| 欧美男生操女生| 免费在线观看成人| 精品久久免费看| 国产一区二区三区久久久| 久久久久久久久久看片| 国产91丝袜在线播放0| 日本一区二区久久| 99这里只有久久精品视频| 日本一区二区电影| 91麻豆免费观看| 一区二区三区精品视频| 欧美日韩另类国产亚洲欧美一级| 视频一区免费在线观看| 日韩精品一区二区三区四区| 国产在线日韩欧美| 国产精品天干天干在观线| 91免费精品国自产拍在线不卡| 一区二区三区日韩| 欧美一区二区三区啪啪| 7777精品伊人久久久大香线蕉完整版 | 亚洲美女淫视频| 欧美日韩精品一区二区天天拍小说 | 91精品国产综合久久福利| 韩国精品免费视频| 国产精品卡一卡二| 欧美性一区二区| 捆绑紧缚一区二区三区视频| 中文字幕不卡一区| 欧美亚洲一区二区三区四区| 久久精品国产精品亚洲精品| 国产欧美日韩激情| 欧洲亚洲精品在线| 激情五月婷婷综合| 亚洲欧美精品午睡沙发| 日韩午夜激情av| 国产成人免费视频网站| 亚洲电影视频在线| 久久无码av三级| 色激情天天射综合网| 毛片基地黄久久久久久天堂| 国产精品青草久久| 91麻豆精品国产自产在线| 国产高清精品在线| 亚洲国产日韩在线一区模特| 久久久久国产一区二区三区四区 | 亚洲男人电影天堂| 日韩欧美不卡一区| 91久久精品日日躁夜夜躁欧美| 免费成人美女在线观看.| 亚洲欧美怡红院| 欧美成人猛片aaaaaaa| av在线播放不卡| 蜜臀精品久久久久久蜜臀 | 亚洲一区二区三区激情| 日本一区二区三区在线观看| 欧美日韩一区二区在线观看 | 日韩欧美色综合网站| 91丝袜美腿高跟国产极品老师 | 国产精品乡下勾搭老头1| 首页综合国产亚洲丝袜| 国产精品毛片久久久久久| 日韩一级免费一区| 色猫猫国产区一区二在线视频| 国产一区二三区| 午夜精品在线看| 一区二区三区免费在线观看| 久久精品水蜜桃av综合天堂| 欧美一区二区三区影视| 色狠狠av一区二区三区| 成人av在线观| 国产做a爰片久久毛片| 日韩影院在线观看| 尤物视频一区二区| 国产精品萝li| 国产网站一区二区| 日韩欧美亚洲国产另类| 欧美色倩网站大全免费| 99v久久综合狠狠综合久久| 国产在线视频不卡二| 免费成人av在线| 日韩**一区毛片| 亚洲成人动漫av| 一区二区不卡在线播放| 亚洲美女少妇撒尿| 中文字幕亚洲不卡| 国产精品久久毛片a| 久久精品一区二区三区四区| 精品国产免费一区二区三区四区| 91.麻豆视频| 91精品一区二区三区久久久久久| 欧美在线观看18| 91国产视频在线观看|