📄 fdemo.c
字号:
Button_Enable(GetDlgItem(hwnd, IDC_IOTTDEL), (i > 0));
Button_Enable(GetDlgItem(hwnd, IDC_IOTTADD), (i < MAXFILE));
}
/************************************************************
* NAME: FileOpenHookProc
* DESCRIPTION: Process our controls in Common FileOpen Dialog Box
* NOTES: This routine is called from within GetOpenFileName()
* common dialog processing. It is an extension to the
* common OpenFile dialog.
************************************************************/
UINT WINAPI FileOpenHookProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
{
int nSelCount;
int nSelIndex[MAXFILE];
int i,ofs;
char szBuff[MAXFILELEN];
switch (msg) {
case WM_INITDIALOG:
// add any files already selected
for (i=0;i<lpSendFileList->count;i++) {
ListBox_AddString(GetDlgItem(hwnd, IDC_IOTTLIST), lpSendFileList->filename[i]);
}
// update add/delete button states
FileOpenButtonUpdate(hwnd);
return TRUE;
case WM_COMMAND:
if (((LOWORD(wParam) == lst1) && (HIWORD(wParam) == LBN_DBLCLK)) ||
(LOWORD(wParam) == IDC_IOTTADD)) {
// user double clicked in file listbox, hit Add button, or
// hit enter in file name edit control
// get selected items, if any or update listbox
if ((nSelCount = ListBox_GetSelItems(GetDlgItem(hwnd, lst1), MAXFILE, nSelIndex)) <= 0) {
// no files selected in listbox, check edit control
if (GetFocus() == GetDlgItem(hwnd, edt1)) {
}
return TRUE;
}
// limit number of files in IOTTLIST to MAXFILE
i = ListBox_GetCount(GetDlgItem(hwnd, IDC_IOTTLIST));
if (i+nSelCount > MAXFILE) {
nSelCount = MAXFILE - i;
}
if (nSelCount <= 0) {
MessageBeep(MB_ICONASTERISK);
Button_Enable(GetDlgItem(hwnd, IDC_IOTTADD), FALSE);
return(TRUE);
}
// build fully qualified pathname for the file and add to the listbox
szBuff[0]=0;
GetCurrentDirectory(MAXFILELEN, szBuff);
// verify that it ends with a backslash
if (szBuff[strlen(szBuff)-1] != '\\') {
strcat(szBuff,"\\");
}
ofs = strlen(szBuff);
// cycle thru array of selected items, adding them to IOTT listbox
for (i=0;i<nSelCount;i++) {
ListBox_GetText(GetDlgItem(hwnd, lst1), nSelIndex[i], &szBuff[ofs]);
ListBox_AddString(GetDlgItem(hwnd, IDC_IOTTLIST), szBuff);
}
// update add/delete button states
FileOpenButtonUpdate(hwnd);
return TRUE;
}
if (LOWORD(wParam) == IDC_IOTTDEL) {
// remove any selected items in IOTT listbox
if ((nSelCount = ListBox_GetSelItems(GetDlgItem(hwnd, IDC_IOTTLIST), MAXFILE, nSelIndex)) <= 0) {
return TRUE;
}
// cycle thru array of selected items, deleting them to IOTT listbox
for (i=nSelCount-1;i>=0;i--) {
ListBox_DeleteString(GetDlgItem(hwnd, IDC_IOTTLIST), nSelIndex[i]);
}
// update add/delete button states
FileOpenButtonUpdate(hwnd);
return TRUE;
}
if (wParam == IDOK) {
// user finished selecting text, reset listbox so GetOpenFileName()
// doesn't return list of files in ofn.szFile
ListBox_SetSel(GetDlgItem(hwnd, lst1), FALSE, -1);
// copy entries in IOTT listbox to global buffer so we have
// access to them in Sendfax()
if ((nSelCount = ListBox_GetCount(GetDlgItem(hwnd, IDC_IOTTLIST))) <=0) {
// no files were selected, or error occurred, clear global pointer
// and exit
break;
}
// send up to 8 files
if (nSelCount >MAXFILE) {
nSelCount = MAXFILE;
}
// init structure with count, filenames
ZeroMemory(lpSendFileList, sizeof(SENDFILELIST));
lpSendFileList->count = nSelCount;
for (i=0;i<nSelCount;i++) {
ListBox_GetText(GetDlgItem(hwnd, IDC_IOTTLIST), i, lpSendFileList->filename[i]);
}
break;
}
break;
}
return FALSE;
}
/************************************************************
* NAME: SendDialDlgProc()
* DESCRIPTION: Prompt user for files and number and start send fax process
************************************************************/
BOOL WINAPI SendDialDlgProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
{
static LPDEVDATA lpDevData; // static pointer used thru life of dialog
HWND hwndCtl;
int i, j, fh;
char *extp;
static char szBuff[80]; // static for name of GetOpenFileName
switch (msg) {
case WM_INITDIALOG:
// Initialize fields in dialog
if ((lpDevData = GetDevPtr((HWND) lParam)) == NULL) {
// This is an error condition
return TRUE;
}
SetWindowContextHelpId(hwnd, IDD_SENDDIAL);
// reset status message buffer
lpDevData->winbuff[0] = 0;
// clear and init common file open dialog structure
// done only 1 time
ZeroMemory(&ofn,sizeof(OPENFILENAME));
strcpy(szFile, "*.tif");
sprintf(szBuff, "Send Fax on %s", lpDevData->devname);
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwndClient;
ofn.hInstance = hInst;
ofn.lpstrTitle = szBuff;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpTemplateName = MAKEINTRESOURCE(MULTIFILEOPENORD);
ofn.lpfnHook = FileOpenHookProc;
ofn.Flags = OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY | OFN_NONETWORKBUTTON |
OFN_ENABLETEMPLATE | OFN_ENABLEHOOK |
OFN_NOCHANGEDIR;
// init global data structure, used by FileOpenHookProc, to sendfilelist structure
memcpy(lpSendFileList, &lpDevData->sfl, sizeof(SENDFILELIST));
sprintf(szBuff, "Send Fax on %s", lpDevData->devname);
SetWindowText(hwnd, szBuff);
// fax header parameter
if (lpDevData->chtype >= DFS_FAX40) {
fx_getparm(lpDevData->faxhandle, FC_HDRUSER, szBuff);
Edit_LimitText(GetDlgItem(hwnd, IDC_FAXHEADER), MAXHDRLEN);
SetDlgItemText(hwnd, IDC_FAXHEADER, strtrim(szBuff));
}
else {
Static_Enable(GetDlgItem(hwnd, IDS_FAXHEADER), FALSE);
Edit_Enable(GetDlgItem(hwnd, IDC_FAXHEADER), FALSE);
}
// dial string
Edit_LimitText(GetDlgItem(hwnd, IDC_DIALSTR), MAXDIALLEN);
SetDlgItemText(hwnd, IDC_DIALSTR, lpDevData->dialstr);
// fill listbox with files to send for, informational purposes only
hwndCtl = GetDlgItem(hwnd,IDC_SENDLIST);
ListBox_ResetContent(hwndCtl);
for (i=0;i<lpSendFileList->count;i++) {
ListBox_AddString(hwndCtl, lpSendFileList->filename[i]);
}
return TRUE;
case WM_COMMAND:
if (wParam == IDOK) {
// validate and move data back to devdata structure
if (lpSendFileList->count <=0) {
MessageBox(hwnd, "No files selected!", "Send Fax Error", MB_OK);
return FALSE;
}
// dial string
GetDlgItemText(hwnd, IDC_DIALSTR, szBuff, MAXDIALLEN);
strcpy(lpDevData->dialstr, strtrim(szBuff));
if (*lpDevData->dialstr == '\0') {
MessageBox(hwnd, "No dial string!", "Send Fax Error", MB_OK);
return FALSE;
}
// fax header
if (lpDevData->chtype >= DFS_FAX40) {
GetDlgItemText(hwnd, IDC_FAXHEADER, szBuff, MAXHDRLEN);
fx_setparm(lpDevData->faxhandle, FC_HDRUSER, szBuff);
}
// update devices sendfilelist structure from global used by FileOpenHookProc
memcpy(&lpDevData->sfl, lpSendFileList, sizeof(SENDFILELIST));
// init fax call
// build IOTT list from sendfilelist structure
for (i=0;i<lpDevData->sfl.count;i++) {
if ((fh=dx_fileopen(lpDevData->sfl.filename[i], _O_RDONLY | _O_BINARY)) == -1) {
StatusMsg(hwnd, "Error opening %s\n",lpDevData->sfl.filename[i]);
// close anything we may have opened
for (j=0;j<i;j++) {
dx_fileclose(lpDevData->sfl.iott[i].io_fhandle);
}
return FALSE;
}
// file opened, determine TIFF/F or TEXT and init IOTT
extp=strrchr(lpDevData->sfl.filename[i],'.');
if ((extp != NULL) && (_strnicmp(extp+1,"tif",3)==0)) {
// TIFF/F file
fx_setiott(&lpDevData->sfl.iott[i], fh, DF_TIFF, DFC_AUTO);
}
else {
// otherwise treat as Text file
fx_setiott(&lpDevData->sfl.iott[i], fh, DF_ASCII, DFC_AUTO);
lpDevData->sfl.iott[i].io_datap = &lpDevData->asciidata;
}
}
// mark last iott as the last
lpDevData->sfl.iott[lpDevData->sfl.count-1].io_type |= IO_EOT;
// issue sethook to start call
lpDevData->state=ST_TXOFFHK;
dx_sethook(lpDevData->voicehandle, DX_OFFHOOK, EV_ASYNC);
// close dialog box
EndDialog(hwnd, wParam);
}
if (wParam == IDCANCEL) {
// canceled, no changes
EndDialog(hwnd, wParam);
}
if (wParam == IDC_SELECTFILES) {
// display file selection dialog
GetOpenFileName(&ofn);
// and update sendlist listbox, regardless of change
hwndCtl = GetDlgItem(hwnd,IDC_SENDLIST);
ListBox_ResetContent(hwndCtl);
for (i=0;i<lpSendFileList->count;i++) {
ListBox_AddString(hwndCtl, lpSendFileList->filename[i]);
}
}
break;
}
return FALSE;
}
/************************************************************
* NAME: SendfaxCleanup()
* DESCRIPTION: close files in IOTT array after sendfax
* : reset sfl.count if no error
************************************************************/
void SendfaxCleanup(LPDEVDATA lpDevData, int evttype)
{
int i;
// close files in IOTT
for (i=0;i<lpDevData->sfl.count;i++) {
dx_fileclose(lpDevData->sfl.iott[i].io_fhandle);
}
// if successfull, reset file count
if (evttype == TFX_FAXSEND) {
lpDevData->sfl.count =0;
}
}
/************************************************************
* NAME: AboutDlgProc()
* DESCRIPTION: About dialog's procedure
************************************************************/
BOOL WINAPI AboutDlgProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
{
switch (msg) {
case WM_INITDIALOG:
SetWindowContextHelpId(hwnd, IDD_ABOUT);
return TRUE;
case WM_COMMAND:
if (wParam == IDOK) {
EndDialog(hwnd, wParam);
}
break;
}
return FALSE;
}
/************************************************************
* NAME: OpenFaxDevice()
* DESCRIPTION: Creates child window or shows window if aleady open
* child window WM_CREATE opens device and inits structures
* RETURNS: child window handle, or NULL if error
************************************************************/
HWND OpenFaxDevice(char *pName)
{
HWND hwnd;
if ((pName == NULL) || (strlen(pName) ==0)) {
// pName is null, return NULL
return(NULL);
}
// see if device is already open and return it if so
if ((hwnd = AlreadyOpen(pName)) != NULL) {
// bring window to front, and restore if minimized
ShowWindow(hwnd, SW_SHOWNORMAL);
SendMessage(hwndClient, WM_MDIACTIVATE, (WPARAM) hwnd, 0);
return(hwnd);
}
// for now, just create window
hwnd = CreateMDIWindow(szChild,
pName,
0,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hwndClient,
hInst,
0);
// update menu item states
GrayMenuItems();
return(hwnd);
}
/************************************************************
* NAME: CloseFaxDevice()
* DESCRIPTION: Close device, checking for inactive first
* Child window WM_DESTROY closes devices and frees
* channel structure
* RETURNS: success, failure
************************************************************/
BOOL CloseFaxDevice(HWND hwnd)
{
LPDEVDATA lpDevData;
if ((lpDevData = GetDevPtr(hwnd)) != NULL) {
if (!((lpDevData->state == ST_WTRING) || (lpDevData->state == ST_INIT))) {
if (MessageBox(NULL,"Device is still active. Close anyway?", lpDevData->devname, MB_YESNO) == IDNO) {
// user cancelled
return(FALSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -