📄 acdclnt.c
字号:
// Try (or retry) to get the LINEAGENTACTIVITYLIST information
//
EnterCriticalSection(&csLineReply);
glResult = lineGetAgentActivityList(hLine,
dwAddressID,
pLineAgentActivityList);
if (glResult < 0)
{
LeaveCriticalSection(&csLineReply);
bError = TRUE;
//error
}
else if (WaitForLineReply())
{
bError = TRUE;
//error
}
if (bError)
{
GlobalFree((HLOCAL)pLineAgentActivityList);
return NULL;
}
// If the currently allocated LINEAGENTACTIVITYLIST memory block was big
// enough, we're all done, else we need to realloc the memory block
// and try again.
//
if (pLineAgentActivityList->dwNeededSize <= dwMaxNeededSize)
{
return pLineAgentActivityList;
}
else
{
dwMaxNeededSize = pLineAgentActivityList->dwNeededSize;
pLineAgentActivityList = GlobalReAlloc((HLOCAL)pLineAgentActivityList,
dwMaxNeededSize,
GMEM_MOVEABLE);
}
}
}
///////////////////////////////////////////////////////////////////////////////
//
// LineGetAddressCaps()
//
///////////////////////////////////////////////////////////////////////////////
LINEADDRESSCAPS * LineGetAddressCaps (HLINEAPP hLineApp,
DWORD dwDeviceID,
DWORD dwAddressID)
{
LONG lRetVal;
LINEADDRESSCAPS * pLineAddressCaps;
static DWORD dwMaxNeededSize = sizeof(LINEADDRESSCAPS);
// Allocate an initial block of memory for the LINEADDRESSCAPS structure,
// which may or may not be big enough to hold all of the information.
//
pLineAddressCaps = GlobalAlloc(GPTR, dwMaxNeededSize);
for (;;)
{
if (pLineAddressCaps == NULL)
{
return NULL;
}
pLineAddressCaps->dwTotalSize = dwMaxNeededSize;
// Try (or retry) to get the LINEADDRESSCAPS information
//
lRetVal = lineGetAddressCaps(hLineApp,
dwDeviceID,
dwAddressID,
TAPI_CURRENT_VERSION,
0,
pLineAddressCaps);
if (lRetVal < 0)
{
GlobalFree((HLOCAL)pLineAddressCaps);
return NULL;
}
// If the currently allocated LINEADDRESSCAPS memory block was big
// enough, we're all done, else we need to realloc the memory block
// and try again.
//
if (pLineAddressCaps->dwNeededSize <= dwMaxNeededSize)
{
return pLineAddressCaps;
}
else
{
dwMaxNeededSize = pLineAddressCaps->dwNeededSize;
pLineAddressCaps = GlobalReAlloc((HLOCAL)pLineAddressCaps,
dwMaxNeededSize,
GMEM_MOVEABLE);
}
}
}
///////////////////////////////////////////////////////////////////////////////
//
// LineGetCallInfo()
//
///////////////////////////////////////////////////////////////////////////////
LINECALLINFO * LineGetCallInfo (HCALL hCall)
{
LONG lRetVal;
LINECALLINFO * pLineCallInfo;
static DWORD dwMaxNeededSize = sizeof(LINECALLINFO);
// Allocate an initial block of memory for the LINECALLINFO structure,
// which may or may not be big enough to hold all of the information.
//
pLineCallInfo = GlobalAlloc(GPTR, dwMaxNeededSize);
for (;;)
{
if (pLineCallInfo == NULL)
{
return NULL;
}
pLineCallInfo->dwTotalSize = dwMaxNeededSize;
// Try (or retry) to get the LINECALLINFO information
//
lRetVal = lineGetCallInfo(hCall,
pLineCallInfo);
if (lRetVal < 0)
{
GlobalFree((HLOCAL)pLineCallInfo);
return NULL;
}
// If the currently allocated LINECALLINFO memory block was big
// enough, we're all done, else we need to realloc the memory block
// and try again.
//
if (pLineCallInfo->dwNeededSize <= dwMaxNeededSize)
{
return pLineCallInfo;
}
else
{
dwMaxNeededSize = pLineCallInfo->dwNeededSize;
pLineCallInfo = GlobalReAlloc((HLOCAL)pLineCallInfo,
dwMaxNeededSize,
GMEM_MOVEABLE);
}
}
}
///////////////////////////////////////////////////////////////////////////////
//
// LineGetDevCaps()
//
///////////////////////////////////////////////////////////////////////////////
LINEDEVCAPS * LineGetDevCaps (HLINEAPP hLineApp,
DWORD dwDeviceID)
{
LONG lRetVal;
LINEDEVCAPS * pLineDevCaps;
static DWORD dwMaxNeededSize = sizeof(LINEDEVCAPS);
pLineDevCaps = GlobalAlloc(GPTR, dwMaxNeededSize);
for (;;)
{
if (pLineDevCaps == NULL)
{
return NULL;
}
pLineDevCaps->dwTotalSize = dwMaxNeededSize;
lRetVal = lineGetDevCaps(hLineApp,
dwDeviceID,
TAPI_CURRENT_VERSION,
0,
pLineDevCaps);
if (lRetVal < 0)
{
GlobalFree((HLOCAL)pLineDevCaps);
return NULL;
}
if (pLineDevCaps->dwNeededSize <= dwMaxNeededSize)
{
return pLineDevCaps;
}
else
{
dwMaxNeededSize = pLineDevCaps->dwNeededSize;
pLineDevCaps = GlobalReAlloc((HLOCAL)pLineDevCaps,
dwMaxNeededSize,
GMEM_MOVEABLE);
}
}
}
///////////////////////////////////////////////////////////////////////////////
//
// LineGetID()
//
///////////////////////////////////////////////////////////////////////////////
VARSTRING * LineGetID (HLINE hLine,
DWORD dwAddressID,
HCALL hCall,
DWORD dwSelect,
LPCTSTR lpszDeviceClass)
{
LONG lRetVal;
VARSTRING * pVarString;
static DWORD dwMaxNeededSize = sizeof(VARSTRING);
// Allocate an initial block of memory for the VARSTRING structure,
// which may or may not be big enough to hold all of the information.
//
pVarString = GlobalAlloc(GPTR, dwMaxNeededSize);
for (;;)
{
if (pVarString == NULL)
{
return NULL;
}
pVarString->dwTotalSize = dwMaxNeededSize;
// Try (or retry) to get the VARSTRING information
//
lRetVal = lineGetID(hLine,
dwAddressID,
hCall,
dwSelect,
pVarString,
lpszDeviceClass);
if (lRetVal < 0)
{
GlobalFree((HLOCAL)pVarString);
return NULL;
}
// If the currently allocated VARSTRING memory block was big
// enough, we're all done, else we need to realloc the memory block
// and try again.
//
if (pVarString->dwNeededSize <= dwMaxNeededSize)
{
return pVarString;
}
else
{
dwMaxNeededSize = pVarString->dwNeededSize;
pVarString = GlobalReAlloc((HLOCAL)pVarString,
dwMaxNeededSize,
GMEM_MOVEABLE);
}
}
}
///////////////////////////////////////////////////////////////////////////////
//
// LineGetCallStatus()
//
///////////////////////////////////////////////////////////////////////////////
LINECALLSTATUS * LineGetCallStatus (HCALL hCall)
{
LONG lRetVal;
LINECALLSTATUS * pLineCallStatus;
static DWORD dwMaxNeededSize = sizeof(LINECALLSTATUS);
// Allocate an initial block of memory for the LINECALLSTATUS structure,
// which may or may not be big enough to hold all of the information.
//
pLineCallStatus = GlobalAlloc(GPTR, dwMaxNeededSize);
while (TRUE)
{
if (pLineCallStatus == NULL)
{
return NULL;
}
pLineCallStatus->dwTotalSize = dwMaxNeededSize;
// Try (or retry) to get the LINECALLSTATUS information
//
lRetVal = lineGetCallStatus(hCall,
pLineCallStatus);
if (lRetVal < 0)
{
GlobalFree((HLOCAL)pLineCallStatus);
return NULL;
}
// If the currently allocated LINECALLSTATUS memory block was big
// enough, we're all done, else we need to realloc the memory block
// and try again.
//
if (pLineCallStatus->dwNeededSize <= dwMaxNeededSize)
{
return pLineCallStatus;
}
else
{
dwMaxNeededSize = pLineCallStatus->dwNeededSize;
pLineCallStatus = GlobalReAlloc((HLOCAL)pLineCallStatus,
dwMaxNeededSize,
GMEM_MOVEABLE);
}
}
}
////////////////////////////////////////////////////////////////////////////
//
//
// constants for creating buttons in the main window
//
#define YSTART 8
#define XSTART 8
#define STATICX 57
#define BUTTONX 50
#define BUTTONGAP 20
#define BUTTONY 14
#define LINEGAP 8
/////////////////////////////////////////////////////////////////////////////
//
// BOOL RedoWindow()
//
// Creates the buttons and static controls in the main window
// For each address on the line, create a static control with the name off
// the address, a button to get/set status, and a button to answer/drop
//
// Right now, this should only be done when the app is starting. It does
// not check to see if pAddressInfo has already been allocated
//
/////////////////////////////////////////////////////////////////////////////
BOOL RedoWindow()
{
DWORD dwAddress;
LPLINEADDRESSCAPS pLAC;
TCHAR szBuffer[64];
LONG lBaseUnits, lxbase, lybase;
HFONT hFont;
HWND hWnd;
int x,y,w,h,xstart,ystart,buttonx,buttony,staticx,buttongap,linegap;
// alloc for address info
pAddressInfo = (PADDRESSINFO)GlobalAlloc(GPTR, sizeof(ADDRESSINFO) * gdwAddresses);
if (!pAddressInfo)
{
return FALSE;
}
// get conversions
lBaseUnits = GetDialogBaseUnits();
lxbase = (LONG)LOWORD(lBaseUnits);
lybase = (LONG)HIWORD(lBaseUnits);
// convert dialog units to pixels
xstart = (XSTART * lxbase) / 4;
ystart = (YSTART * lybase) / 8;
buttonx = (BUTTONX * lxbase) / 4;
buttony = (BUTTONY * lybase) / 8;
staticx = (STATICX * lxbase) / 4;
buttongap = (BUTTONGAP * lxbase) / 4;
linegap = (LINEGAP * lybase) / 8;
// init
x = xstart;
y = ystart;
w = buttonx;
h = buttony;
// get the font used by the static control
hFont = (HFONT)SendDlgItemMessage(ghMainWnd,
IDC_STATIC1,
WM_GETFONT,
0,
0);
// loop through all addressed
for (dwAddress = 0; dwAddress < gdwAddresses; dwAddress++)
{
// get the name of the address
pLAC = LineGetAddressCaps(ghLineApp,
gdwDeviceID,
dwAddress);
if (!pLAC || !pLAC->dwAddressSize)
{
wsprintf(szBuffer,
TEXT("Address %lu"),
dwAddress);
}
else
{
lstrcpy(szBuffer,
(LPTSTR)(((LPBYTE)pLAC)+pLAC->dwAddressOffset));
}
if (pLAC)
{
GlobalFree(pLAC);
}
w = staticx;
x = xstart;
// create the static control
hWnd = CreateWindow(TEXT("STATIC"),
szBuffer,
WS_CHILD | SS_LEFT | WS_VISIBLE,
x,y+(buttony/3),w,h,
ghMainWnd,
NULL,
ghInstance,
NULL);
// set the font
SendMessage(hWnd,
WM_SETFONT,
(WPARAM)hFont,
0);
x += staticx;
w = buttonx;
// create the status button
pAddressInfo[dwAddress].hStatus = CreateWindow(TEXT("BUTTON"),
TEXT("Set Status..."),
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
x,y,w,h,
ghMainWnd,
NULL,
ghInstance,
NULL);
// set the font
SendMessage(pAddressInfo[dwAddress].hStatus,
WM_SETFONT,
(WPARAM)hFont,
0);
x += buttonx + buttongap;
// create the answer/drop button
pAddressInfo[dwAddress].hAnswer = CreateWindow(TEXT("BUTTON"),
TEXT("Answer"),
WS_CHILD | WS_DISABLED | BS_PUSHBUTTON | WS_VISIBLE,
x,y,w,h,
ghMainWnd,
NULL,
ghInstance,
NULL);
// set the font
SendMessage(pAddressInfo[dwAddress].hAnswer,
WM_SETFONT,
(WPARAM)hFont,
0);
y += buttony + linegap;
}
// adjust position of message static control
SetWindowPos(GetDlgItem(ghMainWnd,
IDC_STATIC1),
NULL,
xstart,y,0,0,
SWP_NOZORDER | SWP_NOSIZE);
// adjust the size of th main window
SetWindowPos(ghMainWnd,
NULL,
0,0,xstart+staticx+buttonx+buttonx+buttongap+50,y+50,
SWP_NOZORDER | SWP_NOMOVE);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -