void CMultiMoveClientDlg::init_client() { ioCtx_t ctx; ctx.on_error = __error_func; ctx.on_print = __print_func; ctx.ctx = (void*)this; cmInit_t cm_init; cm_init.io_ctx = ctx; cliInit_t init; init.ctx = (void*)this; init.hide_cursor = ::LoadCursor(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_CURSOR_BLANK)); init.on_notify = __client_notify; clientInit_t client_init; client_init.cm_init = cm_init; client_init.cli_init = init; if(!Client_Init(&client_init)) { AfxAbort(); } if(!Cli_Start()) { AfxAbort(); } }
void CStcGroup::CopyDataValues( StcDataValues *pDV, HGLOBAL nValues, DWORD nValuesSize ) { char * pnVal = (char *)GlobalLock(nValues); if ( pnVal == NULL ) { AfxMessageBox("GlobalLock Fails: CStcGroup::CopyVars 1" ); AfxAbort(); } pDV->Values = GlobalAlloc( GMEM_FLAG, nValuesSize ); pDV->ValuesSize = nValuesSize; if ( pDV->Values == NULL ) { AfxMessageBox("GlobalAlloc Fails: CStcGroup::CopyVars 2" ); AfxAbort(); } char *pVal = (char *)GlobalLock(pDV->Values); if ( pVal == NULL ) { AfxMessageBox("GlobalLock Fails: CStcGroup::CopyVars 3" ); AfxAbort(); } while ( nValuesSize-- ) { *pVal++ = *pnVal++; } GlobalUnlock(nValues); GlobalUnlock(pDV->Values); }
void CMultiMoveClientDlg::uninit_cliet() { SystemParametersInfo(SPI_SETCURSORS,0,0,WM_SETTINGCHANGE | SPIF_UPDATEINIFILE ); if(!Cli_Stop()) { AfxAbort(); } if(!Client_UnInit()) { AfxAbort(); } }
// Create an element of the current type CElement* CMDIView::CreateElement(void) const { // Get a pointer to the document for this view CMDIDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // Verify the pointer is good // Get the current element color COLORREF color = static_cast<COLORREF>(pDoc->GetElementColor()); // Now select the element using the type stored in the document switch(pDoc->GetElementType()) { case ElementType::RECTANGLE: return new CRectangle(m_FirstPoint, m_SecondPoint, color); case ElementType::CIRCLE: return new CCircle(m_FirstPoint, m_SecondPoint, color); case ElementType::CURVE: return new CCurve(m_FirstPoint, m_SecondPoint, color); case ElementType::LINE: return new CLine(m_FirstPoint, m_SecondPoint, color); case ElementType::ELLIPSE: return new CEllipse(m_FirstPoint, m_SecondPoint, color); default: // Something's gone wrong AfxMessageBox(_T("Bad Element code"), MB_OK); AfxAbort(); return nullptr; } }
CElement* CSketcherView::CreateElement(void) const { // Get a pointer to the document for this view CSketcherDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // Verify the pointer is good // Now select the element using the type stored in the document switch(pDoc->GetElementType()) { case RECTANGLE: return new CRectangle(m_FirstPoint, m_SecondPoint,pDoc->GetElementColor(),pDoc->GetElementPenStyle()); case CIRCLE: return new CCircle(m_FirstPoint, m_SecondPoint, pDoc->GetElementColor(),pDoc->GetElementPenStyle()); case CURVE: return new CCurve(new CPoint(m_FirstPoint), new CPoint(m_SecondPoint), pDoc->GetElementColor(),pDoc->GetElementPenStyle()); case LINE: return new CLine(m_FirstPoint, m_SecondPoint, pDoc->GetElementColor(),pDoc->GetElementPenStyle()); case ELLIPSE: return new CEllipse(m_FirstPoint, m_SecondPoint, pDoc->GetElementColor(),pDoc->GetElementPenStyle()); default: // Something's gone wrong AfxMessageBox(_T("Bad Element code"), MB_OK); AfxAbort(); return nullptr; } }
// Draw a curve void CCurve::Draw(CDC* pDC, CElement* pElement) { // Create a pen for this object and // initialize it to the object color and line width of 1 pixel CPen aPen; COLORREF aColor = m_Color; // Initialize with element color if(this == pElement) // This element selected? aColor = SELECT_COLOR; // Set highlight color if(!aPen.CreatePen(PS_SOLID, m_Pen, aColor)) { // Pen creation failed. Close the program AfxMessageBox(_T("Pen creation failed drawing a curve"), MB_OK); AfxAbort(); } CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen // Now draw the curve // Get the position in the list of the first element POSITION aPosition = m_PointPtrList.GetHeadPosition(); // As long as it's good, move to that point if(aPosition) pDC->MoveTo(*m_PointPtrList.GetNext(aPosition)); // Draw a segment for each of the following points while(aPosition) pDC->LineTo(*m_PointPtrList.GetNext(aPosition)); pDC->SelectObject(pOldPen); // Restore the old pen }
// Draw a curve void CCurve::Draw(CDC* pDC, CElement* pElement) { // Create a pen for this object and // initialize it to the object color and line width of m_PenWidth CPen aPen; if(!aPen.CreatePen(m_LineStyle, m_PenWidth, this==pElement ? SELECT_COLOR : m_Color)) { // Pen creation failed AfxMessageBox(_T("Pen creation failed drawing a curve"), MB_OK); AfxAbort(); } // Select the pen CPen* pOldPen = pDC->SelectObject(& aPen); // Now draw the curve //pDC->MoveTo(m_Points[0]); pDC->MoveTo(m_APoints[0]); /* for(size_t i=1; i<m_Points.size(); ++i) { pDC->LineTo(m_Points[i]); } */ for(int i=1; i<m_APoints.GetSize(); ++i) { pDC->LineTo(m_APoints[i]); } pDC->SelectObject(pOldPen); // Restore the old pen }
// Draw a circle void CCircle::Draw(CDC* pDC, CElement* pElement) { // Create a pen for this object and // initialize it to the object color and line width of 1 pixel CPen aPen; COLORREF aColor = m_Color; // Initialize with element color if(this == pElement) // This element selected? aColor = SELECT_COLOR; // Set highlight color if(!aPen.CreatePen(PS_SOLID, m_Pen, aColor)) { // Pen creation failed AfxMessageBox(_T("Pen creation failed drawing a circle"), MB_OK); AfxAbort(); } CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen // Select a null brush CBrush* pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH); // Now draw the circle pDC->Ellipse(m_EnclosingRect); pDC->SelectObject(pOldPen); // Restore the old pen pDC->SelectObject(pOldBrush); // Restore the old brush }
// Draw a circle void CEllipse::Draw(CDC* pDC, CElement* pElement) { // Create a pen for this object and // initialize it to the object color and line width of m_PenWidth CPen aPen; if(!aPen.CreatePen(m_LineStyle, m_PenWidth, this==pElement ? SELECT_COLOR : m_Color)) { // Pen creation failed AfxMessageBox(_T("Pen creation failed drawing a circle"), MB_OK); AfxAbort(); } // Select the pen CPen* pOldPen = pDC->SelectObject(& aPen); // Select a null brush CBrush* pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH); // Now draw the circle pDC->Ellipse(m_EnclosingRect); pDC->SelectObject(pOldPen); // Restore the old pen pDC->SelectObject(pOldBrush); // Restore the old brush }
CCPUID::CCPUID() { if (!CPUIDSupported()) { AfxMessageBox("CPUID不被支持,程序即将退出"); AfxAbort(); } }
//=--------------------------------------------------------------------------= // CImp_DrawDlg::HandleErrors //=--------------------------------------------------------------------------= // Purpose: This function pops up an error dialog box and aborts further execution. // // // Parameters: // _com_error // // Output: // none // // Notes: // This function demonstrates how to pull an HRESULT from the _com_error class. // void CImp_DrawDlg::HandleErrors(_com_error &comerr) { HRESULT hr = comerr.Error(); char szErr[30] = ""; _itoa_s(hr, szErr, sizeof(szErr), 16); CString tempString = "The method returned the error code 0x"; tempString += szErr; tempString += ". Exiting."; MessageBox(tempString, NULL, MB_ICONSTOP | MB_OK); AfxAbort(); };
void CStcGroup::CopyResidues( HGLOBAL nResidues, DWORD nResiduesSize ) { if ( nResidues != NULL ) { char * pnRes = (char *)GlobalLock(nResidues); if ( pnRes == NULL ) { AfxMessageBox("GlobalLock Fails: CStcGroup::CopyVars 1" ); AfxAbort(); } m_Residues = GlobalAlloc( GMEM_FLAG, nResiduesSize ); m_ResiduesSize = nResiduesSize; if ( m_Residues == NULL ) { AfxMessageBox("GlobalAlloc Fails: CStcGroup::CopyVars 2" ); AfxAbort(); } char *pRes = (char *)GlobalLock(m_Residues); if ( pRes == NULL ) { AfxMessageBox("GlobalLock Fails: CStcGroup::CopyVars 3" ); AfxAbort(); } while ( nResiduesSize-- ) { *pRes++ = *pnRes++; } GlobalUnlock(nResidues); GlobalUnlock(m_Residues); } else { m_Residues = NULL; m_ResiduesSize = 0; } }
TorrentCreator::TorrentCreator() : m_pIPData(NULL), m_nLastAutoID(0), m_pInfoBuffer(NULL), m_nInfoBufferSize(0) { seedRand(); // Open the temp buffer file if( !m_tempOutputFile.Open( "\\BTTorrentGenerator\\OutputData.tmp", CFile::modeCreate | CFile::modeReadWrite | CFile::shareDenyWrite ) ) { TRACE( "Error opening \"\\BTTorrentGenerator\\OutputData.tmp\" temp buffer file\n" ); MessageBox( NULL, "Error opening\n\"c:\\BTTorrentGenerator\\OutputData.tmp\"\ntemp buffer file", "No Temp File", MB_ICONEXCLAMATION | MB_OK ); AfxAbort(); return; } // Open the data file that is used to generate hashes, if it is not open already if( !m_decoyDataFile.Open( "\\syncher\\rcv\\plug-ins\\BTTorrentGenerator\\TorrentDecoyFile", CFile::modeRead | CFile::shareDenyWrite ) ) { TRACE( "Error opening input decoy data file\n" ); MessageBox( NULL, "Could not open decoy data file", "No Data File", MB_ICONEXCLAMATION | MB_OK ); AfxAbort(); return; } }
BOOL AFXAPI AfxAssertFailedLine( LPCSTR lpszFileName, int nLine ) /***************************************************************/ { CString strMessage( _T("Assertion failed!\n\nFile: ") ); strMessage += lpszFileName; strMessage.AppendFormat( _T("\nLine: %d\n\n"), nLine ); strMessage += _T("Select Abort to terminate the program.\n"); strMessage += _T("Select Retry to debug.\n"); strMessage += _T("Select Ignore to continue execution."); int nResult = ::MessageBox( NULL, strMessage, NULL, MB_ABORTRETRYIGNORE ); if( nResult == IDABORT ) { AfxAbort(); } else if( nResult == IDRETRY ) { return( TRUE ); } return( FALSE ); }
void CCell::Draw_Line(CDC* pDC, CPoint StartPos, CPoint EndPos) const { CPen aPen; if(!aPen.CreatePen(PS_DOT, m_nPenWidth, m_clrColor)) { // Pen creation failed. Close the program AfxMessageBox("Pen creation failed drawing a curve", MB_OK); AfxAbort(); } CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen pDC->MoveTo(StartPos); pDC->LineTo(EndPos); pDC->SelectObject(pOldPen); // Restore the old pen }
// ---------------------------------------------------------------------------- // 2006-10-23 오전 3:43:27 추가(New), Sun.H.D // 호출 시점 : Dotted Line // // 특 징 : // // 매개 변수 : // // 리 턴 값 : // ---------------------------------------------------------------------------- void CDottedLine::Draw(CDC* pDC) { CPen aPen; if(!aPen.CreatePen(PS_DOT, 1, m_clrColor)) { // Pen creation failed. Close the program AfxMessageBox("Pen creation failed drawing a curve", MB_OK); AfxAbort(); } CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen pDC->MoveTo(m_ptStartPoint); pDC->LineTo(m_ptEndPoint); pDC->SelectObject(pOldPen); // Restore the old pen }
BOOL AssertFailedLine(LPCSTR lpszFileName, int nLine) { TCHAR szMessage[_MAX_PATH*2]; InterlockedDecrement(&AssertReallyBusy); // format message into buffer wsprintf(szMessage, _T("File %hs, Line %d"), lpszFileName, nLine); TCHAR szT[_MAX_PATH*2 + 20]; wsprintf(szT, _T("Assertion Failed: %s\n"), szMessage); OutputDebugString(szT); if (InterlockedIncrement(&AssertBusy) > 0) { InterlockedDecrement(&AssertBusy); // assert within assert (examine call stack to determine first one) DebugBreak(); return FALSE; } // active popup window for the current thread HWND hWndParent = GetActiveWindow(); if (hWndParent != NULL) hWndParent = GetLastActivePopup(hWndParent); // display the assert int nCode = ::MessageBox(hWndParent, szMessage, _T("Assertion Failed!"), MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND); // cleanup InterlockedDecrement(&AssertBusy); if (nCode == IDIGNORE) return FALSE; // ignore if (nCode == IDRETRY) return TRUE; // will cause DebugBreak AfxAbort(); // should not return (but otherwise DebugBreak) return TRUE; }
void CCell::Draw_Rect(CDC* pDC, CRect rect) const { CPen aPen; if(!aPen.CreatePen(PS_SOLID, m_nPenWidth, m_clrColor)) { // Pen creation failed. Close the program AfxMessageBox("Pen creation failed drawing a curve", MB_OK); AfxAbort(); } CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen CBrush* pOldBrush = static_cast<CBrush*>(pDC->SelectStockObject(HOLLOW_BRUSH)); pDC->Rectangle(rect); pDC->SelectObject(pOldPen); // Restore the old pen pDC->SelectObject(pOldBrush); // Restore the old brush }
// Draw a CLine object void CLine::Draw(CDC* pDC, CElement* pElement) { // Create a pen for this object and // initialize it to the object color and line width m_PenWidth CPen aPen; if (!aPen.CreatePen(PS_SOLID, m_PenWidth, this == pElement ? SELECT_COLOR : m_Color)) { // Pen creation failed. Abort the program AfxMessageBox(_T("Pen creation failed drawing a line"), MB_OK); AfxAbort(); } CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen // Now draw the line pDC->MoveTo(m_StartPoint); pDC->LineTo(m_EndPoint); pDC->SelectObject(pOldPen); // Restore the old pen }
// Draw a curve void CCurve::Draw(CDC* pDC, CElement* pElement) { // Create a pen for this object and // initialize it to the object color and line width of m_PenWidth CPen aPen; if(!aPen.CreatePen(PS_SOLID, m_PenWidth, this==pElement ? SELECT_COLOR : m_Color)) { // Pen creation failed AfxMessageBox(_T("Pen creation failed drawing a curve"), MB_OK); AfxAbort(); } CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen // A forward iterator enables you to traverse the list forwards auto iter = m_Points.begin(); // Create a forward iterator pDC->MoveTo(**(iter++)); // Move to the first point and increment the iterator for(; iter != m_Points.end() ; ++iter) // Draw segments between the remaining points pDC->LineTo(**iter); pDC->SelectObject(pOldPen); // Restore the old pen }
void CInkPoint::Draw(CDC* pDC, const CInkPoint* pElement) { CPen aPen; CPen* pOldPen; CString aStr; COLORREF aColor = m_inkPointInfo.clrColor; if ( m_inkPointInfo.bSelected == TRUE ) aColor = SELECT_COLOR; if(!aPen.CreatePen(PS_SOLID, m_inkPointInfo.nPenWidth, aColor)) { // Pen creation failed AfxMessageBox("Pen creation failed drawing a InkPoint", MB_OK); AfxAbort(); } pOldPen = pDC->SelectObject(&aPen); // Select the apen // Select a null brush CBrush* pOldBrush = static_cast<CBrush*>(pDC->SelectStockObject(HOLLOW_BRUSH)); //m_rtEnclosingRect = GetBoundRect(); pDC->Ellipse(m_inkPointInfo.rtEnclosingRect); pDC->SelectObject(pOldPen); // Restore th old pen pDC->SelectObject(pOldBrush); // Restore the old brush // Dotted Line Draw m_inkPointInfo.dlineDottedLine.m_ptStartPoint.x = m_inkPointInfo.rtEnclosingRect.right; m_inkPointInfo.dlineDottedLine.m_ptStartPoint.y = ((m_inkPointInfo.rtEnclosingRect.bottom - m_inkPointInfo.rtEnclosingRect.top) / 2 ) + m_inkPointInfo.rtEnclosingRect.top; m_inkPointInfo.dlineDottedLine.m_ptEndPoint.x = m_inkPointInfo.rtEnclosingRect.right + 40; m_inkPointInfo.dlineDottedLine.m_ptEndPoint.y = ((m_inkPointInfo.rtEnclosingRect.bottom - m_inkPointInfo.rtEnclosingRect.top) / 2 ) + m_inkPointInfo.rtEnclosingRect.top; m_inkPointInfo.dlineDottedLine.m_clrColor = BLACK; m_inkPointInfo.dlineDottedLine.Draw(pDC); }
// Draw a CLine object void CLine::Draw(CDC* pDC, CElement* pElement) { // Create a pen for this object and // initialize it to the object color and line width of 1 pixel CPen aPen; COLORREF aColor = m_Color; // Initialize with element color if(this == pElement) // This element selected? aColor = SELECT_COLOR; // Set highlight color if(!aPen.CreatePen(PS_SOLID, m_Pen, aColor)) { // Pen creation failed. Abort the program AfxMessageBox(_T("Pen creation failed drawing a line"), MB_OK); AfxAbort(); } CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen // Now draw the line pDC->MoveTo(m_StartPoint); pDC->LineTo(m_EndPoint); pDC->SelectObject(pOldPen); // Restore the old pen }
static void InternalAssert(const TCHAR * AssertDescription, const char * lpszFileName, INT32 nLine, BOOL UseMFC) { if (!UseMFC) #if defined(__WXMSW__) MessageBeep(MB_ICONASTERISK); #else ::wxBell(); #endif #ifdef _ENSURES TCHAR sz[256]; static TCHAR BASED_CODE szTitle[] = wxT("Ensure Failed!"); // In Unicode we need to convert the filename to TCHAR #if 0 != wxUSE_UNICODE TCHAR szRealFile[256]; size_t count = camMbstowcs(szRealFile, lpszFileName, 255); if (count == (size_t)-1) count = 0; szRealFile[count] = (TCHAR)0; const TCHAR* lpszRealFile = szRealFile; #else const TCHAR* lpszRealFile = lpszFileName; #endif static TCHAR BASED_CODE szMessage[] = wxT("%s, File %s, Line %d"); static TCHAR BASED_CODE szMessageNoReason[] = wxT("Error %d@%s"); // note number first // get app name or NULL if unknown (don't call assert) // const TCHAR *pszAppName = wxGetApp().GetAppName(); if (AssertDescription != NULL) { camSnprintf(sz, 255, szMessage, AssertDescription, lpszRealFile, nLine); } else { camSnprintf(sz, 255, szMessageNoReason, nLine, lpszRealFile); } #ifdef _DEBUG //PORTNOTE("other","Remove afxTraceEnabled") //#ifndef EXCLUDE_FROM_XARALX // if (afxTraceEnabled) #if defined(__WXMSW__) { // assume the debugger or auxiliary port #ifndef _MAC ::OutputDebugString(sz); ::OutputDebugString(_T(", ")); ::OutputDebugString(szTitle); ::OutputDebugString(_T("\n\r")); #else // Mac version needs them all together camStrcat(sz, _T(", ")); camStrcat(sz,szTitle); camStrcat(sz,_T("\n\r")); ::OutputDebugString(sz); #endif } #endif #endif if (AssertBusy > 0) { // getting assertion while inside an assertion // - it has already been traced, but // break into the debugger (or Dr Watson log) DEBUGBREAK; // else Win32s might die (just beeps) return; } AssertBusy++; if ( Error::IsInRenderThread() ) { TRACE( wxT("In RenderThread so clearing up system") ); Error::RenderThreadReset(); // Commented out - no problem using wx for render errors // UseMFC = FALSE; // mustn't use MFC for render errors } INT32 result; TCHAR RealErrorMsg[256]; if (UseMFC) { // use our error handler to report ensures as it is more robust instead of MessageBox // The arrangement of buttons is the same as the exception handler dialog, not the same // as the original Ensure dialog (which was Abort/Retry/Ignore) ErrorInfo Info; // try to preserve original error message camStrcpy( RealErrorMsg, Error::GetErrorString() ); Error::SetErrorSerious( sz ); // set error msg (vaping any previous one) Info.ErrorMsg = 0; Info.Button[0] = _R(IDS_CONTINUE); Info.Button[1] = _R(IDS_QUIT); #ifndef EXCLUDE_FROM_XARALX if (IsWin32NT()) { #endif // only NT can cope with an Abort button Info.Button[2] = _R(IDS_ABORT); Info.Button[3] = _R(IDS_DEBUG); #ifndef EXCLUDE_FROM_XARALX } else { Info.Button[2] = _R(IDS_DEBUG); } #endif // no default button (or Help) Info.Cancel = 1; // Esc = Continue result = InformGeneral( ERRORTYPE_ENSURE, &Info ); } else { CamResource::DoneInit(); CCamApp::DisableSystem(); // e.g. if this an MFC assert, don't use our lovely error handler becuase that itself // uses MFC. Instead we use good old MessageBox #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX) wxWindow *pParent = AfxGetApp().GetTopWindow(); PORTNOTE("other","Use CInformErrorDialog::GetSafeParent() when implemented") #ifndef EXCLUDE_FROM_XARALX CInformErrorDialog::GetSafeParent(); #endif #else wxWindow *pParent = NULL; #endif wxMessageDialog Dialog( pParent, sz, szTitle, wxICON_HAND | wxYES_NO | wxCANCEL ); INT32 nCode = Dialog.ShowModal(); CCamApp::EnableSystem(); // convert MessageBox return value into a sane button ID switch (nCode) { case wxID_NO: result = _R(IDS_ABORT); break; case wxID_YES: result = _R(IDS_DEBUG); break; case wxID_CANCEL: default: result = _R(IDS_CONTINUE); break; } } AssertBusy--; if ((ResourceID)result == _R(IDS_DEBUG)) { DEBUGBREAK; } // no action on _R(IDS_CONTINUE)) else if ((ResourceID)result == _R(IDS_QUIT)) { // quit in a slightly nice way wxWindow *MainWnd = AfxGetApp().GetTopWindow(); if( MainWnd && MainWnd->IsShown() ) { MainWnd->Destroy(); } } // drop through if (((ResourceID)result == _R(IDS_ABORT)) || ((ResourceID)result == _R(IDS_QUIT))) { // if no window, try nasty exit AfxAbort(); return; // how did we get here? } // if we ever get here we just carry on as if nothing happened PORTNOTE("other","We can never use MFC again") #ifndef EXCLUDE_FROM_XARALX if (UseMFC) { if (RealErrorMsg[0]) Error::SetErrorSerious( RealErrorMsg ); // restore previous error msg else Error::ClearError(); } #endif #else // parameters not used if non-debug (void)lpszFileName; (void)nLine; #endif // _ENSURES }
BOOL AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine) { TCHAR szMessage[_MAX_PATH*2]; // handle the (hopefully rare) case of AfxGetAllocState ASSERT if (InterlockedIncrement(&afxAssertReallyBusy) > 0) { // assume the debugger or auxiliary port wsprintf(szMessage, _T("Assertion Failed: File %hs, Line %d\n"), lpszFileName, nLine); OutputDebugString(szMessage); InterlockedDecrement(&afxAssertReallyBusy); // assert w/in assert (examine call stack to determine first one) AfxDebugBreak(); return FALSE; } // check for special hook function (for testing diagnostics) AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); AFX_ALLOC_STATE* pAllocState = AfxGetAllocState(); InterlockedDecrement(&afxAssertReallyBusy); if (pAllocState->m_lpfnAssertFailedLine != NULL) return pAllocState->m_lpfnAssertFailedLine(lpszFileName, nLine); // get app name or NULL if unknown (don't call assert) LPCTSTR lpszAppName = afxCurrentAppName; if (lpszAppName == NULL) lpszAppName = _T("<unknown application>"); // format message into buffer wsprintf(szMessage, _T("%s: File %hs, Line %d"), lpszAppName, lpszFileName, nLine); if (afxTraceEnabled) { // assume the debugger or auxiliary port // output into MacsBug looks better if it's done in one string, // since MacsBug always breaks the line after each output TCHAR szT[_MAX_PATH*2 + 20]; wsprintf(szT, _T("Assertion Failed: %s\n"), szMessage); OutputDebugString(szT); } if (InterlockedIncrement(&afxAssertBusy) > 0) { InterlockedDecrement(&afxAssertBusy); // assert within assert (examine call stack to determine first one) AfxDebugBreak(); return FALSE; } // active popup window for the current thread HWND hWndParent = GetActiveWindow(); if (hWndParent != NULL) hWndParent = GetLastActivePopup(hWndParent); // display the assert int nCode = ::MessageBox(hWndParent, szMessage, _T("Assertion Failed!"), MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND); // cleanup InterlockedDecrement(&afxAssertBusy); if (nCode == IDIGNORE) return FALSE; // ignore if (nCode == IDRETRY) return TRUE; // will cause AfxDebugBreak UNUSED nLine; // unused in release build UNUSED lpszFileName; AfxAbort(); // should not return (but otherwise AfxDebugBreak) return TRUE; }
void CRTEXToolView::DrawArm(int x1, int y1,int z1,float m_fYaw,float theta1,float theta2) { UINT sizenum = pDoc->m_view_resolution / uiscale; CClientDC pDC(this); OnPrepareDC(&pDC); CPoint pt,ptAxis; float m_fScaraRobot_L1 = 325; float m_fScaraRobot_L2 = 225; float m_fScaraRobot_Height_Asix1 = (290+74); float fXpos=0,fYpos=0,fZpos=0; int xJ1, yJ1,zJ1,xJ2, yJ2,zJ2,xJ3, yJ3,zJ3; /////////////////////////////////////////////////////////////// CPen axisPen2; if(!axisPen2.CreatePen(PS_SOLID ,500,RGB(255,255,255))) { // Pen creation failed. Abort the program AfxMessageBox(_T("Pen creation failed drawing a line"), MB_OK); AfxAbort(); } CPen* pOldPen = pDC.SelectObject(&axisPen2); // Select the pen /////////////////////////////////////////////////////////////// pDC.MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(xJ1_backup,yJ1_backup,zJ1_backup); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); ptAxis = Cpt3DptTo2Dpt(xJ2_backup,yJ2_backup,zJ2_backup); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); ptAxis = Cpt3DptTo2Dpt(xJ3_backup,yJ3_backup,zJ3_backup); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); ptAxis = Cpt3DptTo2Dpt(x1_backup,y1_backup,z1_backup); pDC.LineTo(ptAxis.x,ptAxis.y); // pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum/5,ptAxis.y-sizenum/5); pDC.SelectObject(pOldPen); ////////////////draw xyz back ////////////////////////////////////// CPen axisPen; if(!axisPen.CreatePen(PS_DOT,10,RGB(255,0,0))) { // Pen creation failed. Abort the program AfxMessageBox(_T("Pen creation failed drawing a line"), MB_OK); AfxAbort(); } pOldPen = pDC.SelectObject(&axisPen); // Select the pen int showaxis = pDoc->m_view_resolution; // CPoint ptAxis; pDC.MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(showaxis,0,0); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); pDC.TextOut(ptAxis.x,ptAxis.y,"X"); pDC.MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(0,showaxis,0); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); pDC.TextOut(ptAxis.x,ptAxis.y,"Y"); pDC.MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(0,0,showaxis); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); pDC.TextOut(ptAxis.x,ptAxis.y,"Z"); pDC.SelectObject(pOldPen); CPen axisPen1; if(!axisPen1.CreatePen(PS_DOT,10,RGB(0,0,255))) { // Pen creation failed. Abort the program AfxMessageBox(_T("Pen creation failed drawing a line"), MB_OK); AfxAbort(); } pOldPen = pDC.SelectObject(&axisPen1); // Select the pen pDC.MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(-showaxis,0,0); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(0,-showaxis,0); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(0,0,-showaxis); pDC.LineTo(ptAxis.x,ptAxis.y); // pDC.TextOut(cr.TopLeft().x,cr.TopLeft().y,"X vs Y vs Z"); pDC.SelectObject(pOldPen); ////////////////draw xyz back end////////////////////////////////////// /////////////////////////////////////////////////////////////// CPen axisPen3; if(!axisPen3.CreatePen(PS_SOLID ,500,RGB(50,100,150))) { // Pen creation failed. Abort the program AfxMessageBox(_T("Pen creation failed drawing a line"), MB_OK); AfxAbort(); } CPen* pOldPen3 = pDC.SelectObject(&axisPen3); // Select the pen /////////////////////////////////////////////////////////////// xJ1 = 0 ; yJ1 = 0 ; zJ1 = 0 +(int)(0.5 + (m_fScaraRobot_Height_Asix1 * 1000)); fXpos = (float)(m_fScaraRobot_L1 * cos((theta1)*M_PI/180)); fYpos = (float)(m_fScaraRobot_L1 * sin((theta1)*M_PI/180)); xJ2 = xJ1+(int)(0.5 + (fXpos * 1000)); yJ2 = yJ1+(int)(0.5 + (fYpos * 1000)); zJ2 = zJ1; fXpos = (float)(m_fScaraRobot_L2 * cos((theta1+theta2)*M_PI/180)); fYpos = (float)(m_fScaraRobot_L2 * sin((theta1+theta2)*M_PI/180)); xJ3 = xJ2+(int)(0.5 + (fXpos * 1000)); yJ3 = yJ2+(int)(0.5 + (fYpos * 1000)); zJ3 = zJ2; pDC.MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(xJ1,yJ1,zJ1); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); ptAxis = Cpt3DptTo2Dpt(xJ2,yJ2,zJ2); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); ptAxis = Cpt3DptTo2Dpt(xJ3,yJ3,zJ3); pDC.LineTo(ptAxis.x,ptAxis.y); pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); ptAxis = Cpt3DptTo2Dpt(x1,y1,z1); pDC.LineTo(ptAxis.x,ptAxis.y); // pDC.Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); pDC.SelectObject(pOldPen3); xJ1_backup = xJ1; yJ1_backup = yJ1; zJ1_backup = zJ1; xJ2_backup = xJ2; yJ2_backup = yJ2; zJ2_backup = zJ2; xJ3_backup = xJ3; yJ3_backup = yJ3; zJ3_backup = zJ3; x1_backup = x1; y1_backup = y1; z1_backup = z1; }
void CRTEXToolView::OnDraw(CDC* pDC) { //CRTEXToolDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: 在此加入原生資料的描繪程式碼 UINT sizenum = pDoc->m_view_resolution * 5 / uiscale; CPen axisPen; if(!axisPen.CreatePen(PS_DOT,10,RGB(255,0,0))) { // Pen creation failed. Abort the program AfxMessageBox(_T("Pen creation failed drawing a line"), MB_OK); AfxAbort(); } CPen* pOldPen = pDC->SelectObject(&axisPen); // Select the pen CRect cr; CSize size; GetClientRect(&cr); pDC->DPtoLP(&cr); int showaxis = pDoc->m_view_resolution; CPoint ptAxis; pDC->MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(showaxis,0,0); pDC->LineTo(ptAxis.x,ptAxis.y); pDC->Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); pDC->TextOut(ptAxis.x,ptAxis.y,"X"); pDC->MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(0,showaxis,0); pDC->LineTo(ptAxis.x,ptAxis.y); pDC->Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); pDC->TextOut(ptAxis.x,ptAxis.y,"Y"); pDC->MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(0,0,showaxis); pDC->LineTo(ptAxis.x,ptAxis.y); pDC->Ellipse(ptAxis.x-sizenum,ptAxis.y+sizenum,ptAxis.x+sizenum,ptAxis.y-sizenum); pDC->TextOut(ptAxis.x,ptAxis.y,"Z"); /* pDC->MoveTo(cr.TopLeft().x,0); pDC->LineTo(cr.BottomRight().x,0); pDC->MoveTo(0,cr.BottomRight().y); pDC->LineTo(0,cr.TopLeft().y); pDC->TextOut(cr.TopLeft().x,cr.TopLeft().y,"X vs Y"); */ pDC->SelectObject(pOldPen); CPen axisPen1; if(!axisPen1.CreatePen(PS_DOT,10,RGB(0,0,255))) { // Pen creation failed. Abort the program AfxMessageBox(_T("Pen creation failed drawing a line"), MB_OK); AfxAbort(); } pOldPen = pDC->SelectObject(&axisPen1); // Select the pen pDC->MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(-showaxis,0,0); pDC->LineTo(ptAxis.x,ptAxis.y); pDC->MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(0,-showaxis,0); pDC->LineTo(ptAxis.x,ptAxis.y); pDC->MoveTo(0,0); ptAxis = Cpt3DptTo2Dpt(0,0,-showaxis); pDC->LineTo(ptAxis.x,ptAxis.y); pDC->TextOut(cr.TopLeft().x,cr.TopLeft().y,"X vs Y vs Z"); pDC->SelectObject(pOldPen); /* CPoint* currentPt; for(auto iter = pDoc->begin() ; iter != pDoc->end() ; ++iter) { currentPt = *iter; pDC->Ellipse(currentPt->x-sizenum,currentPt->y+sizenum,currentPt->x+sizenum,currentPt->y-sizenum); } */ if(!pDoc->m_fgskipRedraw) { sizenum = pDoc->m_view_resolution / uiscale; CString str; int xx,yy,zz; pDoc->savefile.SeekToBegin(); while(pDoc->savefile.ReadString(str)) { if(str.Left(4) =="XYZ:") { xx = atoi((LPCSTR)str.Mid(39,9)); yy = atoi((LPCSTR)str.Mid(49,9)); zz = atoi((LPCSTR)str.Mid(59,9)); CPoint pt; pt = Cpt3DptTo2Dpt(xx,yy,zz); pDC->Ellipse(pt.x-sizenum,pt.y+sizenum,pt.x+sizenum,pt.y-sizenum); //pDC->Ellipse(xx-sizenum,yy+sizenum,xx+sizenum,yy-sizenum); } } pDoc->savefile.SeekToEnd(); } }
/*************************************************** CUGODBCDatasource::Browse : call this function to invoke the ODBC driver to prompt for connection params. This function gathers information about all of the tables in the datasource selected, storing the information in the array m_dsInfoArray for later retrieval. This function also saves the resulting connect string for later use. ****************************************************/ int CUGODBCDatasource::Browse(HWND hwnd){ HENV henv; HDBC hdbc; HSTMT hstmt; RETCODE retcode; SQLTCHAR buf[255]; SQLTCHAR sqlerror[255]; SQLTCHAR sqlstate[255]; SDWORD nerr, cbVal; SWORD num; // for table info.... SQLTCHAR szTableQualifier[128]; SQLTCHAR szTableOwner[128]; SQLTCHAR szTableName[128]; SQLTCHAR szTableType[128]; SQLTCHAR szRemarks[255]; // close open db Close(); // clean up previous data m_connectString = ""; m_tableCount = 0; retcode = SQLAllocEnv(&henv); // Environment handle if (retcode == SQL_ERROR) { AfxMessageBox(_T("Probable memory allocation error in SQLAllocEnv")); return (int) retcode; } retcode = SQLAllocConnect(henv,&hdbc); if (retcode == SQL_ERROR) { ReportSQLError(henv, SQL_NULL_HDBC, SQL_NULL_HSTMT, retcode, _T("SQLAllocConnect")); SQLFreeEnv(henv); return (int) retcode; } if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { // Set login timeout to 5 seconds. SQLSetConnectOption(hdbc, SQL_LOGIN_TIMEOUT, 5); // Connect to data source // this should cause the ODBC Driver to come up with the // necessary prompts to form a connect string... retcode = SQLDriverConnect(hdbc,hwnd,(SQLTCHAR*)_T(""), 0,buf,254,&num,SQL_DRIVER_PROMPT); if (retcode != SQL_SUCCESS) { #ifdef UG_REPORT_ERROR ReportSQLError(henv, hdbc, SQL_NULL_HSTMT, retcode, _T("SQLDriverConnect")); #endif // user probably cancelled connection... if (retcode != SQL_SUCCESS_WITH_INFO) { SQLFreeConnect(hdbc); SQLFreeEnv(henv); return retcode; } } if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){ // retcode from SQLDriverConnect... // should be cool to try to open a recordset with the info // we have here in buf... CDatabase db; TCHAR buf2[255]; UGStr::stprintf(buf2,255,_T("ODBC;%s"),buf); // now we have the connect string in buf2 - but wait to // see if we can actually open the db before storing // it in m_connectString... try { retcode = db.Open(NULL,FALSE,FALSE,buf2); } catch(CMemoryException* e){ #ifdef UG_ODBC_REPORTERROR e->ReportError(); #endif e->Delete(); AfxAbort(); } catch(CDBException* e){ // standard procedure for ODBC - save the // RETCODE code for the return value - // Report on the error - optional - // use Delete to delete the exception object RETCODE er = e->m_nRetCode; #ifdef UG_ODBC_REPORTERROR e->ReportError(); #endif e->Delete(); SQLFreeConnect(hdbc); SQLFreeEnv(henv); return (int)er; } // now, given an open connection, we should // be able to set up a statement handle.. retcode = SQLAllocStmt(hdbc, &hstmt); switch (retcode) { case SQL_SUCCESS: { // AfxMessageBox("SQLAllocStmt returned success "); // AfxMessageBox((LPCSTR)buf); break; } case SQL_SUCCESS_WITH_INFO:{ AfxMessageBox(_T("SQLAllocStmt returned success with info")); // this indicates that there is a driver specific warning // to be investigated... SQLError(SQL_NULL_HENV,hdbc,SQL_NULL_HSTMT,sqlstate, &nerr,sqlerror,254,&num); AfxMessageBox((LPCTSTR)sqlstate); AfxMessageBox((LPCTSTR)sqlerror); break; } case SQL_NO_DATA_FOUND:{ AfxMessageBox(_T("SQLAllocStmt returned no data found")); break; } case SQL_ERROR:{ AfxMessageBox(_T("SQLAllocStmt returned sql error")); SQLError(SQL_NULL_HENV,hdbc,SQL_NULL_HSTMT,sqlstate,&nerr,sqlerror,254,&num); AfxMessageBox((LPCTSTR)sqlstate); AfxMessageBox((LPCTSTR)sqlerror); break; } case SQL_INVALID_HANDLE:{ AfxMessageBox(_T("SQLDriverConnect returned invalid handle")); break; } default: break; } // ok - now lets see if we can enumerate the tables // contained in the database... retcode = SQLTables(hstmt, // statement handle for // retrieved results NULL, // szTableQualifier SQL_NTS, // cbTableQualifier NULL, // szTableOwner SQL_NTS, // cbTableOwner NULL, // szTableName SQL_NTS, // cbTableName (SQLTCHAR*)_T("'TABLE','VIEW',\ 'SYSTEM TABLE','GLOBAL TEMPORARY','LOCAL TEMPORARY',\ 'ALIAS','SYNONYM'"), // szTableType (list of // table types to match) SQL_NTS); // cbTableTypes if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) { ReportSQLError(henv, hdbc, hstmt, retcode, _T("SQLTables")); SQLFreeStmt(hstmt, SQL_DROP); SQLDisconnect(hdbc); SQLFreeConnect(hdbc); SQLFreeEnv(henv); return retcode; // unable to query tables // User should see message box } // now - can we iterate through the tables found? #ifndef _UNICODE SQLBindCol(hstmt, 1, SQL_C_CHAR, szTableQualifier, 128, &cbVal); SQLBindCol(hstmt, 2, SQL_C_CHAR, szTableOwner, 128, &cbVal); SQLBindCol(hstmt, 3, SQL_C_CHAR, szTableName, 128, &cbVal); SQLBindCol(hstmt, 4, SQL_C_CHAR, szTableType, 128, &cbVal); SQLBindCol(hstmt, 5, SQL_C_CHAR, szRemarks, 255, &cbVal); #else SQLBindCol(hstmt, 1, SQL_UNICODE_CHAR, szTableQualifier, 128, &cbVal); SQLBindCol(hstmt, 2, SQL_UNICODE_CHAR, szTableOwner, 128, &cbVal); SQLBindCol(hstmt, 3, SQL_UNICODE_CHAR, szTableName, 128, &cbVal); SQLBindCol(hstmt, 4, SQL_UNICODE_CHAR, szTableType, 128, &cbVal); SQLBindCol(hstmt, 5, SQL_UNICODE_CHAR, szRemarks, 255, &cbVal); #endif retcode = SQLFetch(hstmt); if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) ReportSQLError(henv, hdbc, hstmt, retcode, _T("SQLFetch")); if (retcode != SQL_NO_DATA_FOUND) m_connectString = (LPTSTR)buf2; // save connection string! // Subsequent calls to GetTableInfo will be able to // retrieve this information... while (retcode != SQL_NO_DATA_FOUND) { UGStr::tcscpy((LPTSTR)m_dsInfoArray[m_tableCount].tableQualifier,128,(LPTSTR)szTableQualifier); UGStr::tcscpy((LPTSTR)m_dsInfoArray[m_tableCount].tableOwner,128, (LPTSTR)szTableOwner); UGStr::tcscpy((LPTSTR)m_dsInfoArray[m_tableCount].tableName,128,(LPTSTR)szTableName); UGStr::tcscpy((LPTSTR)m_dsInfoArray[m_tableCount].tableType,128,(LPTSTR)szTableType); UGStr::tcscpy((LPTSTR)m_dsInfoArray[m_tableCount].remarks,255,(LPTSTR)szRemarks); m_tableCount++; if (m_tableCount >= MAX_TABLES) break; retcode = SQLFetch(hstmt); } }
// ---------------------------------------------------------------------------- // 2006-10-23 오전 4:36:18 추가(New), Sun.H.D // 호출 시점 : Arrow Line // // 특 징 : // // 매개 변수 : // // 리 턴 값 : // ---------------------------------------------------------------------------- void CArrowLine::Draw(CDC* pDC) { CPen aPen; UINT nType = 0; CPoint ArrowPoint; if(!aPen.CreatePen(PS_SOLID, 1, m_clrColor)) { // Pen creation failed. Close the program AfxMessageBox("Pen creation failed drawing a curve", MB_OK); AfxAbort(); } CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen pDC->MoveTo(m_ptStartPoint); pDC->LineTo(m_ptEndPoint); if(m_ptStartPoint.y == m_ptEndPoint.y) nType = 0; else nType = 1; // 수평선 if(nType==0) { ArrowPoint = m_ptStartPoint; ArrowPoint.x += m_nArrowSize; ArrowPoint.y -= m_nArrowSize; pDC->MoveTo(ArrowPoint); pDC->LineTo(m_ptStartPoint); ArrowPoint = m_ptStartPoint; ArrowPoint.x += m_nArrowSize; ArrowPoint.y += m_nArrowSize; pDC->LineTo(ArrowPoint); ArrowPoint = m_ptEndPoint; ArrowPoint.x -= m_nArrowSize; ArrowPoint.y -= m_nArrowSize; pDC->MoveTo(ArrowPoint); pDC->LineTo(m_ptEndPoint); ArrowPoint = m_ptEndPoint; ArrowPoint.x -= m_nArrowSize; ArrowPoint.y += m_nArrowSize; pDC->LineTo(ArrowPoint); } else { // 수직선 ArrowPoint = m_ptStartPoint; ArrowPoint.x -= m_nArrowSize; ArrowPoint.y += m_nArrowSize; pDC->MoveTo(ArrowPoint); pDC->LineTo(m_ptStartPoint); ArrowPoint = m_ptStartPoint; ArrowPoint.x += m_nArrowSize; ArrowPoint.y += m_nArrowSize; pDC->LineTo(ArrowPoint); ArrowPoint = m_ptEndPoint; ArrowPoint.x -= m_nArrowSize; ArrowPoint.y -= m_nArrowSize; pDC->MoveTo(ArrowPoint); pDC->LineTo(m_ptEndPoint); ArrowPoint = m_ptEndPoint; ArrowPoint.x += m_nArrowSize; ArrowPoint.y -= m_nArrowSize; pDC->LineTo(ArrowPoint); } pDC->SelectObject(pOldPen); // Restore the old pen }
static BOOL DoGrowGlobalHandle( HGLOBAL *pHandle, UINT32 OldSize, UINT32 NewSize, UINT32 MoreFlags, LPVOID *Pointer) { if (GlobalUnlock( *pHandle )) { // if didn't unlock then we won't be able to realloc, so better stop now TRACE( wxT("GlobalUnlock failed in GrowGlobalHandle\n") ); return FALSE; } // get Windows to grab us a new bigger block. Important to use GMEM_MOVEABLE as we want // our block to move if possible to satisfy the request HGLOBAL hNewHandle = GlobalReAlloc( *pHandle, NewSize, GMEM_MOVEABLE | MoreFlags ); if (hNewHandle) { ADDR NewPtr = (ADDR)GlobalLock( hNewHandle ); if (NewPtr == NULL) { // careful here as we really do want to get our old data back - at the moment // all we have is a handle to an unlocked block of memory. To try and recover the // situation we'll try setting it back to its old size hNewHandle = GlobalReAlloc( hNewHandle, OldSize, GMEM_MOVEABLE ); if (hNewHandle) { NewPtr = (ADDR)GlobalLock( hNewHandle ); if (NewPtr) { // OK, got old data back but might be in different place so tidy up // then exit gracefully *Pointer = NewPtr; *pHandle = hNewHandle; TRACE( wxT("WARNING: Made hasty exit from GrowGlobalHandle\n") ); return FALSE; // indicate failure } } // this is very catastrophic - we cannot get our old data back, so // we will communicate this to the user. The program is likely to // crash and burn after this TRACE( wxT("DANGER: Catastrophic failure in GrowGlobalHandle\n") ); if (InformSeriousError( _R(IDE_BAD_GROWHEAP), _R(IDS_ABORT), _R(IDS_CONTINUE) ) == 1) AfxAbort(); return FALSE; // although system is v. unstable } TRACEUSER( "Andy", wxT("Handle %x changed to %x (%lx-%lx) (%ld-%ld) %x\n"), (INT32)*pHandle, (INT32)hNewHandle, (INT32)*Pointer, (INT32)NewPtr, (INT32)OldSize, (INT32)NewSize, (INT32)MoreFlags ); // we've got our new block, update the callers variables *Pointer = NewPtr; *pHandle = hNewHandle; return TRUE; } // couldn't reallocate it, the old one will still be there though TRACE( wxT("GlobalReAlloc failed in GrowGlobalHandle\n") ); TRACEUSER( "Andy", wxT("Failed to grow handle %x from %ld.%ld at %lx\n"), (INT32)*pHandle, (INT32)OldSize,(INT32)NewSize, (INT32)*Pointer ); return FALSE; }
UINT ClientReceiverThreadProc(LPVOID pParam) { // Init message window handle if( pParam == NULL ) return (UINT)-1; seedRand(); // Copy data from the param to the locals HWND hwnd = (HWND)pParam; // Create the listening socket, but do not open it ListeningSocket listener( hwnd ); // Link event into events array WSAEVENT aEvents[CLIENTRECEIVER_RESERVED_EVENTS+1]; for( int i = 0; i < CLIENTRECEIVER_RESERVED_EVENTS; i++ ) { aEvents[i] = WSACreateEvent(); if( aEvents[i] == WSA_INVALID_EVENT ) return (UINT)-1; } aEvents[CLIENTRECEIVER_RESERVED_EVENTS] = listener.ReturnEventHandle(); // Critical variables ListeningSocket::ListenerStatus eCriticalStatus; // Threaddata variables ClientReceiverThreadData threadData; memcpy( threadData.m_aReservedEvents, aEvents, sizeof(WSAEVENT) * CLIENTRECEIVER_RESERVED_EVENTS ); threadData.m_peStatus = &eCriticalStatus; CCriticalSection criticalSection; // request initialization of the thread data ::PostMessage( hwnd, WM_LISTENER_INIT_THREAD_DATA, (WPARAM)&criticalSection, (LPARAM)&threadData ); WSANETWORKEVENTS events; // what the fired event data was DWORD event; // which event fired char *pLogMsg = NULL; while(true) { event = WSAWaitForMultipleEvents( (CLIENTRECEIVER_RESERVED_EVENTS + 1), aEvents, false, WSA_INFINITE, false ); char buf[16]; _itoa( event, buf, 10 ); if( event == WSA_WAIT_FAILED ) AfxAbort(); // exit event if( event == 0 ) { CSingleLock singleLock( &criticalSection, true ); WSAResetEvent( aEvents[event] ); break; } // change status if( event == 1 ) { CSingleLock singleLock( &criticalSection, true ); switch( eCriticalStatus ) { case ListeningSocket::OPEN: listener.Open(); break; case ListeningSocket::CLOSED: listener.Close(); break; } WSAResetEvent( aEvents[event] ); } // socket event if( event >= CLIENTRECEIVER_RESERVED_EVENTS ) { WSAResetEvent( aEvents[event] ); events = listener.ReturnNetworkEvents(); if(events.lNetworkEvents & FD_CONNECT) { listener.OnConnect(events.iErrorCode[FD_CONNECT_BIT]); } if(events.lNetworkEvents & FD_READ) { while( listener.OnReceive(events.iErrorCode[FD_READ_BIT]) ); } if(events.lNetworkEvents & FD_WRITE) { listener.OnSend(events.iErrorCode[FD_WRITE_BIT]); } if(events.lNetworkEvents & FD_CLOSE) { listener.OnClose(events.iErrorCode[FD_CLOSE_BIT]); } if(events.lNetworkEvents & FD_ACCEPT) { listener.OnAccept(events.iErrorCode[FD_ACCEPT_BIT]); } } } // end while(1) // Close the reserved events for( int i = 0; i < CLIENTRECEIVER_RESERVED_EVENTS; i++ ) WSACloseEvent( aEvents[i] ); // close the socket listener.Close(); return 0; // exit the thread }