📄 progman.cpp
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
These sources, libraries and applications are
FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
as long as the following conditions are adhered to.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*____________________________________________________________________________*|
*
* $Source: /cvsroot/pi3web/Pi3Web_200/Source/EnhPi3/ProgMan.cpp,v $
* $Date: 2003/05/13 18:41:59 $
*
Description:
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <assert.h>
#include <windows.h>
#include "ProgMan.h"
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
const char _szClassName[] = "DDEClient";
const char _szProgman[] = "PROGMAN";
extern HINSTANCE __hInstance;
static HWND __hWndDDEClient = 0;
static HWND __hWndDDEServer = 0;
#define WM_INTERNAL (WM_USER+37)
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
LRESULT CALLBACK DDEClientWndProc( HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam )
{
switch( uMsg )
{
case WM_CREATE:
SendMessage( (HWND)-1, WM_DDE_INITIATE, (WPARAM)hWnd,
(LPARAM)(((LPCREATESTRUCT)lParam)->lpCreateParams) );
if ( !__hWndDDEServer )
{ /* error */ return -1; };
break;
case WM_DDE_DATA:
if ( __hWndDDEServer!=(HWND)wParam )
{
if ( HIWORD( lParam )!=NULL )
{ ::GlobalFree( (HGLOBAL)HIWORD( lParam ) ); };
::GlobalDeleteAtom( LOWORD( lParam ) );
};
break;
case WM_DDE_TERMINATE:
if ( !__hWndDDEServer ) { break; };
::PostMessage( __hWndDDEServer, WM_DDE_TERMINATE, (WPARAM)hWnd, 0 );
__hWndDDEServer = 0;
break;
case WM_DDE_ACK:
if ( !__hWndDDEServer )
{ __hWndDDEServer = (HWND)wParam; }
else
{ ::PostMessage( (HWND)wParam, WM_DDE_TERMINATE, (WPARAM)hWnd, 0 ); };
break;
case WM_DESTROY:
::PostMessage( __hWndDDEServer, WM_DDE_TERMINATE, (WPARAM)hWnd, 0 );
__hWndDDEServer = 0;
break;
case WM_INTERNAL:
{
MSG tMsg;
if ( !__hWndDDEServer ) { break; };
::PostMessage( __hWndDDEServer, WM_DDE_EXECUTE, (WPARAM)hWnd, lParam );
::GetMessage( &tMsg, hWnd, WM_DDE_ACK, WM_DDE_ACK );
wParam = LOWORD( tMsg.lParam );
return ((DDEACK *)&wParam)->fAck;
};
break;
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
};
return (LRESULT)0;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
BOOL WINAPI Internal_RegisterDDEClient( HINSTANCE hInstance )
{
WNDCLASS wc;
memset( &wc, 0, sizeof( WNDCLASS ) );
wc.lpfnWndProc = DDEClientWndProc;
wc.hInstance = hInstance;
wc.lpszClassName = _szClassName;
return ::RegisterClass( &wc );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
BOOL WINAPI Internal_UnregisterDDEClient( HINSTANCE hInstance )
{
return ::UnregisterClass( _szClassName, hInstance );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
int PM_openConnection()
{
Internal_RegisterDDEClient( __hInstance );
ATOM aApp = ::GlobalAddAtom( _szProgman );
ATOM aTopic = ::GlobalAddAtom( _szProgman );
__hWndDDEClient = ::CreateWindow( "DDEClient", "", 0, 0, 0, 0, 0,
NULL, NULL, __hInstance, (void *)MAKELONG( aApp, aTopic ) );
if ( !__hWndDDEClient )
{ return 0; };
::GlobalDeleteAtom( aApp );
::GlobalDeleteAtom( aTopic );
return 1;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
int PM_closeConnection()
{
if ( !__hWndDDEClient )
{ return 0; };
::DestroyWindow( __hWndDDEClient );
Internal_UnregisterDDEClient( __hInstance );
__hWndDDEServer = 0;
__hWndDDEClient = 0;
return 1;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
int Internal_groupAction( const char *pAction, const char *pName )
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
wsprintf( szBuf, "[%s(%s)]", pAction, pName );
HGLOBAL hG = ::GlobalAlloc( GMEM_MOVEABLE | GMEM_DDESHARE,
strlen( szBuf ) + 1 );
char *pLocked = (char *)::GlobalLock( hG );
strcpy( pLocked, szBuf );
::GlobalUnlock( hG );
LRESULT lRet = SendMessage( __hWndDDEClient, WM_INTERNAL, 0, (LPARAM)hG );
::GlobalFree( hG );
return 1;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
int PM_addGroup( const char *pName )
{
return Internal_groupAction( "CreateGroup", pName );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
int PM_deleteGroup( const char *pName )
{
return Internal_groupAction( "DeleteGroup", pName );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
int PM_addItem( const char *pName, const char *pCmd, const char *pIconPath,
int iIconIndex, int iX, int iY, const char *pWorking )
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
wsprintf( szBuf, "[AddItem(%s,%s,%s,%d,%d,%d,\"%s\")]",
pCmd,
pName,
pIconPath,
iIconIndex,
iX,
iY,
pWorking
);
HGLOBAL hG = ::GlobalAlloc( GMEM_MOVEABLE | GMEM_DDESHARE,
strlen( szBuf ) + 1 );
char *pLocked = (char *)::GlobalLock( hG );
strcpy( pLocked, szBuf );
::GlobalUnlock( hG );
LRESULT lRet = SendMessage( __hWndDDEClient, WM_INTERNAL, 0, (LPARAM)hG );
::GlobalFree( hG );
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -