StringList CSxSParser::FindMatchedFSObjects(LPCTSTR szParentFolder, LPCTSTR szFilter, BOOL bIsFile) const { CString strParent(szParentFolder); if(strParent[strParent.GetLength() - 1] != _T('\\')) strParent += _T('\\'); CString strFilter(strParent); strFilter += szFilter; StringList listResult; WIN32_FIND_DATA data; HANDLE hFind = ::FindFirstFile(strFilter, &data); if(hFind == INVALID_HANDLE_VALUE) return listResult; CString strFilePath; do { if(_tcscmp(data.cFileName, _T(".")) == 0 || _tcscmp(data.cFileName, _T("..")) == 0) continue; if(bIsFile && ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)) continue; if(!bIsFile && ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)) continue; strFilePath = data.cFileName; listResult.Add(strFilePath); } while (::FindNextFile(hFind, &data)); ::FindClose(hFind); return listResult; }
BOOL CPPgMessages::OnApply() { thePrefs.msgonlyfriends = IsDlgButtonChecked(IDC_MSGONLYFRIENDS)!=0; thePrefs.msgsecure = IsDlgButtonChecked(IDC_MSGONLYSEC)!=0; thePrefs.m_bAdvancedSpamfilter = IsDlgButtonChecked(IDC_ADVSPAMFILTER)!=0; thePrefs.indicateratings = IsDlgButtonChecked(IDC_INDICATERATINGS)!=0; GetDlgItem(IDC_FILTER)->GetWindowText(thePrefs.messageFilter); CString strCommentFilters; GetDlgItem(IDC_COMMENTFILTER)->GetWindowText(strCommentFilters); strCommentFilters.MakeLower(); CString strNewCommentFilters; int curPos = 0; CString strFilter(strCommentFilters.Tokenize(_T("|"), curPos)); while (!strFilter.IsEmpty()) { strFilter.Trim(); if (!strNewCommentFilters.IsEmpty()) strNewCommentFilters += _T('|'); strNewCommentFilters += strFilter; strFilter = strCommentFilters.Tokenize(_T("|"), curPos); } thePrefs.commentFilter = strNewCommentFilters; if (thePrefs.commentFilter != strCommentFilters) SetDlgItemText(IDC_COMMENTFILTER, thePrefs.commentFilter); LoadSettings(); SetModified(FALSE); return CPropertyPage::OnApply(); }
void FrmCell::filterModel4Combo() { QString strQuery = "select fr_gls2als.id_abstract_landingsite as ls, ref_minor_strata.id_gls, fr_gls2als.id_gls as expr1" " from ref_minor_strata inner join" " fr_time on ref_minor_strata.id_frame_time = fr_time.id inner join" " fr_frame on fr_time.id_frame = fr_frame.id inner join" " fr_sub_frame on fr_frame.id = fr_sub_frame.id_frame inner join" " fr_gls2als on fr_sub_frame.id = fr_gls2als.id_sub_frame and ref_minor_strata.id_gls = fr_gls2als.id_gls" " where (ref_minor_strata.id = :id)" ; QSqlQuery query; query.prepare(strQuery); query.bindValue(0,m_sample->minorStrataId); if (!query.exec()){ emit showError(tr("Could not obtain filter for Landing Sites!")); return; } Q_ASSERT_X(query.size()>=1, "Cell", QString(QString("Selection of a GLS without landing sites!") + m_sample->print()).toUtf8().constData()); QString strFilter(""); while (query.next()) { strFilter.append("ID=" + query.value(0).toString()); strFilter.append(" OR "); } if (!strFilter.isEmpty()) strFilter=strFilter.remove(strFilter.size()-QString(" OR ").length(),QString(" OR ").length()); tSampCell->relationModel(2)->setFilter(strFilter); //first we set the relation; then we create a mapper and assign the (amended) model to the mapper; initMapper1(); }
bool Utils::OpenMultiFileDialog(CStringList& fileNameList) { CFileDialog dlg(TRUE); std::vector<CString> filter = getOpenFilter(); CString strFilter(makeFilter(filter)); dlg.m_ofn.lpstrFilter = strFilter; dlg.m_ofn.lpstrDefExt = NULL; dlg.m_ofn.Flags |= OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT; const int maxChar = 5000; CString strBuffer; dlg.m_ofn.lpstrFile = strBuffer.GetBuffer(maxChar); dlg.m_ofn.nMaxFile = maxChar; int choice = dlg.DoModal(); strBuffer.ReleaseBuffer(); if (choice == IDOK) { POSITION pos = dlg.GetStartPosition(); while (pos != NULL) { fileNameList.AddTail(dlg.GetNextPathName(pos)); } return true; } return false; }
void CAbstractFile::RefilterKadNotes(bool bUpdate){ // check all availabe comments against our filter again if (thePrefs.GetCommentFilter().IsEmpty()) return; POSITION pos1, pos2; for (pos1 = m_kadNotes.GetHeadPosition();( pos2 = pos1 ) != NULL;) { m_kadNotes.GetNext(pos1); Kademlia::CEntry* entry = m_kadNotes.GetAt(pos2); if (!entry->GetStrTagValue(TAG_DESCRIPTION).IsEmpty()){ CString strCommentLower(entry->GetStrTagValue(TAG_DESCRIPTION)); strCommentLower.MakeLower(); int iPos = 0; CString strFilter(thePrefs.GetCommentFilter().Tokenize(_T("|"), iPos)); while (!strFilter.IsEmpty()) { // comment filters are already in lowercase, compare with temp. lowercased received comment if (strCommentLower.Find(strFilter) >= 0) { m_kadNotes.RemoveAt(pos2); delete entry; break; } strFilter = thePrefs.GetCommentFilter().Tokenize(_T("|"), iPos); } } } if (bUpdate) // untill updated rating and m_bHasComment might be wrong UpdateFileRatingCommentAvail(); }
void FrmCatch::filterModel4Combo() { if (!m_sample) return; QSqlQuery query; QString strQuery; if (m_sample->operationId==-1) { emit showError(tr("Could not identify the operation for this catch!")); return; } strQuery= "SELECT id_commercial_category" " FROM dbo.Sampled_Fishing_Operations_Categories" " WHERE (id_fishing_operation = " + QVariant(m_sample->operationId).toString() + ")"; query.prepare(strQuery); if (!query.exec()) { emit showError(tr("Could not obtain filter for commercial categories!")); return; } QString strFilter(""); while (query.next()) { strFilter.append("ID=" + query.value(0).toString()); strFilter.append(" OR "); } if (!strFilter.isEmpty()) strFilter=strFilter.remove(strFilter.size()-QString(" OR ").length(),QString(" OR ").length()); tCatch->relationModel(2)->setFilter(strFilter); initMapper1(); }
void CMainWnd::SaveMediaFile(HWND hwndParent) { if (m_fShowOpenDlg) return; BOOL fRet; CTempStr strTitle(IDS_TITLE_SAVE_LIST); CTempStr strFilter(IDS_FILTER_SAVE_LIST); TCHAR szFile[MAX_PATH] = {0}; m_fShowOpenDlg = TRUE; #ifdef _WIN32_WCE OPENFILENAME ofn; memset(&(ofn), 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwndParent ? hwndParent : m_hWnd; ofn.lpstrFile = szFile; ofn.nMaxFile = MAX_PATH; ofn.lpstrTitle = strTitle; ofn.lpstrFilter = strFilter; ofn.lpstrDefExt = M3U_FILE_EXT; ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT; ofn.lpstrInitialDir = m_pOptions->m_szLastDir; BOOL (*gsGetSaveFileName)(OPENFILENAME*) = NULL; HINSTANCE hInst = LoadLibrary(_T("gsgetfile.dll")); if (hInst) { (FARPROC&)gsGetSaveFileName = GetProcAddress(hInst, _T("gsGetSaveFileName")); } if (gsGetSaveFileName) fRet = gsGetSaveFileName(&ofn); else fRet = GetSaveFileName(&ofn); if (hInst) FreeLibrary(hInst); #else OPENFILENAME ofn; memset(&(ofn), 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = m_hWnd; ofn.lpstrFile = szFile; ofn.nMaxFile = MAX_PATH; ofn.lpstrTitle = strTitle; ofn.lpstrFilter = strFilter; ofn.lpstrDefExt = M3U_FILE_EXT; ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT; ofn.lpstrInitialDir = m_pOptions->m_szLastDir; fRet = GetSaveFileName(&ofn); #endif m_fShowOpenDlg = FALSE; if (!fRet) return; SavePlayList(szFile); }
bool Utils::OpenFileDialog(CString& strFile) { CFileDialog dlg(TRUE); std::vector<CString> filter = getOpenFilter(); CString strFilter(makeFilter(filter)); dlg.m_ofn.lpstrFilter = strFilter; dlg.m_ofn.lpstrDefExt = NULL; dlg.m_ofn.Flags |= OFN_FILEMUSTEXIST; if (dlg.DoModal() == IDOK) { strFile = dlg.GetPathName(); return true; } return false; }
bool Utils::OpenSaveDialog(CString& strFile, const std::vector<CString>& filter, const CString& strInitialDirectory) { CFileDialog dlg(true); CString strFilter(makeFilter(filter)); dlg.m_ofn.lpstrFilter = strFilter; dlg.m_ofn.lpstrDefExt = NULL; dlg.m_ofn.lpstrInitialDir = strInitialDirectory; dlg.m_ofn.Flags |= OFN_FILEMUSTEXIST; if (dlg.DoModal() == IDOK) { strFile = dlg.GetPathName(); return true; } return false; }
BOOL CPPgSecurity::OnApply() { TCHAR buffer[510]; if(GetDlgItem(IDC_FILTERLEVEL)->GetWindowTextLength()) { GetDlgItem(IDC_FILTERLEVEL)->GetWindowText(buffer,4); thePrefs.filterlevel=_tstoi(buffer); } thePrefs.filterserverbyip = (uint8)IsDlgButtonChecked(IDC_FILTERSERVERBYIPFILTER); thePrefs.msgonlyfriends = (uint8)IsDlgButtonChecked(IDC_MSGONLYFRIENDS); thePrefs.msgsecure = (uint8)IsDlgButtonChecked(IDC_MSGONLYSEC); thePrefs.m_bAdvancedSpamfilter = IsDlgButtonChecked(IDC_ADVSPAMFILTER); thePrefs.m_bUseSecureIdent = IsDlgButtonChecked(IDC_USESECIDENT); thePrefs.m_bRunAsUser = (uint8)IsDlgButtonChecked(IDC_RUNASUSER); GetDlgItem(IDC_FILTER)->GetWindowText(thePrefs.messageFilter,ARRSIZE(thePrefs.messageFilter)); CString strCommentFilters; GetDlgItem(IDC_COMMENTFILTER)->GetWindowText(strCommentFilters); strCommentFilters.MakeLower(); CString strNewCommentFilters; int curPos = 0; CString strFilter(strCommentFilters.Tokenize(_T("|"), curPos)); while (!strFilter.IsEmpty()) { strFilter.Trim(); if (!strNewCommentFilters.IsEmpty()) strNewCommentFilters += _T('|'); strNewCommentFilters += strFilter; strFilter = strCommentFilters.Tokenize(_T("|"), curPos); } thePrefs.commentFilter = strNewCommentFilters; if (thePrefs.commentFilter != strCommentFilters) SetDlgItemText(IDC_COMMENTFILTER, thePrefs.commentFilter); LoadSettings(); SetModified(FALSE); return CPropertyPage::OnApply(); }
void FrmMinorStrata::filterModel4Combo() { QString strQuery= "select fr_f2gls.id_gls " "from fr_sub_frame inner join" " fr_f2gls on fr_sub_frame.id = fr_f2gls.id_sub_frame inner join" " fr_frame inner join" " fr_time on fr_frame.id = fr_time.id_frame on fr_sub_frame.id_frame = fr_frame.id " " where (fr_time.id = :id) and (fr_sub_frame.type =" " (select id" " from ref_frame" " where (name = :root)) );" ; QSqlQuery query; query.prepare(strQuery); query.bindValue(0,m_sample->frameTimeId); query.bindValue(1,qApp->translate("frame", strRoot)); if (!query.exec()){ emit showError(tr("Could not obtain filter for Group of Landing Sites!")); return; } Q_ASSERT_X(query.numRowsAffected()>=1, "Minor Strata", QString(QString("Selection of a frame without GLS!") + m_sample->print()).toUtf8().constData()); QString strFilter(""); while (query.next()) { strFilter.append("id=" + query.value(0).toString()); strFilter.append(" OR "); } if (!strFilter.isEmpty()) strFilter=strFilter.remove(strFilter.size()-QString(" OR ").length(),QString(" OR ").length()); else{ emit showError(tr("Could not obtain a filter for Group of Landing Sites!")); return; } tRefMinorStrata->relationModel(2)->setFilter(strFilter); }
BOOL CPPgMessages::OnApply() { thePrefs.msgonlyfriends = IsDlgButtonChecked(IDC_MSGONLYFRIENDS)!=0; thePrefs.m_bAdvancedSpamfilter = IsDlgButtonChecked(IDC_ADVSPAMFILTER)!=0; thePrefs.indicateratings = IsDlgButtonChecked(IDC_INDICATERATINGS)!=0; thePrefs.m_bUseChatCaptchas = IsDlgButtonChecked(IDC_USECAPTCHAS) != 0; bool bOldSmileys = thePrefs.GetMessageEnableSmileys(); thePrefs.m_bMessageEnableSmileys = IsDlgButtonChecked(IDC_MSHOWSMILEYS) != 0; if (bOldSmileys != thePrefs.GetMessageEnableSmileys()) theApp.emuledlg->chatwnd->EnableSmileys(thePrefs.GetMessageEnableSmileys()); GetDlgItem(IDC_FILTER)->GetWindowText(thePrefs.messageFilter); CString strCommentFilters; GetDlgItem(IDC_COMMENTFILTER)->GetWindowText(strCommentFilters); strCommentFilters.MakeLower(); CString strNewCommentFilters; int curPos = 0; CString strFilter(strCommentFilters.Tokenize(_T("|"), curPos)); while (!strFilter.IsEmpty()) { strFilter.Trim(); if (!strNewCommentFilters.IsEmpty()) strNewCommentFilters += _T('|'); strNewCommentFilters += strFilter; strFilter = strCommentFilters.Tokenize(_T("|"), curPos); } thePrefs.commentFilter = strNewCommentFilters; if (thePrefs.commentFilter != strCommentFilters) SetDlgItemText(IDC_COMMENTFILTER, thePrefs.commentFilter); LoadSettings(); SetModified(FALSE); return CPropertyPage::OnApply(); }
bool Utils::SaveDialog(CString& strFile, FileType& fileType, std::vector<CString>& filter, std::vector<FileType>& fileTypes) { CFileDialog dlg(FALSE); CString strFilter(makeFilter(filter)); dlg.m_ofn.lpstrFilter = strFilter; dlg.m_ofn.lpstrDefExt = NULL; CString initalDirectory(getCurrentDirectory()); dlg.m_ofn.lpstrInitialDir = initalDirectory; dlg.m_ofn.Flags |= OFN_CREATEPROMPT; if (dlg.DoModal() == IDOK) { int typeIndex = dlg.m_ofn.nFilterIndex; strFile = getFileName(filter, typeIndex, dlg.GetPathName()); fileType = fileTypes[typeIndex - 1]; return true; } return false; }
static void PrintPiecesThread(void* pv) { CFrameWndEx* pFrame = (CFrameWndEx*)pv; CView* pView = pFrame->GetActiveView(); CPrintDialog PD(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOPAGENUMS|PD_NOSELECTION, pFrame); if (theApp.DoPrintDialog(&PD) != IDOK) return; if (PD.m_pd.hDC == NULL) return; Project* project = lcGetActiveProject(); ObjArray<lcPiecesUsedEntry> PiecesUsed; project->GetPiecesUsed(PiecesUsed); PiecesUsed.Sort(PiecesUsedSortFunc, NULL); // gather file to print to if print-to-file selected CString strOutput; if (PD.m_pd.Flags & PD_PRINTTOFILE) { CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT)); CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT)); CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER)); CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION)); CFileDialog dlg(FALSE, strDef, strPrintDef,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter); dlg.m_ofn.lpstrTitle = strCaption; if (dlg.DoModal() != IDOK) return; strOutput = dlg.GetPathName(); } CString DocName; char* Ext = strrchr(project->m_strTitle, '.'); DocName.Format("LeoCAD - %.*s BOM", Ext ? Ext - project->m_strTitle : strlen(project->m_strTitle), project->m_strTitle); DOCINFO docInfo; memset(&docInfo, 0, sizeof(DOCINFO)); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = DocName; CString strPortName; int nFormatID; if (strOutput.IsEmpty()) { docInfo.lpszOutput = NULL; strPortName = PD.GetPortName(); nFormatID = AFX_IDS_PRINTONPORT; } else { docInfo.lpszOutput = strOutput; AfxGetFileTitle(strOutput, strPortName.GetBuffer(_MAX_PATH), _MAX_PATH); nFormatID = AFX_IDS_PRINTTOFILE; } SetAbortProc(PD.m_pd.hDC, _AfxAbortProc); pFrame->EnableWindow(FALSE); CPrintingDialog dlgPrintStatus(NULL); CString strTemp; dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, DocName); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, PD.GetDeviceName()); AfxFormatString1(strTemp, nFormatID, strPortName); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp); dlgPrintStatus.ShowWindow(SW_SHOW); dlgPrintStatus.UpdateWindow(); if (StartDoc(PD.m_pd.hDC, &docInfo) == SP_ERROR) { pFrame->EnableWindow(TRUE); dlgPrintStatus.DestroyWindow(); AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT); return; } int ResX = GetDeviceCaps(PD.m_pd.hDC, LOGPIXELSX); int ResY = GetDeviceCaps(PD.m_pd.hDC, LOGPIXELSY); CRect RectDraw(0, 0, GetDeviceCaps(PD.m_pd.hDC, HORZRES), GetDeviceCaps(PD.m_pd.hDC, VERTRES)); DPtoLP(PD.m_pd.hDC, (LPPOINT)(RECT*)&RectDraw, 2); RectDraw.DeflateRect((int)(ResX*(float)theApp.GetProfileInt("Default","Margin Left", 50)/100.0f), (int)(ResY*(float)theApp.GetProfileInt("Default","Margin Top", 50)/100.0f), (int)(ResX*(float)theApp.GetProfileInt("Default","Margin Right", 50)/100.0f), (int)(ResY*(float)theApp.GetProfileInt("Default","Margin Bottom", 50)/100.0f)); CRect HeaderRect = RectDraw; HeaderRect.top -= (int)(ResY*theApp.GetProfileInt("Default", "Margin Top", 50) / 200.0f); HeaderRect.bottom += (int)(ResY*theApp.GetProfileInt("Default", "Margin Bottom", 50) / 200.0f); int RowsPerPage = AfxGetApp()->GetProfileInt("Default", "Catalog Rows", 10); int ColsPerPage = AfxGetApp()->GetProfileInt("Default", "Catalog Columns", 3); int PicHeight = RectDraw.Height() / RowsPerPage; int PicWidth = RectDraw.Width() / ColsPerPage; int TotalRows = (PiecesUsed.GetSize() + ColsPerPage - 1) / ColsPerPage; int TotalPages = (TotalRows + RowsPerPage - 1) / RowsPerPage; int RowHeight = RectDraw.Height() / RowsPerPage; int ColWidth = RectDraw.Width() / ColsPerPage; PD.m_pd.nMinPage = 1; PD.m_pd.nMaxPage = TotalPages + 1; UINT EndPage = PD.m_pd.nToPage; UINT StartPage = PD.m_pd.nFromPage; if (PD.PrintAll()) { EndPage = PD.m_pd.nMaxPage; StartPage = PD.m_pd.nMinPage; } lcClamp(EndPage, PD.m_pd.nMinPage, PD.m_pd.nMaxPage); lcClamp(StartPage, PD.m_pd.nMinPage, PD.m_pd.nMaxPage); int StepPage = (EndPage >= StartPage) ? 1 : -1; VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM)); // begin page printing loop BOOL bError = FALSE; // Creating Compatible Memory Device Context CDC *pMemDC = new CDC; if (!pMemDC->CreateCompatibleDC(pView->GetDC())) return; BITMAPINFO bi; ZeroMemory(&bi, sizeof(BITMAPINFO)); bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bi.bmiHeader.biWidth = PicWidth; bi.bmiHeader.biHeight = PicHeight; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 24; bi.bmiHeader.biCompression = BI_RGB; bi.bmiHeader.biSizeImage = PicWidth * PicHeight * 3; bi.bmiHeader.biXPelsPerMeter = 2925; bi.bmiHeader.biYPelsPerMeter = 2925; bi.bmiHeader.biClrUsed = 0; bi.bmiHeader.biClrImportant = 0; LPBITMAPINFOHEADER lpbi[1]; HBITMAP hBm, hBmOld; hBm = CreateDIBSection(pView->GetDC()->GetSafeHdc(), &bi, DIB_RGB_COLORS, (void **)&lpbi, NULL, (DWORD)0); if (!hBm) return; hBmOld = (HBITMAP)::SelectObject(pMemDC->GetSafeHdc(), hBm); PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI, PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; int pixelformat = ChoosePixelFormat(pMemDC->m_hDC, &pfd); DescribePixelFormat(pMemDC->m_hDC, pixelformat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); SetPixelFormat(pMemDC->m_hDC, pixelformat, &pfd); HGLRC hmemrc = wglCreateContext(pMemDC->GetSafeHdc()); wglMakeCurrent(pMemDC->GetSafeHdc(), hmemrc); GL_DisableVertexBufferObject(); float Aspect = (float)PicWidth/(float)PicHeight; glViewport(0, 0, PicWidth, PicHeight); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.5f, 0.1f); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(1, 1, 1, 1); LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = -MulDiv(12, ResY, 72); lf.lfWeight = FW_REGULAR; lf.lfCharSet = DEFAULT_CHARSET; lf.lfQuality = PROOF_QUALITY; strcpy (lf.lfFaceName , "Arial"); HFONT HeaderFont = CreateFontIndirect(&lf); HFONT OldFont = (HFONT)SelectObject(PD.m_pd.hDC, HeaderFont); SetBkMode(PD.m_pd.hDC, TRANSPARENT); SetTextColor(PD.m_pd.hDC, 0x000000); SetTextAlign(PD.m_pd.hDC, TA_CENTER|TA_NOUPDATECP); DWORD PrintOptions = AfxGetApp()->GetProfileInt("Settings", "Print", PRINT_NUMBERS | PRINT_BORDER/*|PRINT_NAMES*/); bool DrawNames = 1;//(PrintOptions & PRINT_NAMES) != 0; bool Horizontal = 1;//(PrintOptions & PRINT_HORIZONTAL) != 0; pMemDC->SetTextColor(0x000000); pMemDC->SetBkMode(TRANSPARENT); // lf.lfHeight = -MulDiv(40, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72); // lf.lfWeight = FW_BOLD; HFONT CatalogFont = CreateFontIndirect(&lf); lf.lfHeight = -MulDiv(80, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72); HFONT CountFont = CreateFontIndirect(&lf); HFONT OldMemFont = (HFONT)SelectObject(pMemDC->m_hDC, CatalogFont); HPEN hpOld = (HPEN)SelectObject(pMemDC->m_hDC, GetStockObject(BLACK_PEN)); for (UINT CurPage = StartPage; CurPage != EndPage; CurPage += StepPage) { TCHAR szBuf[80]; wsprintf(szBuf, strTemp, CurPage); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf); if (::StartPage(PD.m_pd.hDC) < 0) { bError = TRUE; break; } // Draw header and footer. SelectObject(PD.m_pd.hDC, HeaderFont); CString Header; UINT Align; FormatHeader(Header, Align, AfxGetApp()->GetProfileString("Default", "Catalog Header", ""), project->m_strTitle, project->m_strAuthor, project->m_strDescription, CurPage, TotalPages); Align |= DT_TOP|DT_SINGLELINE; DrawText(PD.m_pd.hDC, (LPCTSTR)Header, Header.GetLength(), HeaderRect, Align); FormatHeader(Header, Align, AfxGetApp()->GetProfileString("Default", "Catalog Footer", "Page &P"), project->m_strTitle, project->m_strAuthor, project->m_strDescription, CurPage, TotalPages); Align |= DT_BOTTOM|DT_SINGLELINE; DrawText(PD.m_pd.hDC, (LPCTSTR)Header, Header.GetLength(), HeaderRect, Align); int StartPiece = (CurPage - 1) * RowsPerPage * ColsPerPage; int EndPiece = lcMin(StartPiece + RowsPerPage * ColsPerPage, PiecesUsed.GetSize()); for (int CurPiece = StartPiece; CurPiece < EndPiece; CurPiece++) { FillRect(pMemDC->m_hDC, CRect(0, PicHeight, PicWidth, 0), (HBRUSH)GetStockObject(WHITE_BRUSH)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); PieceInfo* pInfo = PiecesUsed[CurPiece].Info; pInfo->ZoomExtents(30.0f, Aspect); pInfo->RenderPiece(PiecesUsed[CurPiece].ColorIndex); glFinish(); // Draw description text at the bottom. CRect TextRect(0, 0, PicWidth, PicHeight); if (DrawNames) { SelectObject(pMemDC->m_hDC, CatalogFont); pMemDC->DrawText(pInfo->m_strDescription, strlen(pInfo->m_strDescription), TextRect, DT_CALCRECT | DT_WORDBREAK); TextRect.OffsetRect(0, PicHeight - TextRect.Height() - 5); pMemDC->DrawText(pInfo->m_strDescription, strlen(pInfo->m_strDescription), TextRect, DT_WORDBREAK); } // Draw count. SelectObject(pMemDC->m_hDC, CountFont); TextRect = CRect(0, 0, PicWidth, TextRect.top); TextRect.DeflateRect(5, 5); char CountStr[16]; sprintf(CountStr, "%dx", PiecesUsed[CurPiece].Count); pMemDC->DrawText(CountStr, strlen(CountStr), TextRect, DT_BOTTOM | DT_LEFT | DT_SINGLELINE); LPBITMAPINFOHEADER lpbi[1]; lpbi[0] = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hBm, 24)); BITMAPINFO bi; ZeroMemory(&bi, sizeof(BITMAPINFO)); memcpy (&bi.bmiHeader, lpbi[0], sizeof(BITMAPINFOHEADER)); SetStretchBltMode(PD.m_pd.hDC, COLORONCOLOR); int CurRow, CurCol; if (Horizontal) { CurRow = (CurPiece - StartPiece) / ColsPerPage; CurCol = (CurPiece - StartPiece) % ColsPerPage; } else { CurRow = (CurPiece - StartPiece) % RowsPerPage; CurCol = (CurPiece - StartPiece) / RowsPerPage; } int Left = RectDraw.left + ColWidth * CurCol + (ColWidth - PicWidth) / 2; int Top = RectDraw.top + RowHeight * CurRow + (RowHeight - PicHeight) / 2; StretchDIBits(PD.m_pd.hDC, Left, Top, PicWidth, PicHeight, 0, 0, PicWidth, PicHeight, (LPBYTE)lpbi[0] + lpbi[0]->biSize + lpbi[0]->biClrUsed * sizeof(RGBQUAD), &bi, DIB_RGB_COLORS, SRCCOPY); if (lpbi[0]) GlobalFreePtr(lpbi[0]); } if (::EndPage(PD.m_pd.hDC) < 0 || !_AfxAbortProc(PD.m_pd.hDC, 0)) { bError = TRUE; break; } } SelectObject(pMemDC->m_hDC, hpOld); SelectObject(PD.m_pd.hDC, OldFont); DeleteObject(HeaderFont); SelectObject(pMemDC->m_hDC, OldMemFont); DeleteObject(CatalogFont); DeleteObject(CountFont); GL_EnableVertexBufferObject(); wglMakeCurrent(NULL, NULL); wglDeleteContext(hmemrc); SelectObject(pMemDC->GetSafeHdc(), hBmOld); DeleteObject(hBm); delete pMemDC; if (!bError) EndDoc(PD.m_pd.hDC); else AbortDoc(PD.m_pd.hDC); pFrame->EnableWindow(); dlgPrintStatus.DestroyWindow(); if (PD.m_pd.hDC != NULL) { ::DeleteDC(PD.m_pd.hDC); PD.m_pd.hDC = NULL; } }
void CPrint::OnPrint() { if (ParentWnd == NULL) return; // get default print info CPrintInfo printInfo; ASSERT(printInfo.m_pPD != NULL); // must be set /* if (LOWORD(GetCurrentMessage()->wParam) == ID_FILE_PRINT_DIRECT) { CCommandLineInfo* pCmdInfo = AfxGetApp()->m_pCmdInfo; if (pCmdInfo != NULL) { if (pCmdInfo->m_nShellCommand == CCommandLineInfo::FilePrintTo) { printInfo.m_pPD->m_pd.hDC = ::CreateDC(pCmdInfo->m_strDriverName, pCmdInfo->m_strPrinterName, pCmdInfo->m_strPortName, NULL); if (printInfo.m_pPD->m_pd.hDC == NULL) { AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT); return; } } } printInfo.m_bDirect = TRUE; } */ if (OnPreparePrinting(&printInfo)) { // hDC must be set (did you remember to call DoPreparePrinting?) ASSERT(printInfo.m_pPD->m_pd.hDC != NULL); // gather file to print to if print-to-file selected CString strOutput; if (printInfo.m_pPD->m_pd.Flags & PD_PRINTTOFILE && !printInfo.m_bDocObject) { // construct CFileDialog for browsing CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT)); CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT)); CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER)); CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION)); CFileDialog dlg(FALSE, strDef, strPrintDef, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter); dlg.m_ofn.lpstrTitle = strCaption; if (dlg.DoModal() != IDOK) return; // set output device to resulting path name strOutput = dlg.GetPathName(); } // set up document info and start the document printing process DOCINFO docInfo; memset(&docInfo, 0, sizeof(DOCINFO)); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = PrintTitle; CString strPortName; int nFormatID; if (strOutput.IsEmpty()) { docInfo.lpszOutput = NULL; strPortName = printInfo.m_pPD->GetPortName(); nFormatID = AFX_IDS_PRINTONPORT; } else { docInfo.lpszOutput = strOutput; strPortName = "Miracle"; /*AfxGetFileTitle(strOutput, strPortName.GetBuffer(_MAX_PATH), _MAX_PATH);*/ nFormatID = AFX_IDS_PRINTTOFILE; } // setup the printing DC CDC dcPrint; if (!printInfo.m_bDocObject) { dcPrint.Attach(printInfo.m_pPD->m_pd.hDC); // attach printer dc dcPrint.m_bPrinting = TRUE; } OnBeginPrinting(&dcPrint, &printInfo); if (!printInfo.m_bDocObject) dcPrint.SetAbortProc(AbortProc); // disable main window while printing & init printing status dialog AfxGetMainWnd()->EnableWindow(FALSE); CPrintingDialog dlgPrintStatus(ParentWnd); ghwndAbort = dlgPrintStatus.m_hWnd; CString strTemp; dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, PrintTitle); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, printInfo.m_pPD->GetDeviceName()); AfxFormatString1(strTemp, nFormatID, strPortName); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp); dlgPrintStatus.ShowWindow(SW_SHOW); dlgPrintStatus.UpdateWindow(); // start document printing process if (!printInfo.m_bDocObject && dcPrint.StartDoc(&docInfo) == SP_ERROR) { // enable main window before proceeding AfxGetMainWnd()->EnableWindow(TRUE); // cleanup and show error message OnEndPrinting(&dcPrint, &printInfo); dlgPrintStatus.DestroyWindow(); dcPrint.Detach(); // will be cleaned up by CPrintInfo destructor AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT); return; } // Guarantee values are in the valid range UINT nEndPage = printInfo.GetToPage(); UINT nStartPage = printInfo.GetFromPage(); if (nEndPage < printInfo.GetMinPage()) nEndPage = printInfo.GetMinPage(); if (nEndPage > printInfo.GetMaxPage()) nEndPage = printInfo.GetMaxPage(); if (nStartPage < printInfo.GetMinPage()) nStartPage = printInfo.GetMinPage(); if (nStartPage > printInfo.GetMaxPage()) nStartPage = printInfo.GetMaxPage(); int nStep = (nEndPage >= nStartPage) ? 1 : -1; nEndPage = (nEndPage == 0xffff) ? 0xffff : nEndPage + nStep; VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM)); // If it's a doc object, we don't loop page-by-page // because doc objects don't support that kind of levity. BOOL bError = FALSE; // Print Loop // Burada DocObject kýsmý silindi { // begin page printing loop for (printInfo.m_nCurPage = nStartPage; printInfo.m_nCurPage != nEndPage; printInfo.m_nCurPage += nStep) { OnPrepareDC(&dcPrint, &printInfo); // check for end of print if (!printInfo.m_bContinuePrinting) break; // write current page TCHAR szBuf[80]; wsprintf(szBuf, strTemp, printInfo.m_nCurPage); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf); // set up drawing rect to entire page (in logical coordinates) printInfo.m_rectDraw.SetRect(0, 0, dcPrint.GetDeviceCaps(HORZRES), dcPrint.GetDeviceCaps(VERTRES)); dcPrint.DPtoLP(&printInfo.m_rectDraw); // attempt to start the current page if (dcPrint.StartPage() < 0) { DebugMessage("Error on print 2"); bError = TRUE; break; } // must call OnPrepareDC on newer versions of Windows because // StartPage now resets the device attributes. //if (afxData.bMarked4) OnPrepareDC(&dcPrint, &printInfo); ASSERT(printInfo.m_bContinuePrinting); // page successfully started, so now render the page OnPrint(&dcPrint, &printInfo); TRACE("on print\n"); int stat = dcPrint.EndPage(); if (stat < 0 || !AbortProc(dcPrint.m_hDC, 0)) { bError = TRUE; CString str; str.Format("End Page = %ld,Abort = %ld",stat,gbAbort); DebugMessage(str); DebugMessage("Error on print"); break; } } } // cleanup document printing process if (!printInfo.m_bDocObject) { if (!bError) dcPrint.EndDoc(); else dcPrint.AbortDoc(); } AfxGetMainWnd()->EnableWindow(); // enable main window OnEndPrinting(&dcPrint, &printInfo); // clean up after printing dlgPrintStatus.DestroyWindow(); dcPrint.Detach(); // will be cleaned up by CPrintInfo destructor } }
void CELibrarianApp::OnPrintLibrary() { CString pszLibraryName, pszHeaderName; CPrintInfo printInfo; CELibrarianApp * pApp = this; // // get document // CELibrarianDoc* pDoc = (CELibrarianDoc*) GetDocument(); pszLibraryName = pDoc->GetTitle(); // // print dialog // Page selection disabled // printInfo.m_pPD->m_pd.Flags |= PD_NOPAGENUMS; if (IDOK != pApp->DoPrintDialog(printInfo.m_pPD)) { return; // do not print } // print all pages printInfo.m_pPD->m_pd.nToPage = 0xffff; if (NULL == printInfo.m_pPD->m_pd.hDC) { return; } // gather file to print to if print-to-file selected CString strOutput; if (printInfo.m_pPD->m_pd.Flags & PD_PRINTTOFILE) { // construct CFileDialog for browsing CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT)); CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT)); CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER)); CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION)); CFileDialog dlg(FALSE, strDef, strPrintDef, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter); dlg.m_ofn.lpstrTitle = strCaption; if (IDOK != dlg.DoModal()) { return; } // set output device to resulting path name strOutput = dlg.GetPathName(); } // // set up document info and start the document printing process // DOCINFO docInfo; memset(&docInfo, 0, sizeof(DOCINFO)); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = pszLibraryName; CString strPortName; int nFormatID; if (strOutput.IsEmpty()) { docInfo.lpszOutput = NULL; strPortName = printInfo.m_pPD->GetPortName(); nFormatID = AFX_IDS_PRINTONPORT; } else { docInfo.lpszOutput = strOutput; nFormatID = AFX_IDS_PRINTTOFILE; } // // setup the printing DC // CDC dcPrint; dcPrint.Attach(printInfo.m_pPD->m_pd.hDC); // attach printer dc dcPrint.m_bPrinting = TRUE; // // setup status dialog // dcPrint.SetAbortProc(PrjPrintAbortProc); // disable main window while printing & init printing status dialog AfxGetMainWnd()->EnableWindow(FALSE); CPrjPrintDialog dlgPrintStatus(m_pMainWnd); CString strTemp; dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, pszLibraryName); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, printInfo.m_pPD->GetDeviceName()); AfxFormatString1(strTemp, nFormatID, strPortName); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp); dlgPrintStatus.ShowWindow(SW_SHOW); dlgPrintStatus.UpdateWindow(); // // start printing // if (dcPrint.StartDoc(&docInfo) == SP_ERROR) { // enable main window before proceeding AfxGetMainWnd()->EnableWindow(TRUE); // cleanup and show error message dlgPrintStatus.DestroyWindow(); dcPrint.Detach(); // will be cleaned up by CPrintInfo destructor AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT); return; } BOOL bError = FALSE; CPrintUserData UserData; CString strBuffer; printInfo.m_lpUserData = (LPVOID)&UserData; UserData.SetLibraryName(pszLibraryName); // // print list of POU's // //bError = PrintPOUList(&dcPrint, & printInfo); bError = FALSE; // // print all headers pf POU's // /*CELibrary* pCeLibrary = pDoc->GetCELibrary(); int nn = pCeLibrary->GetPOUCount(); CString pouName; for ( int ii=0 ; ii<nn && !bError; ii++) { pouName = pCeLibrary->GetPOUName(ii); if (pouName != ".") { UserData.SetHeaderName(pouName); bError = PrintPOUHeader( pouName, &dcPrint, &printInfo, &dlgPrintStatus); } }*/ if (!bError) dcPrint.EndDoc(); else dcPrint.AbortDoc(); AfxGetMainWnd()->EnableWindow(); // enable main window dlgPrintStatus.DestroyWindow(); dcPrint.Detach(); // will be cleaned up by CPrintInfo destructor return; }
void FrmTrip::filterModel4Combo() { if (!m_sample) return; QSqlQuery query; QString strQuery, strFilter; if (m_sample->bLogBook){ if (m_sample->minorStrataId==-1){ emit showError(tr("Could not identify the stratum of this frame!")); return; } strQuery= "SELECT TOP (100) PERCENT dbo.Ref_Abstract_LandingSite.ID" " FROM dbo.Ref_Minor_Strata INNER JOIN" " dbo.FR_Time ON dbo.Ref_Minor_Strata.id_frame_time = dbo.FR_Time.ID INNER JOIN" " dbo.FR_Frame ON dbo.FR_Time.id_frame = dbo.FR_Frame.ID INNER JOIN" " dbo.FR_Sub_Frame ON dbo.FR_Frame.ID = dbo.FR_Sub_Frame.id_frame INNER JOIN" " dbo.FR_GLS2ALS ON dbo.FR_Sub_Frame.ID = dbo.FR_GLS2ALS.id_sub_frame INNER JOIN" " dbo.Ref_Abstract_LandingSite ON dbo.FR_GLS2ALS.id_abstract_landingsite = dbo.Ref_Abstract_LandingSite.ID" " WHERE (dbo.Ref_Minor_Strata.ID = " + QVariant(m_sample->minorStrataId).toString() + " ) AND (dbo.FR_GLS2ALS.id_gls =" " (SELECT id_gls" " FROM dbo.Ref_Minor_Strata AS Ref_Minor_Strata_1" " WHERE (ID = " + QVariant(m_sample->minorStrataId).toString() + ")))" ;//for getting all the boats on the frame, just remove the last condition query.prepare(strQuery); if (!query.exec()){ emit showError(tr("Could not obtain filter for Landing Sites!")); return; } QString strFilter(""); while (query.next()) { strFilter.append("ID=" + query.value(0).toString()); strFilter.append(" OR "); } if (!strFilter.isEmpty()) strFilter=strFilter.remove(strFilter.size()-QString(" OR ").length(),QString(" OR ").length()); tTrips->relationModel(4)->setFilter(strFilter); }else{ strQuery= "SELECT id_abstract_LandingSite" " FROM dbo.Sampled_Cell" " WHERE (ID = :id)" ; query.prepare(strQuery); if (m_sample->cellId==-1){ emit showError(tr("There is a problem with the type of this frame!")); return; } query.bindValue(0,m_sample->cellId); if (!query.exec() || query.numRowsAffected()!=1){ emit showError(tr("Could not obtain filter for landing sites!")); return; } query.first(); strFilter.append("ID=" + query.value(0).toString()); if (!strFilter.isEmpty()){ tTrips->relationModel(4)->setFilter(strFilter); } } initMapper1(); }
BOOL CMUSHclientDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; SetDefaults (false); // set up numeric/boolean defaults SetAlphaDefaults (false); // set up alpha defaults if (App.m_TypeOfNewDocument == App.eNormalNewDocument) // only ask on normal new world { int i = ::TMessageBox ("Preload world defaults from an existing world?", MB_YESNOCANCEL | MB_ICONQUESTION); if (i == IDCANCEL) return FALSE; if (i == IDYES) while (TRUE) // loop until successful read of file, or cancel { // Get file CString strFilter(MAKEINTRESOURCE(IDS_OPEN_WORLD_FILTER)); CString strTitle(MAKEINTRESOURCE(IDS_OPEN_WORLD_TITLE)); CFileDialog dlg(TRUE, // TRUE for FileOpen NULL, // default extension NULL, // no initial file name OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, strFilter); dlg.m_ofn.lpstrTitle = strTitle; // use default world file directory dlg.m_ofn.lpstrInitialDir = Make_Absolute_Path (App.m_strDefaultWorldFileDirectory); ChangeToFileBrowsingDirectory (); int nResult = dlg.DoModal(); ChangeToStartupDirectory (); if (nResult != IDOK) break; CString strFileName = dlg.GetPathName(); CWaitCursor wait; try { // Open existing world file CFile fileWorld(strFileName, CFile::modeRead|CFile::shareDenyWrite); CArchive ar(&fileWorld, CArchive::load); try { Serialize (ar); } catch(CException* e) { ::TMessageBox ("Unexpected file format - invalid world file", MB_ICONEXCLAMATION); e->Delete(); ar.Close(); continue; } ar.Close(); } catch(CException* e) { ::TMessageBox ("Unable to open world file", MB_ICONEXCLAMATION); e->Delete(); continue; } // if we got here, we successfully loaded the world! SetModifiedFlag (); m_strWorldID = GetUniqueID (); // new world ID break; } // end of preloading defaults } // end of normal new world // if defaults are wanted, overwrite what we loaded with them :) if (m_bLoaded) OnFileReloaddefaults (); else { if (!App.m_strDefaultColoursFile.IsEmpty ()) { m_bUseDefaultColours = true; Load_Set (COLOUR, App.m_strDefaultColoursFile, &Frame); } if (!App.m_strDefaultTriggersFile.IsEmpty ()) { m_bUseDefaultTriggers = true; Load_Set (TRIGGER, App.m_strDefaultTriggersFile, &Frame); } if (!App.m_strDefaultAliasesFile.IsEmpty ()) { m_bUseDefaultAliases = true; Load_Set (ALIAS, App.m_strDefaultAliasesFile, &Frame); } if (!App.m_strDefaultTimersFile.IsEmpty ()) { m_bUseDefaultTimers = true; Load_Set (TIMER, App.m_strDefaultTimersFile, &Frame); } if (!App.m_strDefaultMacrosFile.IsEmpty ()) { m_bUseDefaultMacros = true; Load_Set (MACRO, App.m_strDefaultMacrosFile, &Frame); } if (!App.m_strDefaultInputFont.IsEmpty ()) { m_bUseDefaultInputFont = true; m_input_font_height = App.m_iDefaultInputFontHeight; m_input_font_name = App.m_strDefaultInputFont; m_input_font_italic = App.m_iDefaultInputFontItalic; m_input_font_weight = App.m_iDefaultInputFontWeight; m_input_font_charset = App.m_iDefaultInputFontCharset; } // end of input font override if (!App.m_strDefaultOutputFont.IsEmpty ()) { m_bUseDefaultOutputFont = true; m_font_height = App.m_iDefaultOutputFontHeight; m_font_name = App.m_strDefaultOutputFont; m_font_weight = FW_NORMAL; m_font_charset = App.m_iDefaultOutputFontCharset; } // end of output font override } // end of not loading an existing world m_bLoaded = false; // not really loaded - effectively a new world // get name and IP address, give up if cancelled if (App.m_TypeOfNewDocument == App.eQuickConnect) // pop up nice simple dialog box { CQuickConnectDlg dlg; dlg.m_iPort = 4000; dlg.m_strWorldName = "Untitled world"; dlg.m_strAddress = ""; if (dlg.DoModal () != IDOK) return FALSE; m_server = dlg.m_strAddress; m_port = dlg.m_iPort; m_mush_name = dlg.m_strWorldName; // save auto connect flag, then set to true, to make sure we connect unsigned int savebAutoConnectWorlds = App.m_bAutoConnectWorlds; App.m_bAutoConnectWorlds = TRUE; SetUpOutputWindow (); OpenSession (); App.m_bAutoConnectWorlds = savebAutoConnectWorlds; SetModifiedFlag (); return TRUE; } // end of quick connect if (App.m_TypeOfNewDocument == App.eTelnetFromNetscape) // just do it { // get rid of telnet stuff CString strCommandLine = ::Replace (App.m_lpCmdLine, "telnet://", ""); int iSpace = strCommandLine.FindOneOf (" :"); if (iSpace == -1) { m_server = strCommandLine; m_mush_name = strCommandLine; m_port = 23; } else { m_server = strCommandLine.Left (iSpace); m_mush_name = m_server; m_port = atoi (strCommandLine.Mid (iSpace + 1)); } // save auto connect flag, then set to true, to make sure we connect unsigned int savebAutoConnectWorlds = App.m_bAutoConnectWorlds; App.m_bAutoConnectWorlds = TRUE; SetUpOutputWindow (); OpenSession (); App.m_bAutoConnectWorlds = savebAutoConnectWorlds; SetModifiedFlag (); return TRUE; } // end of telnet called from netscape navigator // we have to do this *before* getting the preferences SetUpOutputWindow (); if (!GamePreferences (ePageGeneral)) return FALSE; if(m_mush_name.IsEmpty ()) { ::TMessageBox("Your world name cannot be blank.", MB_ICONEXCLAMATION); return FALSE; } if(m_server.IsEmpty ()) { ::TMessageBox("The world TCP/IP address cannot be blank.", MB_ICONEXCLAMATION); return FALSE; } OpenSession (); return TRUE; }
void FrmOperation::filterModel4Combo() { if (!m_sample) return; QSqlQuery query; QString strQuery; if (m_sample->tripId==-1){ emit showError(tr("Could not identify the trip for this operation!")); return; } strQuery= "SELECT id_fishing_gear" " FROM dbo.Sampled_Fishing_Trips_Gears" " WHERE (id_fishing_trip = " + QVariant(m_sample->tripId).toString() + ")"; query.prepare(strQuery); if (!query.exec()){ if (query.lastError().type()!=QSqlError::NoError){ emit showError(query.lastError().text()); }else emit showError(tr("Could not obtain filter for gears!")); return; } QString strFilter(""); while (query.next()) { strFilter.append("ID=" + query.value(0).toString()); strFilter.append(" OR "); } if (!strFilter.isEmpty()) strFilter=strFilter.remove(strFilter.size()-QString(" OR ").length(),QString(" OR ").length()); tOperations->relationModel(4)->setFilter(strFilter); strQuery= "SELECT id_fishing_zone" " FROM dbo.Sampled_fishing_trips_zones" " WHERE (id_fishing_trip = " + QVariant(m_sample->tripId).toString() + ")"; query.prepare(strQuery); if (!query.exec()){ if (query.lastError().type()!=QSqlError::NoError){ emit showError(query.lastError().text()); }else emit showError(tr("Could not obtain filter for Zones!")); return; } strFilter=""; while (query.next()) { strFilter.append("ID=" + query.value(0).toString()); strFilter.append(" OR "); } if (!strFilter.isEmpty()) strFilter=strFilter.remove(strFilter.size()-QString(" OR ").length(),QString(" OR ").length()); tOperations->relationModel(18)->setFilter(strFilter); initMapper1(); }
void CView::OnFilePrint() { // get default print info CPrintInfo printInfo; ASSERT(printInfo.m_pPD != NULL); // must be set if (LOWORD(GetCurrentMessage()->wParam) == ID_FILE_PRINT_DIRECT) { CCommandLineInfo* pCmdInfo = AfxGetApp()->m_pCmdInfo; if (pCmdInfo != NULL) { if (pCmdInfo->m_nShellCommand == CCommandLineInfo::FilePrintTo) { printInfo.m_pPD->m_pd.hDC = ::CreateDC(pCmdInfo->m_strDriverName, pCmdInfo->m_strPrinterName, pCmdInfo->m_strPortName, NULL); if (printInfo.m_pPD->m_pd.hDC == NULL) { AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT); return; } } } printInfo.m_bDirect = TRUE; } if (OnPreparePrinting(&printInfo)) { // hDC must be set (did you remember to call DoPreparePrinting?) ASSERT(printInfo.m_pPD->m_pd.hDC != NULL); // gather file to print to if print-to-file selected CString strOutput; if (printInfo.m_pPD->m_pd.Flags & PD_PRINTTOFILE && !printInfo.m_bDocObject) { // construct CFileDialog for browsing CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT)); CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT)); CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER)); CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION)); CFileDialog dlg(FALSE, strDef, strPrintDef, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter, NULL, 0); dlg.m_ofn.lpstrTitle = strCaption; if (dlg.DoModal() != IDOK) return; // set output device to resulting path name strOutput = dlg.GetPathName(); } // set up document info and start the document printing process CString strTitle; CDocument* pDoc = GetDocument(); if (pDoc != NULL) strTitle = pDoc->GetTitle(); else EnsureParentFrame()->GetWindowText(strTitle); DOCINFO docInfo; memset(&docInfo, 0, sizeof(DOCINFO)); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = strTitle; CString strPortName; if (strOutput.IsEmpty()) { docInfo.lpszOutput = NULL; strPortName = printInfo.m_pPD->GetPortName(); } else { docInfo.lpszOutput = strOutput; AfxGetFileTitle(strOutput, strPortName.GetBuffer(_MAX_PATH), _MAX_PATH); } // setup the printing DC CDC dcPrint; if (!printInfo.m_bDocObject) { dcPrint.Attach(printInfo.m_pPD->m_pd.hDC); // attach printer dc dcPrint.m_bPrinting = TRUE; } OnBeginPrinting(&dcPrint, &printInfo); if (!printInfo.m_bDocObject) dcPrint.SetAbortProc(_AfxAbortProc); // disable main window while printing & init printing status dialog // Store the Handle of the Window in a temp so that it can be enabled // once the printing is finished CWnd * hwndTemp = AfxGetMainWnd(); hwndTemp->EnableWindow(FALSE); CPrintingDialog dlgPrintStatus(this); CString strTemp; dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, strTitle); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, printInfo.m_pPD->GetDeviceName()); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strPortName); dlgPrintStatus.ShowWindow(SW_SHOW); dlgPrintStatus.UpdateWindow(); // start document printing process if (!printInfo.m_bDocObject) { printInfo.m_nJobNumber = dcPrint.StartDoc(&docInfo); if (printInfo.m_nJobNumber == SP_ERROR) { // enable main window before proceeding hwndTemp->EnableWindow(TRUE); // cleanup and show error message OnEndPrinting(&dcPrint, &printInfo); dlgPrintStatus.DestroyWindow(); dcPrint.Detach(); // will be cleaned up by CPrintInfo destructor AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT); return; } } // Guarantee values are in the valid range UINT nEndPage = printInfo.GetToPage(); UINT nStartPage = printInfo.GetFromPage(); if (nEndPage < printInfo.GetMinPage()) nEndPage = printInfo.GetMinPage(); if (nEndPage > printInfo.GetMaxPage()) nEndPage = printInfo.GetMaxPage(); if (nStartPage < printInfo.GetMinPage()) nStartPage = printInfo.GetMinPage(); if (nStartPage > printInfo.GetMaxPage()) nStartPage = printInfo.GetMaxPage(); int nStep = (nEndPage >= nStartPage) ? 1 : -1; nEndPage = (nEndPage == 0xffff) ? 0xffff : nEndPage + nStep; VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM)); // If it's a doc object, we don't loop page-by-page // because doc objects don't support that kind of levity. BOOL bError = FALSE; if (printInfo.m_bDocObject) { OnPrepareDC(&dcPrint, &printInfo); OnPrint(&dcPrint, &printInfo); } else { // begin page printing loop for (printInfo.m_nCurPage = nStartPage; printInfo.m_nCurPage != nEndPage; printInfo.m_nCurPage += nStep) { OnPrepareDC(&dcPrint, &printInfo); // check for end of print if (!printInfo.m_bContinuePrinting) break; // write current page TCHAR szBuf[80]; ATL_CRT_ERRORCHECK_SPRINTF(_sntprintf_s(szBuf, _countof(szBuf), _countof(szBuf) - 1, strTemp, printInfo.m_nCurPage)); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf); // set up drawing rect to entire page (in logical coordinates) printInfo.m_rectDraw.SetRect(0, 0, dcPrint.GetDeviceCaps(HORZRES), dcPrint.GetDeviceCaps(VERTRES)); dcPrint.DPtoLP(&printInfo.m_rectDraw); // attempt to start the current page if (dcPrint.StartPage() < 0) { bError = TRUE; break; } // must call OnPrepareDC on newer versions of Windows because // StartPage now resets the device attributes. OnPrepareDC(&dcPrint, &printInfo); ASSERT(printInfo.m_bContinuePrinting); // page successfully started, so now render the page OnPrint(&dcPrint, &printInfo); // If the user restarts the job when it's spooling, all // subsequent calls to EndPage returns < 0. The first time // GetLastError returns ERROR_PRINT_CANCELLED if (dcPrint.EndPage() < 0 && (GetLastError()!= ERROR_SUCCESS)) { HANDLE hPrinter; if (!OpenPrinter(LPTSTR(printInfo.m_pPD->GetDeviceName().GetBuffer()), &hPrinter, NULL)) { bError = TRUE; break; } DWORD cBytesNeeded; if(!GetJob(hPrinter,printInfo.m_nJobNumber,1,NULL,0,&cBytesNeeded)) { if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { bError = TRUE; break; } } JOB_INFO_1 *pJobInfo; if((pJobInfo = (JOB_INFO_1 *)malloc(cBytesNeeded))== NULL) { bError = TRUE; break; } DWORD cBytesUsed; BOOL bRet = GetJob(hPrinter,printInfo.m_nJobNumber,1,LPBYTE(pJobInfo),cBytesNeeded,&cBytesUsed); DWORD dwJobStatus = pJobInfo->Status; free(pJobInfo); pJobInfo = NULL; // if job status is restart, just continue if(!bRet || !(dwJobStatus & JOB_STATUS_RESTART) ) { bError = TRUE; break; } } if(!_AfxAbortProc(dcPrint.m_hDC, 0)) { bError = TRUE; break; } } } // cleanup document printing process if (!printInfo.m_bDocObject) { if (!bError) dcPrint.EndDoc(); else dcPrint.AbortDoc(); } hwndTemp->EnableWindow(); // enable main window OnEndPrinting(&dcPrint, &printInfo); // clean up after printing dlgPrintStatus.DestroyWindow(); dcPrint.Detach(); // will be cleaned up by CPrintInfo destructor } }
void processPNG(unsigned char* buffer, long lSize, int verbose) { int cur = 0; unsigned char strBuffer[LEN_STR]; printf("\n0x%08X\tpng-signature=", cur); getBytes(buffer, cur, LEN_PNGSIG); puts(""); cur += LEN_PNGSIG; while (cur < lSize) { // Print (LENGTH, TYPE, CRC) for each. long length = getNum(buffer, cur, LEN_CKLENGTH); printf("\n0x%08X\tchunk-length=0x%08lX\t(%ld)", cur, length, length); // CHUNK LENGTH cur += LEN_CKLENGTH; unsigned char type[LEN_HDR]; grabString(buffer, cur, LEN_CKTYPE, type); printf("\n0x%08X\tchunk-type=\'%s\'", cur, type); // CHUNK TYPE int crcBegin = cur; cur += LEN_CKTYPE; if (verbose && (strcmp((char*)type, "IHDR") == 0)) { //if verbose, print expanded IHDR long width = getNum(buffer, cur, LEN_WIDTH); printf("\n0x%08X\twidth=0x%08lX\t(%ld)", cur, width, width); cur += LEN_WIDTH; long height = getNum(buffer, cur, LEN_HEIGHT); printf("\n0x%08X\theight=0x%08lX\t(%ld)", cur, height, height); cur += LEN_HEIGHT; printf("\n0x%08X\tbit-depth=%ld", cur, getNum(buffer, cur, LEN_BITDEPTH)); cur += LEN_BITDEPTH; long colorType = getNum(buffer, cur, LEN_COLORTYPE); strColorType(colorType, strBuffer); // Stores type description in strBuffer printf("\n0x%08X\tcolor-type=%ld \t(%s)", cur, colorType, strBuffer); cur += LEN_COLORTYPE; long compressMethod = getNum(buffer, cur, LEN_COMPRESS); strCompress(compressMethod, strBuffer); printf("\n0x%08X\tcompression-method=%ld \t(%s)", cur, compressMethod, strBuffer); cur += LEN_COMPRESS; long filterMethod = getNum(buffer, cur, LEN_FILTER); strFilter(filterMethod, strBuffer); printf("\n0x%08X\tfilter-method=%ld \t(%s)", cur, filterMethod, strBuffer); cur += LEN_FILTER; long interlaceMethod = getNum(buffer, cur, LEN_INTERLACE); strInterlace(interlaceMethod, strBuffer); printf("\n0x%08X\tinterlace-method=%ld \t(%s)", cur, interlaceMethod, strBuffer); cur += LEN_INTERLACE; } int crcLen = LEN_CKTYPE + length; unsigned char crcInput[crcLen]; grabBytes(buffer, crcBegin, crcLen, crcInput); cur = crcBegin + crcLen; long crcCode = getNum(buffer, cur, LEN_CRC); long crcComputed = crc(crcInput, crcLen); char* crcResult = "CRC FAILED"; if (crcCode == crcComputed) crcResult = "CRC OK!"; printf("\n0x%08X\tcrc-code=0x%08lX", cur, crcCode); printf("\n>> (CRC CHECK) crc-computed=0x%08lX \t=>\t%s\n\n", crcComputed, crcResult); cur += LEN_CRC; } }
int main() { signal(SIGINT, &prohandler); signal(SIGTERM, &prohandler); /** Allocation of the arguments' array */ char** argumentArray = (char**) malloc(sizeof(char*) * NUM_OF_ARGS); int i=0; for(i=0;i<NUM_OF_ARGS;i++) { argumentArray[i] = (char*) malloc(sizeof(char) * MAX_ARG_SIZE); } /** Allocation of the input command array */ char* command = malloc(MAX_COMMAND_SIZE); if (command == NULL) { printf("No memory \n"); return 1; } /** Allocation of the home path array */ char* home = malloc(1024); if (home == NULL) { printf("No memory \n"); return 1; } /** End of allocations */ /****************************************** MAIN LOOP ********************************************************************/ /**************************************************************************************************************************/ //Like a normal shell - user@hostname struct passwd *p = getpwuid(getuid()); // Check for NULL! char hostname[HOST_NAME_MAX+1]; while(1) { /** * Shell waiting for input. If you just press enter, or enter something starting with a whitespace, the shell will ask for * new entry. If Ctrl-C is pressed while in the loop, the loop breaks. */ do { //printf("User name: %s\n", p->pw_name); gethostname(hostname, sizeof(hostname)); // Check the return value! //printf("Host name: %s\n", hostname); //fprintf(stdout, KRED "SuperHackingShell:" RESET); fprintf(stdout, KCYN "%s" RESET "@" KGRN "%s:" RESET,p->pw_name,hostname); printDir(); fprintf(stdout, KNRM "$ " RESET); fgets(command, MAX_COMMAND_SIZE, stdin); }while(strFilter(command)==0 ); /** Check for exit command */ if (stringCompare(command,"exit")) break; /** Parsing */ int args = cmdParser(command, argumentArray, NUM_OF_ARGS); //args contains the number of arguments the command contained. /** Executing programs and commands - if no cd command given */ if(cd(argumentArray) != 0) { /** Check for background execution */ if( *argumentArray[args-1] == 38) //if last argument of command is "&"(38), execute in background { *argumentArray[args-1] = 0; //doesn't appear to create problems NOPE: me ls -l & peos //prepei na kopsw to teleutaio argument //printf("%s %s",argumentArray[0],argumentArray[1]);//tsekarei an to ekopse cmdExecBack(argumentArray); } /** Normal execution */ else cmdExecute(argumentArray); } } fprintf(stdout, KRED"<1337>...SuperHackingShell...exiting... <1337> \n" RESET); free(command); free(argumentArray); exit(0); }
static void PrintCatalogThread (CWnd* pParent, CFrameWndEx* pMainFrame) { CCADView* pView = (CCADView*)pMainFrame->GetActiveView(); CPrintDialog* PD = new CPrintDialog(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOSELECTION|PD_ENABLEPRINTHOOK, pParent); lcPiecesLibrary *pLib = lcGetPiecesLibrary(); int bricks = 0; for (int j = 0; j < pLib->mPieces.GetSize(); j++) if (pLib->mPieces[j]->m_strDescription[0] != '~') bricks++; int rows = theApp.GetProfileInt("Default", "Catalog Rows", 10); int cols = theApp.GetProfileInt("Default", "Catalog Columns", 3); PD->m_pd.lpfnPrintHook = PrintHookProc; PD->m_pd.nFromPage = PD->m_pd.nMinPage = 1; PD->m_pd.nMaxPage = bricks/(rows*cols); if (bricks%(rows*cols) != 0) PD->m_pd.nMaxPage++; PD->m_pd.nToPage = PD->m_pd.nMaxPage; PD->m_pd.lCustData= (LONG)pMainFrame; // bring up the print dialog and allow user to change things if (theApp.DoPrintDialog(PD) != IDOK) return; if (PD->m_pd.hDC == NULL) return; // update page range rows = theApp.GetProfileInt("Default","Catalog Rows", 10); cols = theApp.GetProfileInt("Default","Catalog Columns", 3); PD->m_pd.nMaxPage = bricks/(rows*cols); if (bricks%(rows*cols) != 0) PD->m_pd.nMaxPage++; // gather file to print to if print-to-file selected CString strOutput; if (PD->m_pd.Flags & PD_PRINTTOFILE) { // construct CFileDialog for browsing CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT)); CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT)); CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER)); CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION)); CFileDialog dlg(FALSE, strDef, strPrintDef, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter); dlg.m_ofn.lpstrTitle = strCaption; if (dlg.DoModal() != IDOK) return; // set output device to resulting path name strOutput = dlg.GetPathName(); } DOCINFO docInfo; memset(&docInfo, 0, sizeof(DOCINFO)); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = "LeoCAD pieces catalog"; CString strPortName; int nFormatID; if (strOutput.IsEmpty()) { docInfo.lpszOutput = NULL; strPortName = PD->GetPortName(); nFormatID = AFX_IDS_PRINTONPORT; } else { docInfo.lpszOutput = strOutput; AfxGetFileTitle(strOutput, strPortName.GetBuffer(_MAX_PATH), _MAX_PATH); nFormatID = AFX_IDS_PRINTTOFILE; } // setup the printing DC SetAbortProc(PD->m_pd.hDC, _AfxAbortProc); // disable main window while printing & init printing status dialog pParent->EnableWindow(FALSE); CPrintingDialog dlgPrintStatus(NULL); CString strTemp; dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, "LeoCAD parts catalog"); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, PD->GetDeviceName()); AfxFormatString1(strTemp, nFormatID, strPortName); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp); dlgPrintStatus.ShowWindow(SW_SHOW); dlgPrintStatus.UpdateWindow(); // start document printing process if (StartDoc(PD->m_pd.hDC, &docInfo) == SP_ERROR) { pParent->EnableWindow(TRUE); dlgPrintStatus.DestroyWindow(); AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT); return; } // Guarantee values are in the valid range UINT nEndPage = PD->m_pd.nToPage; UINT nStartPage = PD->m_pd.nFromPage; if (PD->PrintAll()) { nEndPage = PD->m_pd.nMaxPage; nStartPage = PD->m_pd.nMinPage; } if (nEndPage < PD->m_pd.nMinPage) nEndPage = PD->m_pd.nMinPage; if (nEndPage > PD->m_pd.nMaxPage) nEndPage = PD->m_pd.nMaxPage; if (nStartPage < PD->m_pd.nMinPage) nStartPage = PD->m_pd.nMinPage; if (nStartPage > PD->m_pd.nMaxPage) nStartPage = PD->m_pd.nMaxPage; int nStep = (nEndPage >= nStartPage) ? 1 : -1; nEndPage = nEndPage + nStep; VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM)); // begin page printing loop BOOL bError = FALSE; // set up drawing rect to entire page (in logical coordinates) CRect rectDraw (0, 0, GetDeviceCaps(PD->m_pd.hDC, HORZRES), GetDeviceCaps(PD->m_pd.hDC, VERTRES)); DPtoLP(PD->m_pd.hDC, (LPPOINT)(RECT*)&rectDraw, 2); rectDraw.DeflateRect( GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSX)*theApp.GetProfileInt("Default","Margin Left", 50)/100, GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Top", 50)/100, GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSX)*theApp.GetProfileInt("Default","Margin Right", 50)/100, GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Bottom", 50)/100); int w = rectDraw.Width()/cols; int h = rectDraw.Height()/rows; // Creating Compatible Memory Device Context CDC *pMemDC = new CDC; if (!pMemDC->CreateCompatibleDC(pView->GetDC())) return; // Preparing bitmap header for DIB section BITMAPINFO bi; ZeroMemory(&bi, sizeof(BITMAPINFO)); bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bi.bmiHeader.biWidth = w; bi.bmiHeader.biHeight = h; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 24; bi.bmiHeader.biCompression = BI_RGB; bi.bmiHeader.biSizeImage = w * h * (24/8); bi.bmiHeader.biXPelsPerMeter = 2925; bi.bmiHeader.biYPelsPerMeter = 2925; bi.bmiHeader.biClrUsed = 0; bi.bmiHeader.biClrImportant = 0; LPBITMAPINFOHEADER lpbi[1]; // Creating a DIB surface HBITMAP hBm, hBmOld; hBm = CreateDIBSection(pView->GetDC()->GetSafeHdc(), &bi, DIB_RGB_COLORS, (void **)&lpbi, NULL, (DWORD)0); if (!hBm) return; // Selecting the DIB Surface hBmOld = (HBITMAP)::SelectObject(pMemDC->GetSafeHdc(), hBm); if (!hBmOld) return; // Setting up a Pixel format for the DIB surface PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1,PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI, PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; int pixelformat = ChoosePixelFormat(pMemDC->m_hDC, &pfd); DescribePixelFormat(pMemDC->m_hDC, pixelformat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); SetPixelFormat(pMemDC->m_hDC, pixelformat, &pfd); // Creating a OpenGL context HGLRC hmemrc = wglCreateContext(pMemDC->GetSafeHdc()); // Setting up the current OpenGL context GL_DisableVertexBufferObject(); wglMakeCurrent(pMemDC->GetSafeHdc(), hmemrc); double aspect = (float)w/(float)h; glMatrixMode(GL_MODELVIEW); glViewport(0, 0, w, h); // Sort pieces by description struct BRICKSORT { char name[64]; int actual; struct BRICKSORT *next; } start, *node, *previous, *news; start.next = NULL; for (int j = 0; j < pLib->mPieces.GetSize(); j++) { char* desc = pLib->mPieces[j]->m_strDescription; if (desc[0] != '~') continue; // Find the correct location previous = &start; node = start.next; while ((node) && (strcmp(desc, node->name) > 0)) { node = node->next; previous = previous->next; } news = (struct BRICKSORT*) malloc(sizeof(struct BRICKSORT)); news->next = node; previous->next = news; strcpy(news->name, desc); news->actual = j; } node = start.next; if (PD->PrintRange()) { for (int j = 0; j < (int)(nStartPage - 1)*rows*cols; j++) if (node) node = node->next; } LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = -MulDiv(12, GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY), 72); lf.lfWeight = FW_REGULAR; lf.lfCharSet = DEFAULT_CHARSET; lf.lfQuality = PROOF_QUALITY; strcpy (lf.lfFaceName , "Arial"); HFONT HeaderFont = CreateFontIndirect(&lf); HFONT OldFont = (HFONT)SelectObject(PD->m_pd.hDC, HeaderFont); SetBkMode(PD->m_pd.hDC, TRANSPARENT); SetTextColor(PD->m_pd.hDC, 0x000000); SetTextAlign (PD->m_pd.hDC, TA_TOP|TA_LEFT|TA_NOUPDATECP); SetTextColor (pMemDC->m_hDC, 0x000000); lf.lfHeight = -MulDiv(10, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72); lf.lfWeight = FW_BOLD; HFONT CatalogFont = CreateFontIndirect(&lf); HFONT OldMemFont = (HFONT)SelectObject(pMemDC->m_hDC, CatalogFont); HPEN hpOld = (HPEN)SelectObject(pMemDC->m_hDC,(HPEN)GetStockObject(BLACK_PEN)); for (UINT nCurPage = nStartPage; nCurPage != nEndPage; nCurPage += nStep) { // write current page TCHAR szBuf[80]; wsprintf(szBuf, strTemp, nCurPage); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf); // attempt to start the current page if (StartPage(PD->m_pd.hDC) < 0) { bError = TRUE; break; } int printed = 0; // page successfully started, so now render the page for (int r = 0; r < rows; r++) for (int c = 0; c < cols; c++) { if (node == NULL) continue; printed++; glDepthFunc(GL_LEQUAL); glClearColor(1,1,1,1); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glDisable(GL_DITHER); glShadeModel(GL_FLAT); lcSetColor(lcGetActiveProject()->GetCurrentColor()); // dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, node->name); node = node->next; PieceInfo* pInfo = pLib->mPieces[node->actual]; pInfo->ZoomExtents(30.0f, (float)aspect); float pos[4] = { 0, 0, 10, 0 }; glLightfv(GL_LIGHT0, GL_POSITION, pos); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); FillRect(pMemDC->m_hDC, CRect(0,h,w,0), (HBRUSH)GetStockObject(WHITE_BRUSH)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); pInfo->RenderPiece(lcGetActiveProject()->GetCurrentColor()); glFlush(); TextOut (pMemDC->m_hDC, 5, 5, pInfo->m_strDescription, strlen(pInfo->m_strDescription)); // BitBlt(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), w, h, pMemDC->m_hDC, 0, 0, SRCCOPY); LPBITMAPINFOHEADER lpbi[1]; lpbi[0] = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hBm, 24)); BITMAPINFO bi; ZeroMemory(&bi, sizeof(BITMAPINFO)); memcpy (&bi.bmiHeader, lpbi[0], sizeof(BITMAPINFOHEADER)); SetStretchBltMode(PD->m_pd.hDC, COLORONCOLOR); StretchDIBits(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), w, h, 0, 0, w, h, (LPBYTE) lpbi[0] + lpbi[0]->biSize + lpbi[0]->biClrUsed * sizeof(RGBQUAD), &bi, DIB_RGB_COLORS, SRCCOPY); if (lpbi[0]) GlobalFreePtr(lpbi[0]); } DWORD dwPrint = theApp.GetProfileInt("Settings","Print", PRINT_NUMBERS|PRINT_BORDER); if (dwPrint & PRINT_BORDER) for (int r = 0; r < rows; r++) for (int c = 0; c < cols; c++) { if (printed == 0) continue; printed--; if (r == 0) { MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), NULL); LineTo(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*r)); } if (c == 0) { MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), NULL); LineTo(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*(r+1))); } MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*r), NULL); LineTo(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*(r+1))); MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*(r+1)), NULL); LineTo(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*(r+1))); } CRect r2 = rectDraw; r2.top -= GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Top", 50)/200; r2.bottom += GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Bottom", 50)/200; pView->PrintHeader(FALSE, PD->m_pd.hDC, r2, nCurPage, nEndPage, TRUE); pView->PrintHeader(TRUE, PD->m_pd.hDC, r2, nCurPage, nEndPage, TRUE); if (EndPage(PD->m_pd.hDC) < 0 || !_AfxAbortProc(PD->m_pd.hDC, 0)) { bError = TRUE; break; } } SelectObject(pMemDC->m_hDC, hpOld); SelectObject(PD->m_pd.hDC, OldFont); DeleteObject(HeaderFont); SelectObject(pMemDC->m_hDC, OldMemFont); DeleteObject(CatalogFont); node = start.next; while (node) { previous = node; node = node->next; free(previous); } GL_EnableVertexBufferObject(); wglMakeCurrent(NULL, NULL); wglDeleteContext(hmemrc); SelectObject(pMemDC->GetSafeHdc(), hBmOld); DeleteObject(hBm); delete pMemDC; // cleanup document printing process if (!bError) EndDoc(PD->m_pd.hDC); else AbortDoc(PD->m_pd.hDC); pParent->EnableWindow(); dlgPrintStatus.DestroyWindow(); if (PD != NULL && PD->m_pd.hDC != NULL) { ::DeleteDC(PD->m_pd.hDC); PD->m_pd.hDC = NULL; } delete PD; }