📄 wizard.cpp
字号:
// Wizard.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "Wizard.h"
#include "math.h"
#include "keyselint.h"
#include "sectionsel.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//字体类型
#define ts_nil 0x00
#define ts_Bold 0x01
#define ts_Italic 0x02
#define ts_StrikeOut 0x04
#define ts_Underline 0x08
#define FONT_NUM 45
BYTE SymFonts[FONT_NUM] = {
49, 49, 49, 49, 49,
34, 49, 49, 49, 50,
34, 18, 18, 66, 34,
18, 34, 49, 18, 2,
49, 34,
49, 49, 49, 49, 49,
49, 49, 49, 49, 49,
49, 49, 49, 49,
49, 49, 49, 49, 49,
49, 49, 49, 49
};
BYTE CharSets[FONT_NUM] = {
134, 134, 134, 134, 134,
0, 0, 0, 134, 255,
0, 0, 255, 255, 0,
2, 134, 255, 0, 2,
134, 134,
134, 134, 134, 134, 134,
134, 134, 134, 134, 134,
134, 134, 134, 134,
134, 134, 134, 134, 134,
134, 134, 134, 134
};
char* FontNames[FONT_NUM+1] = {
"仿宋体", "黑体", "楷体", "宋体", "宋体繁体",
"Arial", "Courier", "Courier New","Fixedsys", "Modern",
"MS Sans Serif", "MS Serif", "Roman", "Script", "Small Fonts",
"Symbol", "System", "Terminal", "Times New Roman", "Wingdings",
"@Fixedsys", "@System",
"@仿宋体", "@黑体", "@楷体", "@宋体", "@宋体繁体",
//"昆仑仿宋", "昆仑细圆", "昆仑粗隶书", "昆仑楷体", "昆仑黑体",
"仿宋_GB2312","楷体_GB2312","隶书","幼圆","昆仑黑体",
"长城仿宋", "长城细圆", "长城粗隶书", "长城楷体",
"@仿宋_GB2312","@楷体_GB2312","@隶书","@幼圆","@昆仑黑体",
// "@昆仑仿宋", "@昆仑细圆", "@昆仑粗隶书", "@昆仑楷体", "@昆仑黑体",
"@长城仿宋", "@长城细圆", "@长城粗隶书", "@长城楷体",
""
};
class CExecute : public CObject
{
public:
void* m_ScriptParams;
public:
CExecute();
~CExecute();
HWND GetExeWnd();
void SetScriptParams(void* pParams);
void* GetScriptParams();
void ExecScript( void* pParam, int scriptIndex );
};
CExecute exeStatus;
CExecute::CExecute()
{
m_ScriptParams = NULL;
}
CExecute::~CExecute()
{
}
HWND CExecute::GetExeWnd()
{
HWND hWnd;
if( (hWnd=::FindWindow( "pingmei_explorer", NULL ) )== NULL )
{
ASSERT( 0 );
return 0;
}
return hWnd;
}
void CExecute::SetScriptParams(void* pParams)
{
if( pParams == NULL )
if( m_ScriptParams )
delete m_ScriptParams; //free string
m_ScriptParams = pParams;
}
void* CExecute::GetScriptParams()
{
return m_ScriptParams;
}
void CExecute::ExecScript( void* pParam, int scriptIndex )
{
SetScriptParams( pParam );
HWND hWnd = GetExeWnd();
::SendMessage( hWnd,WM_WIZARD_SCRIPT, (WPARAM)scriptIndex,0 );
}
//-------------------------------draw-------------------------------
void KVDrawLine( DRAWRECT* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_LINE );
}
void KVDrawRoundRect( DRAWRECT* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_ROUNDRECT );
}
void KVDrawEllipse( DRAWRECT* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_ELLIPSE );
}
void KVDrawRealBitmap( DRAWBITMAP* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_BITMAP );
}
void KVDrawPipe( DRAWPIPE* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_PIPE );
}
void KVDrawLabel( DRAWLABEL* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_LABEL );
}
void KVDrawMyButton( DRAWMYBUTTON* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_MYBUTTON );
}
void KVDrawPie( DRAWPIE* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_PIE );
}
void KVDrawPolyshape( DRAWPOLYSHAPE* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_POLYSHAPE );
}
void KVDrawAlarmWin( DRAWALARMWIN* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_ALARMWIN );
}
void KVDrawRTrend( DRAWRTREND* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_RTREND );
}
void KVDrawHTrend( DRAWHTREND* pDraw )
{
exeStatus.ExecScript( (void*)pDraw ,DRAW_HTREND );
}
//-------------------------------link--------------------------------
void KVLinkPen( LINKPEN* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_PEN );
}
void KVLinkBrush( LINKBRUSH* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_BRUSH );
}
void KVLinkTextColor( LINKTEXTCOLOR* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_TEXTCOLOR );
}
void KVLinkFill( LINKFILL* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_FILL );
}
void KVLinkSize( LINKSIZE* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_SIZE );
}
void KVLinkRotate( LINKROTATE* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_ROTATE );
}
void KVLinkHorShift( LINKHORSHIFT* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_HORSHIFT );
}
void KVLinkVerShift( LINKVERSHIFT* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_VERSHIFT );
}
void KVLinkAnalogIn( LINKANALOGIN* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_ANALOGIN );
}
void KVLinkDiscIn( LINKDISCIN* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_DISCIN );
}
void KVLinkTextIn(LINKTEXTIN* pLink)
{
exeStatus.ExecScript( (void*)pLink ,LINK_TEXTIN );
}
void KVLinkAnalogOut( LINKANALOGOUT* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_ANALOGOUT );
}
void KVLinkDiscOut( LINKDISCOUT* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_DISCOUT );
}
/*
void KVLinkTextOut( char* szText )
{
exeStatus.ExecScript( (void*)szText ,LINK_TEXTOUT );
}
*/
void KVLinkTextOut( LINKTEXTOUT* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_TEXTOUT );
}
void KVLinkBlink( LINKBLINK* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_BLINK );
}
void KVLinkHide( LINKHIDE* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_HIDE );
}
void KVLinkAction( LINKACTION* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_ACTION );
}
void KVLinkVerShiftIn( LINKVERSHIFT* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_VERSHIFTIN );
}
void KVLinkHorShiftIn( LINKHORSHIFT* pLink )
{
exeStatus.ExecScript( (void*)pLink ,LINK_HORSHIFTIN );
}
//-------------------------------resource----------------------------
void KVUseTagnameDlg( HWND hDialog, void** ppTagName )
{
exeStatus.SetScriptParams( *ppTagName );
::SendMessage( exeStatus.GetExeWnd(), WM_WIZARD_SCRIPT,USE_TAGNAME,(LPARAM)hDialog );
int nStrLen = strlen( (char*)(exeStatus.GetScriptParams()) ) +1;
*ppTagName = CoTaskMemRealloc((void*)(*ppTagName), nStrLen );
strcpy( (char*)(*ppTagName), (char*)exeStatus.GetScriptParams() );
exeStatus.SetScriptParams( NULL ); //free string;
}
void KVUseProgramDlg( HWND hDialog, void** ppProgram )
{
exeStatus.SetScriptParams( *ppProgram );
::SendMessage( exeStatus.GetExeWnd(), WM_WIZARD_SCRIPT,USE_PROGRAM,(LPARAM)hDialog );
int nStrLen = strlen( (char*)(exeStatus.GetScriptParams()) ) +1;
*ppProgram = CoTaskMemRealloc((void*)(*ppProgram), nStrLen );
strcpy( (char*)(*ppProgram), (char*)exeStatus.GetScriptParams() );
exeStatus.SetScriptParams( NULL ); //free string;
}
CSize KVGetLabelMetric( LABELMETRIC* pLabelMetric )
{
HWND hWnd = exeStatus.GetExeWnd();
HDC hDC = ::GetDC( hWnd );
LOGFONT font;
font.lfHeight = (-1)* pLabelMetric->textPenFontHeight;
font.lfWidth = pLabelMetric->textPenFontWidth;
if( pLabelMetric->textPenFontStyle & ts_Bold )
font.lfWeight = FW_BOLD;
else
font.lfWeight = FW_NORMAL;
if( pLabelMetric->textPenFontStyle & ts_Italic )
font.lfItalic = 1;
else
font.lfItalic = 0;
font.lfUnderline =0;
font.lfStrikeOut = 0;
font.lfEscapement = 0;
font.lfOrientation = 0;
font.lfCharSet = CharSets[pLabelMetric->textPenFontIndex];
font.lfOutPrecision = OUT_STROKE_PRECIS;
font.lfClipPrecision = CLIP_STROKE_PRECIS;
font.lfQuality = DRAFT_QUALITY;
font.lfPitchAndFamily = SymFonts[pLabelMetric->textPenFontIndex];
strcpy( font.lfFaceName, FontNames[pLabelMetric->textPenFontIndex] );
HFONT hFont = ::CreateFontIndirect(&font);
HFONT hOldFont = (HFONT)::SelectObject( hDC, hFont );
CSize labelSize;
::GetTextExtentPoint32( hDC,pLabelMetric->pLabel,strlen( pLabelMetric->pLabel ),&labelSize );
::SelectObject( hDC,hOldFont );
::ReleaseDC( hWnd,hDC );
return labelSize;
}
void KVNewTag( HWND hDialog,int nType,char* szTagname )
{
// exeStatus.SetScriptParams( szTagname );
// ::SendMessage( exeStatus.GetExeWnd(), WM_WIZARD_NEWTAG,(WPARAM)nType,0 );
}
//---------------------------Params------------------------------
//__declspec(dllexport) void
void PASCAL EXPORT KVGetParams(void** ppParams,char* pResult)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if( pResult )
{
int nLen = strlen( pResult );
char* pStr = new char[nLen+1]; //Alloc string
strcpy( pStr, pResult );
pStr[nLen] = '\0';
exeStatus.SetScriptParams( (void*)pStr );
}
else
*ppParams = exeStatus.GetScriptParams();
}
CString GetTag( HWND hWnd,CString oldTag,short nShowType /*= SHOW_ALL*/ )
{
CString newTag;
short nLen = oldTag.GetLength() + 1;
void** ppVoid = new void*;
*ppVoid = CoTaskMemAlloc( sizeof( nLen ) + nLen + sizeof( nShowType ) );
LPTSTR pTag = oldTag.LockBuffer();
memcpy( *ppVoid, &nLen, sizeof( nLen ) );
memcpy( ((BYTE*)*ppVoid) + sizeof( nLen ), pTag, nLen );
memcpy( ((BYTE*)*ppVoid)+ sizeof( nLen )+nLen, &nShowType, sizeof( nShowType ) );
oldTag.UnlockBuffer();
KVUseTagnameDlg( hWnd,ppVoid );
newTag = (char*)(*ppVoid);
CoTaskMemFree( *ppVoid );
delete ppVoid;
return newTag;
}
BOOL CheckTagType( HWND hWnd, CString strTag, int nType )
{
int nLen = strTag.GetLength() + 1;
void * pvTag = ::CoTaskMemAlloc( nLen );
LPTSTR pTag = strTag.LockBuffer();
memcpy( pvTag, pTag, nLen );
strTag.UnlockBuffer();
void * pvType = ::CoTaskMemAlloc( 2 * sizeof( int ) );
memcpy( pvType, &nType, sizeof( nType ) );
memcpy( ((BYTE*)pvType)+sizeof( nType ), &hWnd, sizeof( hWnd ) );
HWND hwndMak;
if( (hwndMak=::FindWindow( "pingmei_explorer", NULL ) )== NULL )
{
ASSERT( 0 );
return FALSE ;
}
BOOL bRet = ::SendMessage(hwndMak,WM_CHECK_TAG,(WPARAM)pvTag,(LPARAM)pvType);
CoTaskMemFree( pvTag );
CoTaskMemFree( pvType );
return bRet ;
}
CString GetProgram( HWND hWnd,CString oldProgram )
{
CString newProgram;
int nLen = oldProgram.GetLength() + 1;
void** ppVoid = new void*;
*ppVoid = CoTaskMemAlloc( nLen );
LPTSTR pProg = oldProgram.LockBuffer();
memcpy( *ppVoid, pProg, nLen );
oldProgram.UnlockBuffer();
KVUseProgramDlg( hWnd,ppVoid );
newProgram = (char*)(*ppVoid);
CoTaskMemFree( *ppVoid );
delete ppVoid;
return newProgram;
}
BOOL KVGetHotKey( HWND hWnd,UINT* pKeyCode,char* pszKeyText )
{
ASSERT( pKeyCode );
ASSERT( pszKeyText );
BOOL bOK = FALSE;
HRESULT hRes = CoInitialize(NULL);
_ASSERTE(SUCCEEDED(hRes));
IKeySel* pKeySel = NULL;
HRESULT hr = ::CoCreateInstance(CLSID_KeySel, NULL, CLSCTX_ALL, IID_IKeySel,(void**)&pKeySel);
if(SUCCEEDED(hr))
{
pKeySel->GetKeyCodeName( hWnd, pKeyCode, pszKeyText );
pKeySel->Release();
bOK = TRUE;
}
else
{
bOK = FALSE;
}
CoUninitialize();
return bOK;
}
BOOL KVGetSection( HWND hWnd,LONGLONG * pnSection )
{
ASSERT( pnSection );
BOOL bOK = FALSE;
HRESULT hRes = CoInitialize(NULL);
_ASSERTE(SUCCEEDED(hRes));
ISectionSel* pSectionSel = NULL;
HRESULT hr = ::CoCreateInstance(CLSID_SectionSel, NULL, CLSCTX_ALL, IID_ISectionSel,(void**)&pSectionSel);
if(SUCCEEDED(hr))
{
pSectionSel->GetSectionCode( hWnd, pnSection );
pSectionSel->Release();
bOK = TRUE;
}
else
{
bOK = FALSE;
}
CoUninitialize();
return bOK;
}
BOOL KVGetSectionNameByCode( LONGLONG nSectionCode,CString & strSectionName )
{
BOOL bOK = FALSE;
HRESULT hRes = CoInitialize(NULL);
_ASSERTE(SUCCEEDED(hRes));
ISectionSel* pSectionSel = NULL;
HRESULT hr = ::CoCreateInstance(CLSID_SectionSel, NULL, CLSCTX_ALL, IID_ISectionSel,(void**)&pSectionSel);
if(SUCCEEDED(hr))
{
BSTR bstrSectionName = NULL ;
pSectionSel->GetSectionNameByCode( nSectionCode, &bstrSectionName );
pSectionSel->Release();
bOK = TRUE;
strSectionName = bstrSectionName ;
::CoTaskMemFree( bstrSectionName ) ;
}
else
{
bOK = FALSE;
strSectionName.Empty() ;
}
CoUninitialize();
return bOK;
}
BOOL KVGetKeyNameByCode( UINT nKeyCode,char* szKeyName )
{
ASSERT( szKeyName );
BOOL bOK = FALSE;
HRESULT hRes = CoInitialize(NULL);
_ASSERTE(SUCCEEDED(hRes));
IKeySel* pKeySel = NULL;
HRESULT hr = ::CoCreateInstance(CLSID_KeySel, NULL, CLSCTX_ALL, IID_IKeySel,(void**)&pKeySel);
if(SUCCEEDED(hr))
{
pKeySel->GetKeyNameByCode( nKeyCode, szKeyName );
pKeySel->Release();
bOK = TRUE;
}
else
{
bOK = FALSE;
}
CoUninitialize();
return bOK;
}
//建立历史趋势曲线变量
//return:
// HTREND_TAG_SUCC 1 //建立历史趋势曲线变量成功
// HTREND_DICT_FULL -1 //建立失败:数据库变量已满
// HTREND_SAVE_FAIL -2 //建立失败:数据库存盘失败
int KVNewHTrendTag(char* pName, short nUseCount)
{
exeStatus.SetScriptParams( pName );
WPARAM wParam = WPARAM( nUseCount ) ;
::SendMessage( exeStatus.GetExeWnd(), WM_WIZARD_NEWTAG,wParam,0);
BYTE* pRet = (BYTE*)exeStatus.GetScriptParams();
int nRet = *pRet;
exeStatus.SetScriptParams( NULL ); //free string;
return nRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -