If the fax port is created, the port is ready for sending faxes through the assigned communication port. In order to send a fax, we have to create a fax object performing the CreateSendFax function. The first parameter of this function gives the type of the fax transmission protocol. At this point, FAXCPP supports the normal transmission protocol. The second parameter specifies the description of fax properties in a structure. The properties determine the dimensions of fax pages, the bit order of the transmission and the type of compression of fax pages.
If the fax object is created successfully, the fax pages can be filled with the SetFaxImagePage function. The image page can be specified either with a memory handle or name of a file. The image in the memory can be a device dependent or independent bitmap or a handle to raw data.
In the end; we can send the fax immediately or we can put the fax in a sending queue waiting to get the communication line free for sending it. Sending the fax immediately will cause the transmission currently in progress to be interrupted.
For example:
TSFaxParam sFaxParam;
CImgApp *pApp = (CImgApp *)AfxGetApp();
if(pApp->FaxPorts[0]) {
sFaxParam.PageNum = 1;
sFaxParam.Resolut = RES_98LPI;
sFaxParam.Width = PWD_1728;
sFaxParam.Length = PLN_NOCHANGE;
sFaxParam.Compress = DCF_1DMH;
sFaxParam.Binary = BFT_NOCHANGE;
sFaxParam.BitOrder = BTO_FIRST_LSB;
// Get remote fax number.
GetDlgItemText(IDC_FAXNUMBER, sFaxParam.RemoteID, sizeof(sFaxParam.RemoteID));
sFaxParam.Send = TRUE;
FAXOBJ foFax = CreateSendFax('N', &sFaxParam );
if(!foFax) {
// Creating fax is failed
} else {
union TUFaxImage sFaxPage;
sFaxPage.Dib = pDoc->hDib;
if(!SetFaxImagePage(foFax, 0, IMT_MEM_DIB, &sFaxPage, 0)) {
// Get our identification string.
CString cId = pApp->GetProfileString("Fax", "Identification String", NULL);
char szBuffer[80];
strncpy(szBuffer, cId, sizeof(szBuffer));
SetMyID(szBuffer);
if(bSendQueue) {
if(SetFaxSendQueue(foFax)) {
// Put fax into the queueihas failed.
}
} else if(PutFaxOnQueue(pApp->FaxPorts[0], foFax, FALSE)) {
// Sending fax immediate has failed.
}
} else {
// Setting the image page has failed.
}
}
} else {
// No port is opened.
}