PopFax.cpp
上传用户:looem2003
上传日期:2014-07-20
资源大小:13733k
文件大小:115k
- // PopFax.cpp : Defines the entry point for the application.
- //
- #include "PopFax.h"
- #pragma comment(lib,"Wininet.lib")
- //#pragma comment(lib,"User32.lib")
- #pragma comment(lib,"Comdlg32.lib")
- #pragma comment(lib,"shell32.lib")
- #pragma comment(lib,"Gdi32.lib")
- #pragma comment(lib,"GdiPlus.lib")
- #pragma comment(lib,"cximagecrtu.lib")
- #pragma comment(lib,"comctl32.lib")
- //char optData[12582912] = "";//12582912 12 戾汔徉轵
- char optData[1048576] = "";//1048576 1 戾汔徉轵
- const char* aBoundary = "----AaB03x";
- LPCTSTR tBoundary = _T("----AaB03x");
- #define WRITE_BLOCK 1024
- CGdiPlusInit gdiplusInit;
- BOOL start_process( LPTSTR process );
- int APIENTRY _tWinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine,
- int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- APPCONFIG ac;
- ADDITIONALCONFIG aac;
- LPTSTR buff = lpCmdLine;
- // TODO: Place code here.
- start_process( NULL );
- load_app_config( hInstance, &ac, _T("app_config.ini"), load_config, &aac );
-
- //while( (buff[0] == _T(' ')) || (buff[0] == _T('"')) ) buff++;
- //_tcscpy_s( aac.sendFile, ARRAYSIZE(aac.sendFile), buff );
- //if( NULL != (buff = _tcschr( aac.sendFile, _T('"') ) ) )
- // buff[0] = 0;
- gdiplusInit.gdi_start();
- buff = _tcsrchr( aac.logo, _T('\') );
- _stprintf_s( buff+1, ARRAYSIZE(aac.logo), _T("%s_logo.gif"), lm.get_current_lang() );
- aac.bmp = new Bitmap( aac.logo );
- //convert_pjl_bmp( &ac );
- convert_image( &ac );
- //DialogBoxParam( GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SENDING), NULL, dlg_send, (LPARAM)&ac);
- if( NULL != _tcsstr( lpCmdLine, _T("/config") ) )
- {
- ZeroMemory( aac.sendFile, sizeof(aac.sendFile) );
- DialogBoxParam( hInstance, MAKEINTRESOURCE(IDD_OPTIONS), NULL, dlg_options, (LPARAM)&ac);
- }
- else
- DialogBoxParam( hInstance, MAKEINTRESOURCE(IDD_DLGBOX), NULL, dlg_main, (LPARAM)&ac);
- save_app_config( &ac, save_config );
- if( NULL != aac.bmp )
- {
- Bitmap* bmp = (Bitmap*)aac.bmp;
- //CxImage* bmp = (CxImage*)aac.bmp;
- delete bmp;
- aac.bmp = NULL;
- gdiplusInit.gdi_stop();
- }
- return (int)0;
- }
- INT_PTR CALLBACK dlg_credentials(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- static LPAPPCONFIG ac = NULL;
- static LPADDITIONALCONFIG aac = NULL;
- INT_PTR ret = (INT_PTR)FALSE;
- switch (message)
- {
- case WM_INITDIALOG:
- ret = (INT_PTR)TRUE;
- if( (NULL != ( ac = (LPAPPCONFIG)lParam ))&&( NULL == (aac = (LPADDITIONALCONFIG)ac->addParam) ) )
- {
- EndDialog(hDlg, LOWORD(wParam));
- break;
- }
- SetDlgItemText( hDlg, IDC_EDIT_USER, aac->userName );
- SetDlgItemText( hDlg, IDC_EDIT_PASS, aac->userPass );
- CheckDlgButton( hDlg, IDC_SAVE_PASS, aac->savePass?BST_CHECKED:BST_UNCHECKED);
- set_lang_txt( hDlg, aac, 2 );
- //if( 0 == _tcslen( aac->userName ) )
- // SetFocus( GetDlgItem( hDlg, IDC_EDIT_USER ) );
- //else
- // SetFocus( GetDlgItem( hDlg, IDC_EDIT_PASS ) );
- break;
- case WM_COMMAND:
- switch( LOWORD(wParam) )
- {
- case IDC_SAVE_PASS://
- aac->savePass = (BST_CHECKED == ( BST_CHECKED & IsDlgButtonChecked( hDlg, IDC_SAVE_PASS) ));
- break;
- case IDOK:
- GetDlgItemText( hDlg, IDC_EDIT_USER, aac->userName, ARRAYSIZE(aac->userName) );
- GetDlgItemText( hDlg, IDC_EDIT_PASS, aac->userPass, ARRAYSIZE(aac->userPass) );
- case IDCANCEL:
- EndDialog(hDlg, LOWORD(wParam));
- ret = (INT_PTR)TRUE;
- }
- break;
- }
-
- return ret;
- }
- void draw_item( LPADDITIONALCONFIG aac, LPDRAWITEMSTRUCT lpDrawItem )
- {
- if( (NULL != aac)&&(NULL != lpDrawItem) )
- {
- float x = 0, y = 0, cx = 0, cy = 0, imgW = 0, imgH = 0;
- Bitmap* bmp = (Bitmap*)aac->bmp;
- RECT rc = lpDrawItem->rcItem;
- rc.top++;
- rc.left++;
- rc.bottom -= 3;
- rc.right -= 3;
- if( NULL != bmp )
- {
- cx = (float)(rc.right-rc.left);
- cy = (float)(rc.bottom-rc.top);
- imgW = (float)bmp->GetWidth();
- imgH = (float)bmp->GetHeight();
- if( cy > (imgH/(imgW/cx)) )
- {
- imgH = (imgH/(imgW/cx));
- imgW = cx;
- }
- else
- {
- imgW = (imgW/(imgH/cy));
- imgH = cy;
- }
- Graphics* g = Graphics::FromHDC( lpDrawItem->hDC );
- if( NULL != g )
- {
- //bmp->Draw( lpDrawItem->hDC, rc.left, rc.top, imgW, imgH+2, 0, true);
- g->DrawImage( bmp, (INT)rc.left, (INT)rc.top, (INT)imgW, (INT)imgH+2);
- delete g;
- }
- }
- }
- }
- #define WM_TRAY_ICON (WM_USER+123)
- #define WM_ANIMATE_WAIT (WM_USER+124)
- // Message handler for main box.
- INT_PTR CALLBACK dlg_main(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- static LPAPPCONFIG ac = NULL;
- static LPADDITIONALCONFIG aac = NULL;
- static HICON hIcon = NULL;
- static HICON hBtnIcon = NULL;
- static HICON hBtnMassIcon = NULL;
- static HANDLE hThread = NULL;
- INT_PTR ret = (INT_PTR)FALSE;
- switch (message)
- {
- case WM_INITDIALOG:
- ret = (INT_PTR)TRUE;
- if( (NULL != ( ac = (LPAPPCONFIG)lParam ))&&( NULL == (aac = (LPADDITIONALCONFIG)ac->addParam) ) )
- {
- EndDialog(hDlg, LOWORD(wParam));
- break;
- }
- SetClassLong( hDlg, GCLP_HICON, (LONG)(hIcon = LoadIcon( GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_POPFAX))) );
- SendMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon );
- CheckDlgButton( hDlg, IDC_CLOSE_WND, (!aac->closeWnd)?BST_CHECKED:BST_UNCHECKED);
- CheckDlgButton( hDlg, IDC_TRANSMITION_REPORT, aac->transmReport?BST_CHECKED:BST_UNCHECKED);
- CheckDlgButton( hDlg, IDC_CHECK_ATTACH, aac->transmReportAttach?BST_CHECKED:BST_UNCHECKED);
- EnableWindow( GetDlgItem( hDlg, IDC_CHECK_ATTACH ), aac->transmReport );
- //hBtnIcon = ExtractIcon( GetModuleHandle( NULL ), _T("shell32.dll"), 160 );
- ExtractIconEx( _T("shell32.dll"), 160, &hBtnIcon, NULL, 1 );
- SendDlgItemMessage( hDlg, IDC_BTN_ADR1, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hBtnIcon);
- ExtractIconEx( _T("shell32.dll"), 108, &hBtnMassIcon, NULL, 1 );
- SendDlgItemMessage( hDlg, IDC_BTN_MASS_FAX, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hBtnMassIcon);
- EnableWindow( GetDlgItem( hDlg, IDC_BTN_MASS_FAX ), FALSE );
- set_lang_txt( hDlg, aac, 1 );
- break;
- case WM_DRAWITEM:
- draw_item( aac, (LPDRAWITEMSTRUCT) lParam );
- break;
- case WM_CLOSE:
- case WM_DESTROY:
- if( NULL != hIcon )
- DestroyIcon( hIcon );
- hIcon = NULL;
- if( NULL != hBtnIcon )
- DestroyIcon( hBtnIcon );
- hBtnIcon = NULL;
- if( NULL != hBtnMassIcon )
- DestroyIcon( hBtnMassIcon );
- hBtnMassIcon = NULL;
- break;
- case WM_COMMAND:
- switch( LOWORD(wParam) )
- {
- case IDC_BTN_MASS_FAX:
- if( IDOK == DialogBoxParam( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDD_MASS_FAX ), hDlg, dlg_mass_fax, (LPARAM)ac ) )
- EnableWindow( GetDlgItem( hDlg, IDOK ), TRUE );
- else
- aac->massFax[0] = 0;
- break;
- case IDC_CHECK_MASS_FAX:
- {
- BOOL enabled = (BST_CHECKED == ( BST_CHECKED & IsDlgButtonChecked( hDlg, IDC_CHECK_MASS_FAX) ));
- EnableWindow( GetDlgItem( hDlg, IDC_BTN_MASS_FAX ), enabled);
- EnableWindow( GetDlgItem( hDlg, IDC_FAX1 ), !enabled );
- EnableWindow( GetDlgItem( hDlg, IDC_FAX2 ), !enabled );
- EnableWindow( GetDlgItem( hDlg, IDC_FAX3 ), !enabled );
- if( enabled )
- EnableWindow( GetDlgItem( hDlg, IDOK ), FALSE );
- else
- if( ((0 != GetWindowTextLength( GetDlgItem(hDlg, IDC_FAX1 )))||
- (0 != GetWindowTextLength( GetDlgItem(hDlg, IDC_FAX2 )))||
- (0 != GetWindowTextLength( GetDlgItem(hDlg, IDC_FAX3 ))) ) &&
- (0 != _tcslen(aac->sendFile) ) )
- EnableWindow( GetDlgItem( hDlg, IDOK ), TRUE );
- else
- EnableWindow( GetDlgItem( hDlg, IDOK ), FALSE );
- }
- break;
- case IDC_BTN_ADR1:
- {
- LPTSTR fax = NULL;
- DWORD i = 0, j = 0;
- _tstring faxes( _T("") );
- aac->param = &faxes;
- DialogBoxParam( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDD_CONTACT_BOOK ), hDlg, dlg_contact_book, (LPARAM)ac );
- fax = (LPTSTR)faxes.c_str();
- for( DWORD id = IDC_FAX1, index = 0; id <= IDC_FAX3; id++ )
- if( 0 == GetWindowTextLength( GetDlgItem( hDlg, id ) ) )
- {
- j = 0;
- while( (fax[i] != _T('n'))&&(fax[i] != _T(' ')) )
- aac->fax1[j++] = fax[i++];
- if( fax[i] == _T(' ') )
- break;
- aac->fax1[j] = 0;
- i++;
- SetDlgItemText( hDlg, id, aac->fax1 );
- }
- }
- break;
- case IDC_TRANSMITION_REPORT:
- EnableWindow( GetDlgItem( hDlg, IDC_CHECK_ATTACH ), (aac->transmReport = (BST_CHECKED == ( BST_CHECKED & IsDlgButtonChecked( hDlg, IDC_TRANSMITION_REPORT) )) ) );
- break;
- case IDC_CHECK_ATTACH:
- aac->transmReportAttach = (BST_CHECKED == ( BST_CHECKED & IsDlgButtonChecked( hDlg, IDC_CHECK_ATTACH) ));
- break;
- case IDC_CLOSE_WND:
- aac->closeWnd = !(BST_CHECKED == ( BST_CHECKED & IsDlgButtonChecked( hDlg, IDC_CLOSE_WND) ));
- break;
- case IDC_BROWSE:
- browse_file( hDlg, aac->sendFile, ARRAYSIZE(aac->sendFile), _T("Tiff files (*.tif; *.tiff) *.tif *.tiff ") );
- //break;
- case IDC_FAX1:
- case IDC_FAX2:
- case IDC_FAX3:
- if( ((0 == GetWindowTextLength( GetDlgItem(hDlg, IDC_FAX1 )))&&
- (0 == GetWindowTextLength( GetDlgItem(hDlg, IDC_FAX2 )))&&
- (0 == GetWindowTextLength( GetDlgItem(hDlg, IDC_FAX3 ))) ) ||
- (0 == _tcslen(aac->sendFile) ) )
- EnableWindow( GetDlgItem( hDlg, IDOK ), FALSE );
- else
- EnableWindow( GetDlgItem( hDlg, IDOK ), TRUE );
- break;
- case IDC_PREVIEW:
- //DialogBoxParam( GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PREVIEW), hDlg, dlg_preview, (LPARAM)ac);
- preview( hDlg, aac->sendFile );
- break;
- case IDC_OPTIONS:
- DialogBoxParam( GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS), hDlg, dlg_options, (LPARAM)ac);
- set_lang_txt( hDlg, aac, 1 );
- break;
- case IDOK:
- if( BST_CHECKED == ( BST_CHECKED & IsDlgButtonChecked( hDlg, IDC_CHECK_MASS_FAX) ) )
- {
- aac->fax1[0] = aac->fax2[0] = aac->fax3[0] = 0;
- }
- else
- {
- GetDlgItemText( hDlg, IDC_FAX1, aac->fax1, ARRAYSIZE(aac->fax1) );
- GetDlgItemText( hDlg, IDC_FAX2, aac->fax2, ARRAYSIZE(aac->fax2) );
- GetDlgItemText( hDlg, IDC_FAX3, aac->fax3, ARRAYSIZE(aac->fax3) );
- }
- aac->hDlg = hDlg;
- DialogBoxParam( GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SENDING), hDlg, dlg_send, (LPARAM)ac);
- //if( !aac->closeWnd )
- // break;
- case IDCANCEL:
- EndDialog(hDlg, LOWORD(wParam));
- ret = (INT_PTR)TRUE;
- }
- break;
- }
-
- return ret;
- }
- BOOL send_fax( LPADDITIONALCONFIG aac, DWORD sendFlag )
- {
- BOOL ret = FALSE;
- CURLEncode ue;
- TCHAR resXml[LONG_PATH] = _T("");
- TCHAR retText[1024] = _T("");
- LPCTSTR acceptTypes[] = { _T("Accept: */*"), NULL};
- //LPCTSTR header = (( FAX_TRANSFER == sendFlag )?_T("Content-Type: multipart/form-data; boundary=--AaB03x"):_T("Content-Type: application/x-www-form-urlencoded"));
- LPCTSTR header = _T("Content-Type: multipart/form-data; boundary=--AaB03x");
- DWORD flags = INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID | INTERNET_FLAG_NO_COOKIES;
- DWORD dataSize = 0;
- ULARGE_INTEGER massFileSize = { 0, 0};
- char txRep[][12] = { "YES ", "NO ", "NOT_AT_ALL " } ;
- DWORD txReportNum = 0;
-
- HINTERNET hInternet = NULL;
- HINTERNET hConnect = NULL;
- HINTERNET hRequest = NULL;
- HANDLE hFile = INVALID_HANDLE_VALUE;
- HANDLE hMassFile = INVALID_HANDLE_VALUE;
- if( aac->canSend )
- {
- ShowWindow( aac->hProgress, ( FAX_AUTHENTICATION == sendFlag )?SW_HIDE:SW_SHOW );
- switch( sendFlag )
- {
- case FAX_TRANSFER:
- SetDlgItemText( aac->hDlg, IDC_STATE, lm._ls( IDT_FILE_TRANSFER ) );
- break;
- case FAX_STATUS:
- SetDlgItemText( aac->hDlg, IDC_STATE, lm._ls( IDT_FAX_SENDING ) );
- break;
- }
- }
- ZeroMemory( optData, sizeof(optData) );
- do
- {
- if( FAX_TRANSFER == sendFlag )
- if( (0 != _tcslen( aac->sendFile ))&&
- (-1 == _taccess( aac->sendFile, 0 ) ) )
- break;
- if( NULL == (hInternet = InternetOpen( _T("Popfax"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0) ) )
- break;
- ////耦邃桧