void CSortingListControl::LoadPersistentAttributes() { CArray<int, int> arr; arr.SetSize(GetHeaderCtrl()->GetItemCount()); GetColumnOrderArray(arr.GetData(), arr.GetSize()); CPersistence::GetColumnOrder(m_name, arr); SetColumnOrderArray(arr.GetSize(), arr.GetData()); for (int i=0; i < arr.GetSize(); i++) arr[i]= GetColumnWidth(i); CPersistence::GetColumnWidths(m_name, arr); for (i=0; i < arr.GetSize(); i++) { // To avoid "insane" settings we set the column width to // maximal twice the default width. int maxWidth= GetColumnWidth(i) * 2; int w= min(arr[i], maxWidth); SetColumnWidth(i, w); } // Not so good: CPersistence::GetSorting(m_name, GetHeaderCtrl()->GetItemCount(), m_sorting.column1, m_sorting.ascending1, m_sorting.column2, m_sorting.ascending2); // We refrain from saving the sorting because it is too likely, that // users start up with insane settings and don't get it. }
void CSkyODL::OnDrawFace( Gdiplus::Graphics& gcDrawer, float fScale ) { CBaseODL::OnDrawFace(gcDrawer, fScale); Gdiplus::Pen Dot( m_clDotColor, static_cast<Gdiplus::REAL>(1.0 / fScale)); CArray<Gdiplus::Point> st; CArray<BYTE> stBytes; for (auto& curItem : m_arrTopPoint) { Gdiplus::Point pt; pt.X = static_cast<INT>(curItem.X()); pt.Y = static_cast<INT>(-curItem.Z()); st.Add(pt); } if(st.GetSize()<=0) { return; } Gdiplus::Pen pen( m_clPenColor, static_cast<Gdiplus::REAL>(1.0 / fScale)); pen.SetDashStyle(Gdiplus::DashStyleSolid); Gdiplus::HatchBrush brush( Gdiplus::HatchStyle(Gdiplus::HatchStyle::HatchStyleCross ), m_clPenColor, Gdiplus::Color(0,255,255,255) ); //画皮肤 gcDrawer.FillPolygon(&brush, st.GetData(), st.GetSize(), Gdiplus::FillMode::FillModeAlternate); gcDrawer.DrawLines(&pen, st.GetData(), st.GetSize()); }
TTaskResult CBeep::Execute(CRobot * Robot, CExecutableRWGraphicObjectList * ExecutableObjectList, bool & result) { if (Robot->GetSoftwareRevision() <= 1.06) /*Do the tune as beeps for robots before version 1.07*/ { Robot->AddBeepToInstructions(GetFrequency(), GetDuration()); CFlowZap *FZ = (CFlowZap*)m_fc; CBeep* LastBeep = this; CInstruction *Next = FZ->GetNextInstructionInList(this); // Next = FZ->GetNextExecutableInstruction(Next); while (Next->IsKindOf(RUNTIME_CLASS(CBeep))) { LastBeep = (CBeep*)Next; Robot->AddBeepToInstructions(LastBeep->GetFrequency(), LastBeep->GetDuration()); Next = FZ->GetNextInstructionInList(Next); // Next = FZ->GetNextExecutableInstruction(Next); } FZ->SetCueToInstruction(LastBeep); FZ->RedrawWindow(); } else { unsigned int NumberOfNotes = 1; CArray<short, short> FrequencyList; FrequencyList.SetSize(20, 20); CArray<int, int> DurationList; DurationList.SetSize(20, 20); FrequencyList[0] = GetFrequency(); DurationList[0] = GetDuration(); CFlowZap *FZ = (CFlowZap*)m_fc; CBeep* LastBeep = this; CInstruction *Next = FZ->GetNextInstructionInList(this); // Next = FZ->GetNextExecutableInstruction(Next); while (Next->IsKindOf(RUNTIME_CLASS(CBeep))) { LastBeep = (CBeep*)Next; FrequencyList[NumberOfNotes] = LastBeep->GetFrequency(); DurationList[NumberOfNotes] = LastBeep->GetDuration(); NumberOfNotes++; Next = FZ->GetNextInstructionInList(Next); // Next = FZ->GetNextExecutableInstruction(Next); } FrequencyList[NumberOfNotes] = -1; DurationList[NumberOfNotes] = 0; NumberOfNotes++; Robot->AddTuneToInstructions(FrequencyList.GetData(), DurationList.GetData(), NumberOfNotes); FZ->SetCueToInstruction(LastBeep); FZ->RedrawWindow(); } TTaskResult TaskResult; TaskResult = Robot->FollowInstructions(true, true, IR_InstructionComplete); return TaskResult; }
CString ConvertReceivedDataToString(CByteArray & data) { // data is UTF-8 encoded CArray<WCHAR, WCHAR> wc; // First, compute the amount of space required. n will include the // space for the terminal NUL character INT_PTR n = ::MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)data.GetData(), (int)data.GetSize(), NULL, 0); if(n == 0) { /* failed */ DWORD err = ::GetLastError(); TRACE(_T("%s: MultiByteToWideChar (1) returned error %d\n"), AfxGetApp()->m_pszAppName, err); return CString(_T("")); } /* failed */ else { /* success */ wc.SetSize(n); n = ::MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)data.GetData(), (int)data.GetSize(), (LPWSTR)wc.GetData(), (int)n); if(n == 0) { /* failed */ DWORD err = ::GetLastError(); TRACE(_T("%s: MultiByteToWideChar (2) returned error %d\n"), AfxGetApp()->m_pszAppName, err); return CString(_T("")); } /* failed */ } /* success */ // Data is now in Unicode // If we are a Unicode app we are done // If we are an ANSI app, convert it back to ANSI #ifdef _UNICODE // If this is a Unicode app we are done return CString(wc.GetData(), (int)wc.GetSize()); #else // ANSI // Invert back to ANSI CString s; n = ::WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wc.GetData(), (int)wc.GetSize(), NULL, 0, NULL, NULL); if(n == 0) { /* failed */ DWORD err = ::GetLastError(); TRACE(_T("%s: WideCharToMultiByte (1) returned error %d\n"), AfxGetApp()->m_pszAppName, err); return CString(""); } /* failed */ else { /* success */ LPSTR p = s.GetBuffer((int)n); n = ::WideCharToMultiByte(CP_ACP, 0, wc.GetData(), (int)wc.GetSize(), p, (int)n, NULL, NULL); if(n == 0) { /* conversion failed */ DWORD err = ::GetLastError(); TRACE(_T("%s: WideCharToMultiByte (2) returned error %d\n"), AfxGetApp()->m_pszAppName, err); s.ReleaseBuffer(); return CString(""); } /* conversion failed */ s.ReleaseBuffer(); return s; } /* success */ #endif } // ConvertReceivedDataToString
UWORD ParseCPPLines ( struct SyntaxHandle *handle, LineDef** lines, BSTR textData, UWORD startoffset, UWORD maxlength, CArray <SyntaxChunk, SyntaxChunk>& SyntaxArr ) { SyntaxArr.SetSize(maxlength); // hm.. TODO, add instead SyntaxChunk* syntax = SyntaxArr.GetData(); int ChunkUsed = 0; int pos = 0; while (pos < maxlength) { if (textData[pos] == L'<') { while } } SyntaxArr.SetSize(ChunkUsed); return 0; }
void CMultiSelDlg::OnOK() { // now copy selection to the selection strings CString strSel; if(m_bSingleSelect) { int iSel = m_tListBox.GetCurSel(); if(iSel>=0) { m_tListBox.GetText(iSel, strSel); m_astrStringsSel.Add(strSel); } } else { CArray<int,int> aiListBoxSel; int iCount = m_tListBox.GetSelCount(); aiListBoxSel.SetSize(iCount); m_tListBox.GetSelItems(iCount, aiListBoxSel.GetData()); for(int iSel = 0; iSel < iCount; ++iSel) { m_tListBox.GetText(aiListBoxSel[iSel], strSel); m_astrStringsSel.Add(strSel); } } CDialog::OnOK(); }
void SeriesListCtrl::OnDeleteSeries() { POSITION pos=GetFirstSelectedItemPosition(); bool upd=false; void *x; if(pos) { CArray<int,const int&> ToDel; int i; CString temp; while(pos) ToDel.Add(GetItemData(GetNextSelectedItem(pos))); qsort(ToDel.GetData(),ToDel.GetSize(),sizeof(int),compfunc); for(i=0;i<ToDel.GetSize();i++) { int n=ToDel[i]; temp.Format("Series %s contains %d points. Remove it?",Items[n].Name,Items[n].Size); if(AfxMessageBox(temp,MB_YESNO)==IDNO) ToDel[i]=-1; } if((x=Series->GainAcsess(WRITE))!=0) { upd=true; SeriesProtector Protector(x); TSeriesArray& Series(Protector); { for(i=0;i<ToDel.GetSize();i++) if(ToDel[i]>=0) Series.DeleteItem(ToDel[i]); } } if(upd) UpdateSeriesList(); } }
void CSortingListControl::SavePersistentAttributes() { CArray<int, int> arr; arr.SetSize(GetHeaderCtrl()->GetItemCount()); GetColumnOrderArray(arr.GetData(), arr.GetSize()); CPersistence::SetColumnOrder(m_name, arr); for (int i=0; i < arr.GetSize(); i++) arr[i]= GetColumnWidth(i); CPersistence::SetColumnWidths(m_name, arr); // Not so good: CPersistence::SetSorting(m_name, m_sorting.column1, m_sorting.ascending1, m_sorting.column2, m_sorting.ascending2); }
BOOL CFormStreamReader::Read(void *pv, ULONG cb, ULONG *pcbRead) { if(pv == NULL) return FALSE; if(pcbRead == NULL) return FALSE; CArray<BYTE, BYTE> *pBuffer = m_pForm->GetBuffer(); *pcbRead = min(cb, pBuffer->GetCount() - m_pos); memcpy(pv, &pBuffer->GetData()[m_pos], *pcbRead); m_pos += *pcbRead; return (m_pos >= (ULONG)pBuffer->GetCount()) ? FALSE : TRUE; }
bool SgmlFile::ConvertBufferToString(CArray<BYTE, BYTE> &aLineBytes, CString &csLine, UINT nCodepage) { bool bSuccess = true; if (aLineBytes.GetSize() > 0) { #ifdef _UNICODE WCHAR *wszLine = new WCHAR[aLineBytes.GetSize() + 1]; int iChars = ::MultiByteToWideChar(nCodepage, 0, (const char *)aLineBytes.GetData(), aLineBytes.GetSize(), wszLine, aLineBytes.GetSize()); wszLine[iChars] = 0; // TODO what about the data already being Unicode? And in the wrong order? csLine = wszLine; delete[] wszLine; #else aLineBytes.Add(0); csLine = aLineBytes.GetData(); #endif } else // at least a \n was found (empty line) csLine.Empty(); return bSuccess; }
void CRemoveChannelsDlg::OnOK() //----------------------------- { int nCount = m_RemChansList.GetSelCount(); CArray<int,int> aryListBoxSel; aryListBoxSel.SetSize(nCount); m_RemChansList.GetSelItems(nCount, aryListBoxSel.GetData()); m_bKeepMask.assign(m_nChannels, true); for (int n = 0; n < nCount; n++) { m_bKeepMask[aryListBoxSel[n]] = false; } if ((static_cast<UINT>(nCount) == m_nRemove && nCount > 0) || (m_nRemove == 0 && (m_pSndFile->GetNumChannels() >= nCount + m_pSndFile->GetModSpecifications().channelsMin))) CDialog::OnOK(); else CDialog::OnCancel(); }
void CCommunicationTrafficDlg::OnBnClickedCopy() { //-------------------------------------------------------------------------------------------------------------------- CArray <int, int> aryListSel; int nCount= m_DataList.GetSelCount(); aryListSel.SetSize(nCount); m_DataList.GetSelItems(nCount, aryListSel.GetData()); // aryListSel中存的就是选中列的index值,如果需要取内容,加以下语句: CString str,content; for (int i= nCount-1; i>= 0; i--) { m_DataList.GetText(aryListSel.GetAt(i), (CString&)str); str+=_T("\n"); content==str; } //-------------------------------------------------------------------------------------------------------------------- HGLOBAL hClip; //定义一个HGLOBAL句柄变量用来指向分配的内存块 if (OpenClipboard()) { EmptyClipboard(); //将剪贴板内容清空 hClip=GlobalAlloc(GMEM_MOVEABLE,content.GetLength()+1); //在堆上分配可移动的内存块,程序返回一个内存句柄 char * buff; //定义指向字符型的指针变量 buff=(char*)GlobalLock(hClip); //对分配的内存块进行加锁,将内存块句柄转化成一个指针,并将相应的引用计数器加1 strcpy(buff,(char*)content.GetBuffer()); //将用户输入的数据复制到指针变量中,实际上就是复制到分配的内存块中 GlobalUnlock(hClip); //数据写入完毕,进行解锁操作,并将引用计数器数字减1 SetClipboardData(CF_TEXT,hClip); //将存放有数据的内存块放入剪贴板的资源管理中 CloseClipboard(); //关闭剪贴板,释放剪贴板资源的占用权 } //-------------------------------------------------------------------------------------------------------------------- }
void CSelectPassenger::OnSelectPassenger() { int selCount = listboxPassenger.GetSelCount(); CArray<PassengerInfo>& passlist = CConfig::GetConfig().GetPassenger(); CArray<int> selectedIndex; selectedIndex.SetSize(selCount); listboxPassenger.GetSelItems(selCount, selectedIndex.GetData()); for(int i = 0; i < passlist.GetCount(); i++) { for(int j = 0; j < selectedIndex.GetCount(); j++) { CString str; listboxPassenger.GetText(selectedIndex[j], str); if(passlist[i].name == str) { selectedpass.Add(passlist[i]); } } } }
void CChartDlg::UpdateChart() { // Get the indexes of all the selected items. int nCount = m_Datasel.GetSelCount(); if(nCount <= 0) return; UpdateData(); m_Chart.ClearAll(); m_Chart.SetAxis(m_dBase+5.0*m_dVary,m_dBase-5.0*m_dVary,m_dBase,m_dVary*4.0); CArray<int,int> aryListBoxSel; aryListBoxSel.SetSize(nCount); m_Datasel.GetSelItems(nCount, aryListBoxSel.GetData()); int nTotal = nCount; CString sCurr; while(nCount > 0) { m_Datasel.GetText(nTotal-nCount--,sCurr); m_Chart.AddData(atof(sCurr)); } }
void CChartDlg::OnBnClickedAutoupdate() { // TODO: 在此添加控件通知处理程序代码 //auto size the chart int nCount = m_Datasel.GetSelCount(); if(nCount <= 0) return; CArray<int,int> aryListBoxSel; aryListBoxSel.SetSize(nCount); m_Datasel.GetSelItems(nCount, aryListBoxSel.GetData()); int nTotal = nCount; CString sCurr; double new_base=0; while(nCount > 0) { m_Datasel.GetText(nTotal-nCount--,sCurr); new_base += atof(sCurr); } new_base = new_base/nTotal; nCount = nTotal; double new_vary=0; while(nCount > 0) { m_Datasel.GetText(nTotal-nCount--,sCurr); new_vary += (atof(sCurr)-new_base)*(atof(sCurr)-new_base); } new_vary = sqrt(new_vary/nTotal); m_dBase = new_base; m_dVary = new_vary; UpdateData(FALSE); UpdateChart(); }
void main() { CArray arr; arr.Add(1234); arr.Add(23); arr.Add(44); arr.Add(21); arr.Add(5); arr.RemoveAt(2,20000000); //从第二个位置起,删除2个数据 arr.InsertAt(3,10,2); int i = 0; int nSize = arr.GetSize(); cout << "共有 " << nSize << " 条数据" << endl; TYPE *p = arr.GetData(); qsort(p,nSize,sizeof(TYPE),compar); while(i < nSize) { cout << arr[i] << endl; ++i; } }
HRESULT CSwatchesList::OnDraw(ATL_DRAWINFO& di) { RECT& rc = *(RECT*)di.prcBounds; HDC hDC = di.hdcDraw; if (m_swatches) { Draw3DRect(hDC, m_areaRect.left-1, m_areaRect.top-1, m_areaRect.Width()+2, m_areaRect.Height()+2, RGB(0,0,0), RGB(0,0,0)); long scrollposY; m_vert->get_pos(&scrollposY); if (IntersectClipRect(hDC, m_areaRect.left, m_areaRect.top, m_areaRect.right, m_areaRect.bottom)) { POINT oldOrg; SetViewportOrgEx(hDC, m_areaRect.left, m_areaRect.top - scrollposY, &oldOrg); // For CMYK conversion /* TCHAR colorDirectory[MAX_PATH]; DWORD cbSize = sizeof(colorDirectory); GetColorDirectory(NULL, colorDirectory, &cbSize); HPROFILE hDestProfile = NULL; { TCHAR profilePath[MAX_PATH]; _makepath(profilePath, NULL, colorDirectory, "sRGB Color Space Profile.ICM", NULL); PROFILE profile = {0}; profile.dwType = PROFILE_FILENAME; profile.pProfileData = profilePath; profile.cbDataSize = (_tcslen(profilePath)+1)*sizeof(TCHAR); hDestProfile = OpenColorProfile(&profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING); ATLASSERT(hDestProfile); } HPROFILE hTargetProfile = NULL; { TCHAR profilePath[MAX_PATH]; _makepath(profilePath, NULL, colorDirectory, targetProfile, NULL); PROFILE profile = {0}; profile.dwType = PROFILE_FILENAME; profile.pProfileData = profilePath; profile.cbDataSize = (_tcslen(profilePath)+1)*sizeof(TCHAR); hTargetProfile = OpenColorProfile(&profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING); ATLASSERT(hTargetProfile); } LOGCOLORSPACE lcp = {0}; lcp.lcsSignature = LCS_SIGNATURE; lcp.lcsVersion = 0x400; lcp.lcsSize = sizeof(lcp); lcp.lcsCSType = LCS_sRGB; lcp.lcsFilename;// = NULL; // ?? HTRANSFORM hTransform = CreateColorTransform(&lcp, hDestProfile, hTargetProfile, BEST_MODE); ATLASSERT(hTransform); */ // Pattern for drawing ColorType symbols WORD bmdata[8] = { 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, }; HBITMAP hPatBitmap = CreateBitmap(8, 8, 1, 1, bmdata); ATLASSERT(hPatBitmap); HBRUSH hPatBrush = CreatePatternBrush(hPatBitmap); ATLASSERT(hPatBrush); DeleteObject(hPatBitmap); // HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONT lf; GetObject(hFont, sizeof(lf), &lf); lf.lfWeight = FW_BOLD; HFONT hFontSelected = CreateFontIndirect(&lf); HFONT hOldFont = (HFONT)GetCurrentObject(hDC, OBJ_FONT); long nswatches; m_swatches->get_length(&nswatches); int y = 0; for (int i = 0; i < nswatches; i++) { CComPtr<IPDSwatch> swatch; m_swatches->item(i, &swatch); //Rectangle(hDC, itemrect.left, itemrect.top, itemrect.right+1, itemrect.bottom+1); MoveToEx(hDC, 0, y+m_itemHeight, NULL); LineTo(hDC, m_areaRect.Width()+1, y+m_itemHeight); CRect itemrect(0, y+1, m_areaRect.Width(), y+m_itemHeight-1); // itemrect.top += 1; // itemrect.bottom -= 1; bool bSelected = IsSwatchSelected(swatch); if (bSelected) FillSolidRect(hDC, itemrect.left, itemrect.top+1, itemrect.Width(), itemrect.Height()-1, (bSelected)? GetSysColor(COLOR_HIGHLIGHT): GetSysColor(COLOR_WINDOW)); int swatchSize = m_itemHeight-4; int swatchTop = (m_itemHeight-swatchSize)/2; // CRect swatchRect(itemrect.left + 4, itemrect.top+itemrect.Height()/2-8, itemrect.left + 4 + 16, itemrect.top+itemrect.Height()/2-8+16); CRect swatchRect(itemrect.left + 4, itemrect.top+swatchTop, itemrect.left + 4 + swatchSize, itemrect.top+swatchTop+swatchSize); if (bSelected) { SelectObject(hDC, hFontSelected); SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); } else { SelectObject(hDC, hFont); SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); } SetBkMode(hDC, TRANSPARENT); BSTR bname; swatch->get_name(&bname); _bstr_t name = _bstr_t(bname, false); PDSwatchType swatchType; swatch->get_swatchType(&swatchType); CRect trect = itemrect; trect.left = swatchRect.right + 4; trect.right -= 30; if (swatchType == SWATCH_NONE) { FillSolidRect(hDC, &swatchRect, RGB(255, 255, 255)); HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); HPEN hOldPen = (HPEN)SelectObject(hDC, hPen); MoveToEx(hDC, swatchRect.left+1, swatchRect.bottom-1, NULL); LineTo(hDC, swatchRect.right-1, swatchRect.top+1); SelectObject(hDC, hOldPen); DeleteObject(hPen); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle(hDC, swatchRect.left, swatchRect.top, swatchRect.right, swatchRect.bottom); SelectObject(hDC, hOldBrush); } else if (swatchType == SWATCH_COLOR || swatchType == SWATCH_TINT) { CComPtr<IPDColor> color; CComQIPtr<IPDSwatchColor> swatchColor; if (swatchType == SWATCH_COLOR) { swatchColor = swatch; swatchColor->get_color(&color); } else { CComQIPtr<IPDSwatchTint> swatchTint = swatch; swatchTint->get_swatchColor(&swatchColor); swatchTint->get_finalColor(&color); CRect trect2 = trect; trect.right -= 28; trect2.left = trect.right; double tint; swatchTint->get_tint(&tint); CUString str; str.Format("%d %%", (int)(tint*100)); DrawText(hDC, str, str.GetLength(), &trect2, DT_SINGLELINE | DT_VCENTER); } PDColorMode colorMode; color->get_colorMode(&colorMode); COLORREF clr; if (colorMode == COLORMODE_RGB) { double red; color->getChannel(0, &red); double green; color->getChannel(1, &green); double blue; color->getChannel(2, &blue); clr = RGB(red, green, blue); } else if (colorMode == COLORMODE_CMYK) { /* if (hTransform) { double cyan; color->getChannel(0, &cyan); double magenta; color->getChannel(1, &magenta); double yellow; color->getChannel(2, &yellow); double black; color->getChannel(3, &black); COLOR incolor; incolor.cmyk.cyan = cyan*65535/255; incolor.cmyk.magenta = magenta*65535/255; incolor.cmyk.yellow = yellow*65535/255; incolor.cmyk.black = black*65535/255; COLOR outcolor; BOOL bSuccess = TranslateColors(hTransform, &incolor, 1, COLOR_CMYK, &outcolor, COLOR_RGB); ATLASSERT(bSuccess); clr = RGB( outcolor.rgb.red*255.0/65535, outcolor.rgb.green*255.0/65535, outcolor.rgb.blue*255.0/65535); } else */ clr = -1; } if (clr != -1) { HBRUSH hBrush = CreateSolidBrush(clr); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); Rectangle(hDC, swatchRect.left, swatchRect.top, swatchRect.right, swatchRect.bottom); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } { CRect rc(itemrect.right-15, itemrect.top+4, itemrect.right-15+10, itemrect.top+4+10); if (colorMode == COLORMODE_RGB) { Rectangle(hDC, rc.left, rc.top-1, rc.right+1, rc.bottom+1); FillSolidRect(hDC, rc.left+1, rc.top, 3, rc.Height(), RGB(255, 0, 0)); FillSolidRect(hDC, rc.left+4, rc.top, 3, rc.Height(), RGB(0, 255, 0)); FillSolidRect(hDC, rc.left+7, rc.top, 3, rc.Height(), RGB(0, 0, 255)); } else if (colorMode == COLORMODE_CMYK) { // { HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 255)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.left, rc.top, rc.left+rc.Width(), rc.top, rc.left+rc.Width()/2, rc.top+rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } // { HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 0)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.right, rc.top, rc.right, rc.top+rc.Height(), rc.right-rc.Width()/2, rc.top+rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } // { HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.left, rc.bottom, rc.left+rc.Width(), rc.bottom, rc.left+rc.Width()/2, rc.bottom-rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } // { HBRUSH hBrush = CreateSolidBrush(RGB(0, 255, 255)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.left, rc.top, rc.left, rc.top+rc.Height(), rc.left+rc.Width()/2, rc.top+rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } } } { CRect rc(m_areaRect.right-28, y+4, m_areaRect.right-28+10, y+4+10); PDColorType colorType; swatchColor->get_colorType(&colorType); int oldBkMode = SetBkMode(hDC, OPAQUE); COLORREF oldTextClr = SetTextColor(hDC, RGB(100,100,100)); COLORREF oldBkClr = SetBkColor(hDC, RGB(255,255,255)); if (colorType == COLORTYPE_PROCESS) { HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hPatBrush); Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); SelectObject(hDC, hOldBrush); } else if (colorType == COLORTYPE_SPOT) { Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); HPEN hPen = CreatePen(PS_SOLID, 1, RGB(120, 120, 120)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hPatBrush); HPEN hOldPen = (HPEN)SelectObject(hDC, hPen); Ellipse(hDC, rc.left+2, rc.top+2, rc.right-2, rc.bottom-2); SelectObject(hDC, hOldBrush); SelectObject(hDC, hOldPen); DeleteObject(hPen); } else ATLASSERT(0); SetBkMode(hDC, oldBkMode); SetTextColor(hDC, oldTextClr); SetBkColor(hDC, oldBkClr); } } else if (swatchType == SWATCH_GRADIENT) { Gdiplus::Graphics graphics(hDC); CComQIPtr<IPDSwatchGradient> swatchGradient = swatch; CComPtr<IPDGradient> gradient; swatchGradient->get_gradient(&gradient); PDGradientType gradientType; gradient->get_type(&gradientType); Gdiplus::Rect rc(swatchRect.left, swatchRect.top, swatchRect.Width(), swatchRect.Height()); CArray<Gdiplus::REAL, Gdiplus::REAL> offsets; CArray<Gdiplus::Color,Gdiplus::Color&> colors; CreateGradient(offsets, colors, gradient); if (gradientType == GRADIENT_LINEAR) { Gdiplus::LinearGradientBrush brush(rc, Gdiplus::Color(0,0,0), Gdiplus::Color(0,0,0), Gdiplus::LinearGradientModeHorizontal); brush.SetInterpolationColors(colors.GetData(), offsets.GetData(), colors.GetSize()); graphics.FillRectangle(&brush, rc); } else if (gradientType == GRADIENT_RADIAL) { Gdiplus::GraphicsPath path; path.AddEllipse(rc); Gdiplus::PathGradientBrush brush(&path); brush.SetInterpolationColors(colors.GetData(), offsets.GetData(), colors.GetSize()); graphics.FillRectangle(&brush, rc); } else ATLASSERT(0); } else if (swatchType == SWATCH_PATTERN) { Gdiplus::Graphics graphics(hDC); CComQIPtr<IPDSwatchPattern> swatchPattern = swatch; CComPtr<IPDObjectGroup> objectGroup; swatchPattern->get_objectGroup(&objectGroup); RectD bbox; objectGroup->getExpandedBBox(&bbox); int width = swatchRect.Width(); int height = (bbox.Height * width/bbox.Width);//+0.5; if (height > swatchRect.Height()) { height = swatchRect.Height(); width = (bbox.Width * height/bbox.Height);//+0.5; } ATLASSERT(width <= bbox.Width); double magnify = width/bbox.Width; int left = (swatchRect.Width()-width)/2; int top = (swatchRect.Height()-height)/2; CComPtr<IPDRenderer> renderer; renderer.CoCreateInstance(CLSID_PDRenderer); if (renderer) { Gdiplus::Bitmap bitmap(width, height); { Gdiplus::Graphics bmgraphics(&bitmap); bmgraphics.FillRectangle(&Gdiplus::SolidBrush(Gdiplus::Color(255, 255, 255)), 0, 0, width, height); // Gdiplus::Graphics& bmgraphics = graphics; // CComQIPtr<IPDObjectTransformable> transformable = objectGroup; // RectD bounds; // transformable->get_bounds(&bounds); // bmgraphics.TranslateTransform(swatchRect.left+left, swatchRect.top+top); bmgraphics.ScaleTransform(magnify, magnify); bmgraphics.TranslateTransform(-bbox.X, -bbox.Y); // bmgraphics.TranslateTransform(-bounds.X, -bounds.Y); renderer->put_magnify(magnify); renderer->put_targetHDC((HDC)&bmgraphics); renderer->RenderObject(objectGroup); } graphics.DrawImage(&bitmap, swatchRect.left+left, swatchRect.top+top); } } DrawText(hDC, name, name.length(), &trect, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS); y += m_itemHeight; } SelectObject(hDC, hOldFont); DeleteObject(hFontSelected); DeleteObject(hPatBrush); /* if (hTransform) DeleteColorTransform(hTransform); if (hDestProfile) CloseColorProfile(hDestProfile); */ SetViewportOrgEx(hDC, oldOrg.x, oldOrg.y, NULL); } } return S_OK; }
BOOL COwnerDrawnListControl::OnEraseBkgnd(CDC* pDC) { int i = 0; ASSERT(GetHeaderCtrl()->GetItemCount() > 0); // We should recalculate m_yFirstItem here (could have changed e.g. when // the XP-Theme changed). if(GetItemCount() > 0) { CRect rc; GetItemRect(GetTopIndex(), rc, LVIR_BOUNDS); m_yFirstItem = rc.top; } // else: if we did the same thing as in OnColumnsCreated(), we get // repaint problems. const COLORREF gridColor = RGB(212,208,200); CRect rcClient; GetClientRect(rcClient); CRect rcHeader; GetHeaderCtrl()->GetWindowRect(rcHeader); ScreenToClient(rcHeader); CRect rcBetween = rcClient; // between header and first item rcBetween.top = rcHeader.bottom; rcBetween.bottom = m_yFirstItem; pDC->FillSolidRect(rcBetween, gridColor); CArray<int, int> columnOrder; columnOrder.SetSize(GetHeaderCtrl()->GetItemCount()); GetColumnOrderArray(columnOrder.GetData(), int(columnOrder.GetSize())); CArray<int, int> vertical; vertical.SetSize(GetHeaderCtrl()->GetItemCount()); int x = - GetScrollPos(SB_HORZ); HDITEM hdi; ZeroMemory(&hdi, sizeof(hdi)); hdi.mask = HDI_WIDTH; for(i = 0; i < GetHeaderCtrl()->GetItemCount(); i++) { GetHeaderCtrl()->GetItem(columnOrder[i], &hdi); x += hdi.cxy; vertical[i]= x; } if(m_showGrid) { CPen pen(PS_SOLID, 1, gridColor); CSelectObject sopen(pDC, &pen); for(int y = m_yFirstItem + GetRowHeight() - 1; y < rcClient.bottom; y += GetRowHeight()) { pDC->MoveTo(rcClient.left, y); pDC->LineTo(rcClient.right, y); } // BUGBUG: re-using i could be a potential bug! for(i = 0; i < vertical.GetSize(); i++) { pDC->MoveTo(vertical[i] - 1, rcClient.top); pDC->LineTo(vertical[i] - 1, rcClient.bottom); } } const int gridWidth = m_showGrid ? 1 : 0; const COLORREF bgcolor = ::GetSysColor(COLOR_WINDOW); const int lineCount = GetCountPerPage() + 1; const int firstItem = GetTopIndex(); const int lastItem = min(firstItem + lineCount, GetItemCount()) - 1; ASSERT(GetItemCount() == 0 || firstItem < GetItemCount()); ASSERT(GetItemCount() == 0 || lastItem < GetItemCount()); ASSERT(GetItemCount() == 0 || lastItem >= firstItem); const int itemCount = lastItem - firstItem + 1; CRect fill; fill.left = vertical[vertical.GetSize() - 1]; fill.right = rcClient.right; fill.top = m_yFirstItem; fill.bottom = fill.top + GetRowHeight() - gridWidth; for(i = 0; i < itemCount; i++) { pDC->FillSolidRect(fill, bgcolor); fill.OffsetRect(0, GetRowHeight()); } int top = fill.top; while(top < rcClient.bottom) { fill.top = top; fill.bottom = top + GetRowHeight() - gridWidth; int left = 0; for(int i = 0; i < vertical.GetSize(); i++) { fill.left = left; fill.right = vertical[i] - gridWidth; pDC->FillSolidRect(fill, bgcolor); left = vertical[i]; } fill.left = left; fill.right = rcClient.right; pDC->FillSolidRect(fill, bgcolor); top += GetRowHeight(); } return true; }
/****************************************************************************** Function Name : OnBnClickedCbtnDissociate Input(s) : Output : Functionality : Call the functions to remove the selected Databases Member of : CDatabaseDissociateDlg Friend of : - Author(s) : Anish Kumar Date Created : 06.12.2006 Modifications : ******************************************************************************/ void CDatabaseDissociateDlg::OnBnClickedCbtnDissociate() { //TO store the path of files dissociated CStringArray aomStrFilesDissociated; CMainFrame* pMainFrame = (CMainFrame*)theApp.m_pMainWnd; // Get the indexes of all the selected items. int nCount = m_omDissociateDbLst.GetSelCount(); if(nCount > 0) { // Array of selected item's position CArray<int,int> aomListBoxSel; aomListBoxSel.SetSize(nCount); //Pass the array pointer to get the selected item's positions m_omDissociateDbLst.GetSelItems(nCount, aomListBoxSel.GetData()); aomStrFilesDissociated.RemoveAll(); for(int nTempCnt = 0 ; nTempCnt < nCount ; nTempCnt++) { BOOL bDBDeleted = FALSE; CString omstrDBPath ; //Selected file's index int nSelectedPos = aomListBoxSel.GetAt(nTempCnt); //Find the length of string to pass the buffer to have the selected File path int nBufferSize = m_omDissociateDbLst.GetTextLen(nSelectedPos); m_omDissociateDbLst.GetText(nSelectedPos,omstrDBPath.GetBuffer(nBufferSize)); bDBDeleted = (*(CMsgSignal**)(m_sDbParams.m_ppvImportedDBs))->bDeAllocateMemory(omstrDBPath.GetBuffer(0)); if(TRUE == bDBDeleted) { aomStrFilesDissociated.Add(omstrDBPath.GetBuffer(0)); } } //To remove from theApp class CStringArray aomstrDBFiles; (*(CMsgSignal**)(m_sDbParams.m_ppvImportedDBs))->vGetDataBaseNames(&aomstrDBFiles); //Delete the file path from the List box int nTotalCount = aomStrFilesDissociated.GetSize(); CString omStrTempFile; for(int nCount=0 ; nCount<nTotalCount ; nCount++) { omStrTempFile = aomStrFilesDissociated.GetAt(nCount); int nIndex = 0; if( (nIndex = m_omDissociateDbLst.FindString(0, omStrTempFile)) != LB_ERR ) { //Delete the file path from the list box m_omDissociateDbLst.DeleteString(nIndex); int nStoredFile = aomstrDBFiles.GetSize(); CString omStrTemp; BOOL bRemoved = FALSE; for(int nTemp = 0 ; nTemp < nStoredFile && bRemoved != TRUE; nTemp++) { omStrTemp = aomstrDBFiles.GetAt(nTemp); if(!(omStrTemp.Compare(omStrTempFile))) { aomstrDBFiles.RemoveAt(nTemp); bRemoved = TRUE; } } } } //Set the new file name array (*(CMsgSignal**)(m_sDbParams.m_ppvImportedDBs))->vSetDataBaseNames(&aomstrDBFiles); // Send a message to Tx Window about database change if( pMainFrame != NULL) { eUSERSELCTION eUserSel = eDATABASEIMPORTCMD; pMainFrame->m_objTxHandler.vPostMessageToTxWnd(WM_USER_CMD, (WPARAM)eUserSel,0); } ////Delete Signal watch list and Graph window list //// Check for Signal Watch & DLL load Condition // BOOL bUserOption = FALSE; if(pMainFrame->m_psSignalWatchList != NULL) { if(theApp.m_bFromAutomation == FALSE) bUserOption = AfxMessageBox(defIMPORT_WARNING, MB_YESNO | MB_DEFBUTTON1 | MB_ICONQUESTION) == IDYES; // If user wants to clear if(bUserOption == TRUE ) { // Clear Signal Watch List pMainFrame->vUpdateSWList(); } } //Added by Arun to update Data Handler Main entry list. //pMainFrame->vUpdateMainEntryListInWaveDataHandler(); //pMainFrame->vClearSignalInfoList(); //if(!pMainFrame->m_ouWaveTransmitter.bIsBlockEnabled()) // theApp.pouGetFlagsPtr()->vSetFlagStatus( SEND_SIGNAL_MSG, FALSE ); //Update Message windows pMainFrame->vUpdateAllMsgWndInterpretStatus(FALSE); // Check for Graph list for(register int nBusID = CAN; nBusID < AVAILABLE_PROTOCOLS; nBusID++) { if( pMainFrame->m_odGraphList[nBusID].m_omElementList.GetSize() > 0 ) { // Get the delete confirmation from the user if(theApp.m_bFromAutomation == FALSE) bUserOption = AfxMessageBox(defIMPORT_WARNING_GRAPH, MB_YESNO | MB_DEFBUTTON1 | MB_ICONQUESTION) == IDYES; // If user wants to clear if(bUserOption == TRUE ) { // Clear Graph List for all buses. for(register int nID = CAN; nID < AVAILABLE_PROTOCOLS; nID++) pMainFrame->m_odGraphList[nID].m_omElementList.RemoveAll(); // Send the Message to the Left View to Update List for all buses if( pMainFrame != NULL ) { pMainFrame->vPostConfigChangeCmdToSigGrphWnds(); } } break; } } } }
void CRevisionGraphWnd::DrawConnections (GraphicsDevice& graphics, const CRect& /*logRect*/, const CSize& offset) { CArray<PointF> points; CArray<CPoint> pts; if(graphics.graphics) graphics.graphics->SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); float penwidth = 2*m_fZoomFactor<1? 1:2*m_fZoomFactor; Gdiplus::Pen pen(Color(0,0,0),penwidth); // iterate over all visible lines edge e; forall_edges(e, m_Graph) { // get connection and point position const DPolyline &dpl = this->m_GraphAttr.bends(e); points.RemoveAll(); pts.RemoveAll(); PointF pt; pt.X = (REAL)m_GraphAttr.x(e->source()); pt.Y = (REAL)m_GraphAttr.y(e->source()); points.Add(pt); ListConstIterator<DPoint> it; for(it = dpl.begin(); it.valid(); ++it) { pt.X = (REAL)(*it).m_x; pt.Y = (REAL)(*it).m_y; points.Add(pt); } pt.X = (REAL)m_GraphAttr.x(e->target()); pt.Y = (REAL)m_GraphAttr.y(e->target()); points.Add(pt); points[0] = this->cutPoint(e->source(), 1, points[0], points[1]); points[points.GetCount()-1] = this->cutPoint(e->target(), 1, points[points.GetCount()-1], points[points.GetCount()-2]); // draw the connection for (int i = 0; i < points.GetCount(); ++i) { //CPoint pt; points[i].X = points[i].X * this->m_fZoomFactor - offset.cx; points[i].Y = points[i].Y * this->m_fZoomFactor - offset.cy; //pts.Add(pt); } if (graphics.graphics) { graphics.graphics->DrawLines(&pen, points.GetData(), (INT)points.GetCount()); } else if (graphics.pSVG) { Color color; color.SetFromCOLORREF(GetSysColor(COLOR_WINDOWTEXT)); graphics.pSVG->Polyline(points.GetData(), (int)points.GetCount(), Color(0,0,0), (int)penwidth); } else if (graphics.pGraphviz) { CString hash1 = _T("g") + m_logEntries[e->target()->index()].ToString().Left(g_Git.GetShortHASHLength()); CString hash2 = _T("g") + m_logEntries[e->source()->index()].ToString().Left(g_Git.GetShortHASHLength()); graphics.pGraphviz->DrawEdge(hash1, hash2); } //draw arrow double dx = points[1].X - points[0].X; double dy = points[1].Y - points[0].Y; double len = sqrt(dx*dx + dy*dy); dx = m_ArrowSize * m_fZoomFactor *dx /len; dy = m_ArrowSize * m_fZoomFactor *dy /len; double p1_x, p1_y, p2_x, p2_y; p1_x = dx * m_ArrowCos - dy * m_ArrowSin; p1_y = dx * m_ArrowSin + dy * m_ArrowCos; p2_x = dx * m_ArrowCos + dy * m_ArrowSin; p2_y = -dx * m_ArrowSin + dy * m_ArrowCos; //graphics.graphics->DrawLine(&pen, points[0].X,points[0].Y, points[0].X +p1_x,points[0].Y+p1_y); //graphics.graphics->DrawLine(&pen, points[0].X,points[0].Y, points[0].X +p2_x,points[0].Y+p2_y); GraphicsPath path; PointF arrows[5]; arrows[0].X = points[0].X; arrows[0].Y = points[0].Y; arrows[1].X = points[0].X + (REAL)p1_x; arrows[1].Y = points[0].Y + (REAL)p1_y; arrows[2].X = points[0].X + (REAL)dx*3/5; arrows[2].Y = points[0].Y + (REAL)dy*3/5; arrows[3].X = points[0].X + (REAL)p2_x; arrows[3].Y = points[0].Y + (REAL)p2_y; arrows[4].X = points[0].X; arrows[4].Y = points[0].Y; path.AddLines(arrows, 5); path.SetFillMode(FillModeAlternate); if(graphics.graphics) { graphics.graphics->DrawPath(&pen, &path); }else if(graphics.pSVG) { graphics.pSVG->DrawPath(arrows, 5, Color(0,0,0), (int)penwidth, Color(0,0,0)); } } }
// protected: BOOL COXSplashWnd::BuildRegion(POINT ptStart) // --- In : ptStart, the starting point to search for region boundary // --- Out : // --- Returns : TRUE if successful; FALSE otherwise // --- Effect : calculate the region to be visible in a bitmap { CArray<CPoint, CPoint&> vertexs; CPoint ptMax(0,0); CPoint pt0(0,0); CPoint pt1(0,0); CPoint pt(0,0); CPoint ptPrev(0,0); CSize sizeInc(0,0); int i = 0; int iFirst = 0; int iLast = 0; int iPrev = 0; // move directions: index (xInc, yInc) alternate_index // 0 (-1,-1) 8 1 ( 0,-1) 9 2 ( 1,-1) 10 // 7 (-1, 0) 15 3 ( 1, 0) 11 // 6 (-1, 1) 14 5 ( 0, 1) 13 4 ( 1, 1) 12 const int xd[] = {-1,0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1}; const int yd[] = {-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1,1,1,0}; const int nextdir[] = {6,0,0,2,2,4,4,6,6,0,0,2,2,4,4,6}; BITMAP bm; m_dib.GetBitmapInfo(bm); ptMax = CPoint(bm.bmWidth - 1, bm.bmHeight - 1); // find a start point that's outside the region UNREFERENCED_PARAMETER(ptStart); pt0 = CPoint(0,0); if (!IsBorder(pt0)) pt0 = CPoint(-1,-1); // search diagonally for first point that's within the region sizeInc.cx = (pt0.x > (ptMax.x / 2)) ? -1 : 1; sizeInc.cy = (pt0.y > (ptMax.y / 2)) ? -1 : 1; for (pt1 = pt0 + sizeInc; IsBorder(pt1, FALSE); pt1 += sizeInc) ; pt0 = pt1 - sizeInc; // if not found after hitting the boundary, search by scan lines if (m_dib.GetPixel(pt1) == CLR_INVALID) { for (pt1.y = 0; pt1.y <= ptMax.y; pt1.y++) { for (pt1.x = 0; pt1.x <= ptMax.x && IsBorder(pt1); pt1.x++) ; if (pt1.x <= ptMax.x) break; } if (ptMax.y < pt1.y) return FALSE; pt0 = pt1 - CSize(0, 1); } // now pt1 should be the starting point that's within the region // and pt0 should be a neigboring point that's outside the region ASSERT(IsBorder(pt0) && !IsBorder(pt1)); // clockwise find border/region boundary for (i = 0; i <= 7; i++) { pt = pt1 + CSize(xd[i], yd[i]); if (!IsBorder(pt)) break; } if (i == 8) return FALSE; // important: assign second point as the start point to prevent // diagonal circumvent pt1 = pt; vertexs.Add(pt); // cycle until the most beginning point is found back again do { iPrev = i; ptPrev = pt; iFirst = nextdir[i]; iLast = iFirst + 6; for (i = iFirst; i <= iLast; i++) { pt = ptPrev + CSize(xd[i], yd[i]); if (!IsBorder(pt)) break; } if (i == iPrev) { // moving forward on the same direction // replace the last point with this new one, so that region // definition could be simpler vertexs[vertexs.GetSize()-1] = pt; } else { // direction changed, has to add a new vertex vertexs.Add(pt); } if(vertexs.GetSize()%3000==0) TRACE(_T("Add point: %d,%d, number %d\n"),pt.x,pt.y,vertexs.GetSize()); } while (pt != pt1); m_rgn.DeleteObject(); if (!m_rgn.CreatePolygonRgn(vertexs.GetData(), PtrToInt(vertexs.GetSize()), ALTERNATE)) { ASSERT((HRGN)m_rgn == NULL); return FALSE; } return TRUE; }
void cGraphicsMFC::drawpolygon(cPolygon *ppolygon, int drawflags ) { //Leave the polygon itself alone, but make a copy of its verts and transform them. CArray<cVector, cVector &>* ptransformedvert = ppolygon->transformedVert(_matrix); cVector transformcenter = _matrix*ppolygon->center(); //We assume that the transformed poly has the same radius as the ppolygon, that is, we assume //that _matrix is a rigid body transformation, that is, it has no scale or sheer. //Then convert to pixel coords. int intdotradius, intlinewidth; // int intcenterx, intcentery, intradiusx, intradiusy; // _realpixelconverter.realToPixel(transformcenter.x(), transformcenter.y(), &intcenterx, &intcentery); // _realpixelconverter.realToIntAnisotropic(ppolygon->radius(), &intradiusx, &intradiusy); CArray<CPoint, CPoint &> pointvert; //Helper pointvert.SetSize(ppolygon->vertCount()); /* I fill pointvert in a slightly awkward way because the compiler gets confused and throws an error if I try and use &(pointvert[i].x) as the third argument to realToPixel, which expects an int* there, and is happy with the &x for the local x, but if I try and generate a pointer to the x-field of the CPoint in the pointvert array, the compiler doesn't like it. So I work around it. */ int pix_x, pix_y; for (int i = 0; i<ppolygon->vertCount(); i++) { _realpixelconverter.realToPixel(ptransformedvert->GetAt(i).x(), ptransformedvert->GetAt(i).y(), &pix_x, &pix_y); pointvert[i].x = pix_x; pointvert[i].y = pix_y; } _realpixelconverter.realToInt(ppolygon->dotRadius(), &intdotradius); _realpixelconverter.realToInt(ppolygon->radius()*ppolygon->lineWidthWeight(), &intlinewidth); if (!intlinewidth) /* This is why setting _reallinewidthweight to 0.0 or to LW_IGNORELINEWIDTHWEIGHT has the effect of making it be _linewidth */ intlinewidth = ppolygon->lineWidth(); //Now draw the polygon CBrush cbrush, *pbrush_old; CPen cpen, *ppen_old; if (!ppolygon->vertCount()) return; if (ppolygon->filled() && !(drawflags & CPopView::DF_WIREFRAME)) cbrush.CreateSolidBrush(ppolygon->fillColor()); else cbrush.CreateStockObject(NULL_BRUSH); pbrush_old = _pMemDC->SelectObject(&cbrush); if (ppolygon->edged() || (drawflags & CPopView::DF_WIREFRAME)) cpen.CreatePen(PS_SOLID, intlinewidth, ppolygon->lineColor()); else cpen.CreateStockObject(NULL_PEN); ppen_old = _pMemDC->SelectObject(&cpen); //draw a polygon. /* We draw the polygons using standard CDC::Polygon(POINT *, int) function. The CArray::GetData function turns a CArray into a simple CPoint * array, and we can use this without a further cast into (POINT *). */ _pMemDC->Polygon(pointvert.GetData(), ppolygon->vertCount()); if (ppolygon->dotted()) { /* The only safe way to "change a brush color" is to actually get rid of the old brush and make a new one. Note that it is permissible to call DeleteObject even if cbrush hold the NULL_BRUSH, as a call to delte a stock object actually does nothing. */ _pMemDC->SelectObject(pbrush_old); //Need to unselect the brush before deleting cbrush.DeleteObject(); //Delete the brush. if (ppolygon->pdotcolorstyle()->filled() && !(drawflags & CPopView::DF_WIREFRAME)) cbrush.CreateSolidBrush(ppolygon->pdotcolorstyle()->fillColor()); else cbrush.CreateStockObject(NULL_BRUSH); pbrush_old = _pMemDC->SelectObject(&cbrush); for (i=0; i<ppolygon->vertCount(); i++) #ifndef TRUESTAR //Only draw half the dots if you're not using TRUESTAR, //which is a switch in spritepolygon.h if (i%2 == 0 || ppolygon->convex()) #endif //TRUESTAR _pMemDC->Ellipse(CRect(pointvert[i].x - intdotradius, pointvert[i].y - intdotradius, pointvert[i].x + intdotradius, pointvert[i].y + intdotradius)); } _pMemDC->SelectObject(pbrush_old); _pMemDC->SelectObject(ppen_old); cbrush.DeleteObject(); //Don't trust the destructor to do the DeleteObject. cpen.DeleteObject(); }
void CAccessCtrl::OnAccessCtrlRemove() { int cnt = m_ListBox.GetSelCount(); if(cnt <= 0) return; // confirmation if(AfxMessageBox("Are you sure you want to delete the access permission for selected user(s)?", MB_YESNO) != IDYES) { return; } CArray<int, int> selections; selections.SetSize(cnt); m_ListBox.GetSelItems(cnt, selections.GetData()); CMainFrame* frame = (CMainFrame*)AfxGetMainWnd(); CString irodsZone = ""; CString newPermission = "null"; int i,j; int t; int recursive; if(m_objType == irodsWinObj::IRODS_DATAOBJ_TYPE) { recursive = false; } else if(m_objType == irodsWinObj::IRODS_COLLECTION_TYPE) { recursive = m_recursiveCheckBtn.GetCheck(); } else { return; // should never happen. } this->BeginWaitCursor(); for(i=0;i<cnt;i++) { j = selections[cnt - i -1]; t = irodsWinSetAccessControl(m_doc->conn, irodsZone, irodsUsers[j], newPermission, m_irodsPath, recursive); if(t < 0) { this->EndWaitCursor(); CString msgHead = CString("Remove Access Permission() error"); m_doc->disp_err_msgbox(msgHead, t); return; } m_ListBox.DeleteString(j); irodsUsers.RemoveAt(j); irodsConstraints.RemoveAt(j); } this->EndWaitCursor(); #if 0 for(int i = 0; i < count; i++) { node = (WINI::IAccessNode*)m_ListBox.GetItemData(selections[i]); m_OK.EnableWindow(FALSE); status = m_doc->ModifyAccess(node, "null", (bool)m_Recursive.GetCheck()); m_OK.EnableWindow(TRUE); if(!status.isOk()) AfxMessageBox(status.GetError()); } delete [] selections; Update(); #endif }
SSHANDLE* CSSolid::CreateNewVertexList(CSSFace *pFace, CSSEdge *pEdge1, CSSEdge *pEdge2, int& nv1index, int& nv2index, CSSVertex *pNewVertex1, CSSVertex *pNewVertex2) { // get original vertex list CArray<SSHANDLE, SSHANDLE&> hVertexList; hVertexList.SetSize(pFace->nEdges+4); CreatePointHandleList(*pFace, hVertexList.GetData()); // add vertex1 and vertex2. nv1index = -1; nv2index = -1; int nVertices = pFace->nEdges; int iPass = 0; DoAgain: for(int i = 0; i < nVertices; i++) { int iPrevIndex = GetNext(i, -1, nVertices); int iNextIndex = GetNext(i, 1, nVertices); if(nv1index == -1 && (hVertexList[i] == pEdge1->hvEnd || hVertexList[i] == pEdge1->hvStart)) { // find pEdge1->hvStart if(hVertexList[iPrevIndex] == pEdge1->hvStart || hVertexList[iPrevIndex] == pEdge1->hvEnd) { // add at i. nv1index = i; } if(hVertexList[iNextIndex] == pEdge1->hvStart || hVertexList[iNextIndex] == pEdge1->hvEnd) { // add at iNextIndex nv1index = iNextIndex; } if(nv1index != -1) { hVertexList.InsertAt(nv1index, pNewVertex1->id); ++nVertices; break; } } if(nv2index == -1 && (hVertexList[i] == pEdge2->hvEnd || hVertexList[i] == pEdge2->hvStart)) { // find pEdge1->hvStart if(hVertexList[iPrevIndex] == pEdge2->hvStart || hVertexList[iPrevIndex] == pEdge2->hvEnd) { // add at i. nv2index = i; } if(hVertexList[iNextIndex] == pEdge2->hvStart || hVertexList[iNextIndex] == pEdge2->hvEnd) { // add at iNextIndex nv2index = iNextIndex; } if(nv2index != -1) { hVertexList.InsertAt(nv2index, pNewVertex2->id); ++nVertices; break; } } } SSHANDLE hTmp[64]; memcpy(hTmp, hVertexList.GetData(), sizeof(SSHANDLE) * nVertices); if(nv1index == -1 && nv2index == -1) return NULL; // not used here. if(nv1index == -1 || nv2index == -1) { if(++iPass != 2) goto DoAgain; } SSHANDLE *rvl = new SSHANDLE[nVertices]; memcpy(rvl, hVertexList.GetData(), sizeof(SSHANDLE) * nVertices); return rvl; }
BOOL ConvertStringToSendData(const CString & s, CByteArray & msg) { #ifdef _UNICODE int n = ::WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL); if(n == 0) { /* failed */ //DWORD err = ::GetLastError(); msg.SetSize(0); return FALSE; } /* failed */ else { /* success */ msg.SetSize(n); n = ::WideCharToMultiByte(CP_UTF8, 0, s, -1, (LPSTR)msg.GetData(), n, NULL, NULL); if(n == 0) { /* conversion failed */ DWORD err = ::GetLastError(); msg.SetSize(0); return FALSE; } /* conversion failed */ else { /* use multibyte string */ msg.SetSize(n - 1); return TRUE; } /* use multibyte string */ } /* success */ #else // ANSI CArray<WCHAR, WCHAR> wc; int n = ::MultiByteToWideChar(CP_ACP, 0, s, -1, NULL, 0); if(n == 0) { /* failed */ DWORD err = ::GetLastError(); msg.SetSize(0); return FALSE; } /* failed */ else { /* success */ wc.SetSize(n); n = ::MultiByteToWideChar(CP_ACP, 0, s, -1, wc.GetData(), n); } /* success */ n = ::WideCharToMultiByte(CP_UTF8, 0, wc.GetData(), -1, NULL, 0, NULL, NULL); if(n == 0) { /* failed */ DWORD err = ::GetLastError(); msg.SetSize(0); return FALSE; } /* failed */ else { /* success */ msg.SetSize(n); n = ::WideCharToMultiByte(CP_UTF8, 0, wc.GetData(), -1, (LPSTR)msg.GetData(), n, NULL, NULL); if(n == 0) { /* conversion failed */ DWORD err = ::GetLastError(); msg.SetSize(0); return FALSE; } /* conversion failed */ else { /* use multibyte string */ msg.SetSize(n - 1); return TRUE; } /* use multibyte string */ } /* success */ #endif } // ConvertStringToSendData
void CSkyODL::OnDrawTop(Gdiplus::Graphics& gcDrawer, float fScale) { CBaseODL::OnDrawTop(gcDrawer, fScale); Gdiplus::Pen Dot( m_clDotColor, static_cast<Gdiplus::REAL>(1.0 / fScale)); CArray<Gdiplus::Point> st; CArray<Gdiplus::Point> stMoving; CArray<BYTE> stBytes; for (auto& curItem : m_arrTopPoint) { Gdiplus::Point pt; pt.X = static_cast<INT>(curItem.X()); pt.Y = static_cast<INT>(curItem.Z()); st.Add(pt); } if (IsTopMoving()) { for ( auto& curMoving : m_arrMovingTopPoint ) { Gdiplus::Point pt; pt.X = static_cast<INT>(curMoving.X()); pt.Y = static_cast<INT>(curMoving.Z()); stMoving.Add(pt); } } if(st.GetSize()<=0) { return; } for (int i=0; i<st.GetSize(); ++i) { st[i].X = static_cast<INT>(st[i].X); st[i].Y = static_cast<INT>(st[i].Y); } for (int i=0; i<stMoving.GetSize(); ++i) { stMoving[i].X = static_cast<INT>(stMoving[i].X); stMoving[i].Y = static_cast<INT>(stMoving[i].Y); } Gdiplus::Pen pen( m_clPenColor, static_cast<Gdiplus::REAL>(1.0 / fScale)); pen.SetDashStyle(Gdiplus::DashStyleSolid); if (!IsTopCreating()) { Gdiplus::HatchBrush brush( Gdiplus::HatchStyle(Gdiplus::HatchStyle::HatchStyleCross ), m_clPenColor, Gdiplus::Color(0,255,255,255) ); //画皮肤 gcDrawer.FillPolygon(&brush, st.GetData(), st.GetSize(), Gdiplus::FillMode::FillModeAlternate); } gcDrawer.DrawLines(&pen, st.GetData(), st.GetSize()); if (IsTopMoving()) { Gdiplus::Pen penMoving( m_clDotColor, static_cast<Gdiplus::REAL>(1.0 / fScale)); penMoving.SetDashStyle( Gdiplus::DashStyleSolid); gcDrawer.DrawLines(&penMoving, stMoving.GetData(), stMoving.GetSize()); } if (IsTopSelected()) { //每个转角画一个点 for (int x=0; x<st.GetSize(); x++) { gcDrawer.DrawRectangle(&Dot, (st[x].X) - 3.0f/fScale, (st[x].Y ) - 3.0f/fScale, 6.0f/fScale, 6.0f/fScale); } } }
UWORD ParseCPPLines ( struct SyntaxHandle *handle, LineDef** lines, BSTR textData, UWORD startoffset, UWORD maxlength, CArray <SyntaxChunk, SyntaxChunk>& SyntaxArr ) { SyntaxArr.SetSize(maxlength); // hm.. TODO, add instead SyntaxChunk* syntax = SyntaxArr.GetData(); int ChunkUsed = 0; UWORD parsedlength = 0; BOOL donext; int nline = 0; if (maxlength == 0) return 0; int offset = 0; do { // register UWORD len = linenode->LineLen; UBYTE el = 0; BOOL cont = FALSE; if (offset == 0) /* If first line in the doc */ el = 0; else { // while (!prevline->IsParsed el = 0;//syntax[-1].Element; } // linenode->BegEl = el; /* Attr at beginning of line taken from the previous line's EndAttr */ // if (linenode->Syntax) free(linenode->Syntax); // linenode->Syntax = (SyntaxChunk*)malloc(sizeof(struct SyntaxChunk)*(linenode->LineLen+1)); lines[nline]->m_ckOffset = ChunkUsed; syntax->Length = 0; syntax->Element = el; syntax->Flags = ElementFlags[el]; ChunkUsed += 1; int linelen = lines[nline]->m_lineLength; WCHAR* lineData = &textData[offset]; UWORD col = 0; while (col < linelen) { WCHAR *c = &lineData[col]; UWORD ellen = 1; /* Assume */ UBYTE sel = 255; BOOL off = FALSE; if (!(ctype[*c] & C)) { if (el == 0) ellen = ParseWord(lineData, col, linelen, &sel); } else { if (c[0] == '/') /* This could be the start of a comment */ { if ((el == 0) || (el == EL_PREPROCESSOR)) /* Can have comments on same line as preprocessor */ { if (c[1] == '/') /* CPP comment, set rest of line to that */ { el = EL_CPPCOMMENT; ellen = linelen-col; } else if (c[1] == '*') /* ANSI comment */ { el = EL_COMMENT; ellen = 2; } else { if (el != EL_PREPROCESSOR) /* If it wasn't a comment and we're not */ sel = EL_SYMBOL; /* in preprocessor make it a symbol */ } } } else if (c[0] == '*') /* This could be the end of a comment */ { if ((el == EL_COMMENT) && (c[1] == '/')) { off = TRUE; el = 0; ellen = 2; } else { if (el == 0) /* It was just a normal symbol */ { sel = EL_SYMBOL; } } } else if (c[0] == '\"') /* Either beginning or ending a string quote */ { if (el == 0) /* Beginning */ { el = EL_STRING; } else if (el == EL_STRING) // Maybe it's ending */ { /* Here we check if it's a \", then we check if it's a \\" */ if (((col > 0) && (c[-1] != '\\')) || /* it's not a '\"' */ ((col > 1) && (c[-2] == '\\'))) /* it's a '\\"' */ { off = TRUE; el = 0; } } } else if (c[0] == '\'') /* Either beginning or ending a char quote */ { if (el == 0) /* Beginning */ { el = EL_CHARACTER; } else if (el == EL_CHARACTER) /* Maybe it's ending */ { /* Here we check if it's a \', then we check if it's a \\' */ if (((col > 0) && (c[-1] != '\\')) || /* it's not a \' */ ((col > 1) && (c[-2] == '\\'))) /* it's a \\' */ { off = TRUE; el = 0; } } } else if (c[0] == '#') /* If first non-blank char on line, this is preprocessor statement */ { if (el == 0) { /* TODO: Check if first non-blank */ el = EL_PREPROCESSOR; } } else if (c[0] == '\\') /* If last on line, this is a continuation on the next line */ { if ((col == linelen-1) && /* last on line */ (el != EL_CPPCOMMENT)) { if (el) cont = TRUE; /* Only need to continue if there was some previous el */ } } } if (sel == 255) sel = el; if (off) syntax->Length += ellen; /* If the element has changed goto next syntax chunk */ if (sel != syntax->Element) { // Only create new if the previous syntax chunk contains something // if not, just overwrite that one if (syntax->Length > 0) { ChunkUsed++; syntax++; } syntax->Length = 0; syntax->Element = sel; syntax->Flags = ElementFlags[sel]; } if (!off) syntax->Length += ellen; // CString msg; // msg.Format("%d", syntax->Length); // AfxMessageBox(msg/*(LPCTSTR)(&lineData[col])*/); col += ellen; } // msg.Format("%d, %d, %d", linelen, offset, maxlength); // AfxMessageBox(msg); offset += linelen+1; syntax++; // Always new on each line nline++; #if 0 linenode->Syntax = realloc(linenode->Syntax, linenode->ChunkUsed*sizeof(struct SyntaxChunk)); /* numlines is used later to know the number of lines to visually update folded lines shouldn't be included in this count */ if (!linenode->Folded) parsedlines++; /* Set this line's EndEl */ if ((el == EL_COMMENT) || cont) /* This continues over several lines */ linenode->EndEl= el; else linenode->EndEl = 0; donext = FALSE; /* Assume that we're not gonna parse the next line */ if (--maxlines) { /* Check if Next line is candidate for scanning First check if there IS a next line */ if ((nextline = linenode->Succ)->Succ) { /* If the next line's BegEl is different than the line we just parsed's EndAttr then parse the next one too */ if (nextline->BegEl != linenode->EndEl) { linenode = nextline; donext = TRUE; } } } #endif } while (offset < maxlength/*-1*/); // while (donext); SyntaxArr.SetSize(ChunkUsed); return parsedlength; /* Number of lines that were parsed */ }
ERMsg CUIEnvCanRadar::ExecuteHistorical(CCallback& callback) { ERMsg msg; string workingDir = GetDir(WORKING_DIR); CreateMultipleDir(workingDir); CInternetSessionPtr pSession; CHttpConnectionPtr pConnection; msg = GetHttpConnection(SERVER_NAME[as<size_t>(TYPE)], pConnection, pSession); if (!msg) return msg; callback.AddMessage(GetString(IDS_UPDATE_DIR)); callback.AddMessage(workingDir, 1); callback.AddMessage(GetString(IDS_UPDATE_FROM)); callback.AddMessage(SERVER_NAME[as<size_t>(TYPE)], 1); callback.AddMessage(""); //Get remote station list StringVector imageList; if (msg) msg = GetRadarList(imageList, callback); if (msg) msg = CleanRadarList(imageList, callback); if (!msg) return msg; callback.PushTask("Download historical radar images (" + ToString(imageList.size())+ ")", imageList.size()); //callback.SetNbStep(imageList.size()); int nbRun = 0; int curI = 0; while (curI<imageList.size() && msg) { nbRun++; CInternetSessionPtr pSession; CHttpConnectionPtr pConnection; msg = GetHttpConnection(SERVER_NAME[as<size_t>(TYPE)], pConnection, pSession); if (msg) { TRY { for (int i = curI; i<imageList.size() && msg; i++) { string filePath = GetOutputFilePath(as<size_t>(TYPE), imageList[i]); msg += CreateMultipleDir(GetPath(filePath)); //msg += CopyFile(pConnection, imageList[i], filePath, INTERNET_FLAG_TRANSFER_BINARY | WININET_API_FLAG_SYNC); CString URL(imageList[i].c_str()); CHttpFile* pURLFile = pConnection->OpenRequest(_T("GET"), URL, NULL, 1, NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_TRANSFER_BINARY | WININET_API_FLAG_SYNC | INTERNET_FLAG_NEED_FILE); //CStdioFile* pURLFile = pSession->OpenURL(UtilWin::Convert(imageList[i]), 0, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_EXISTING_CONNECT); bool bRep = false; if (pURLFile != NULL) { if (pURLFile->SendRequest() != 0) { CArray<char> source; int len = 0; CArray<char> tmp; tmp.SetSize(50); DWORD dwStatusCode = 0; pURLFile->QueryInfoStatusCode(dwStatusCode); ULONGLONG length = pURLFile->GetLength(); while (length > 0) { pURLFile->Read(tmp.GetData(), 50); source.Append(tmp); length = pURLFile->GetLength(); } pURLFile->QueryInfoStatusCode(dwStatusCode); pURLFile->Close(); ofStream file; msg = file.open(filePath, ios::out | ios::binary); if (msg) { if (!source.IsEmpty()) file.write(source.GetData(), (UINT)source.GetSize()); file.close(); //convert image to GeoTiff //ConvertToGeotiff(filePath, CCanadianRadar(CCanadianRadar::coord)); } } } if (msg) { curI++; nbRun = 0; msg += callback.StepIt(); } } } CATCH_ALL(e) { msg = UtilWin::SYGetMessage(*e); } END_CATCH_ALL //if an error occur: try again if (!msg && !callback.GetUserCancel()) { //callback.AddTask(1);//one step more if (nbRun < 5) { callback.AddMessage(msg); msg.asgType(ERMsg::OK); Sleep(1000);//wait 1 sec } } //clean connection pConnection->Close(); pSession->Close(); } } callback.AddMessage(GetString(IDS_NB_FILES_DOWNLOADED) + ToString(curI)); callback.PopTask(); return msg; }
void COwnerDrawnListControl::DrawItem(LPDRAWITEMSTRUCT pdis) { COwnerDrawnListItem *item = (COwnerDrawnListItem *)(pdis->itemData); CDC *pdc = CDC::FromHandle(pdis->hDC); CRect rcItem(pdis->rcItem); if(m_showGrid) { rcItem.bottom--; rcItem.right--; } CDC dcmem; dcmem.CreateCompatibleDC(pdc); CBitmap bm; bm.CreateCompatibleBitmap(pdc, rcItem.Width(), rcItem.Height()); CSelectObject sobm(&dcmem, &bm); dcmem.FillSolidRect(rcItem - rcItem.TopLeft(), GetItemBackgroundColor(pdis->itemID)); bool drawFocus = (pdis->itemState & ODS_FOCUS) != 0 && HasFocus() && IsFullRowSelection(); CArray<int, int> order; order.SetSize(GetHeaderCtrl()->GetItemCount()); GetHeaderCtrl()->GetOrderArray(order.GetData(), int(order.GetSize())); CRect rcFocus = rcItem; rcFocus.DeflateRect(0, LABEL_Y_MARGIN - 1); for(int i = 0; i < order.GetSize(); i++) { int subitem = order[i]; CRect rc = GetWholeSubitemRect(pdis->itemID, subitem); CRect rcDraw = rc - rcItem.TopLeft(); int focusLeft = rcDraw.left; if(!item->DrawSubitem(subitem, &dcmem, rcDraw, pdis->itemState, NULL, &focusLeft)) { item->DrawSelection(this, &dcmem, rcDraw, pdis->itemState); CRect rcText = rcDraw; rcText.DeflateRect(TEXT_X_MARGIN, 0); CSetBkMode bk(&dcmem, TRANSPARENT); CSelectObject sofont(&dcmem, GetFont()); CString s = item->GetText(subitem); UINT align = IsColumnRightAligned(subitem) ? DT_RIGHT : DT_LEFT; // Get the correct color in case of compressed or encrypted items COLORREF textColor = item->GetItemTextColor(); // Except if the item is selected - in this case just use standard colors if((pdis->itemState & ODS_SELECTED) && (HasFocus() || IsShowSelectionAlways()) && (IsFullRowSelection())) { textColor = GetItemSelectionTextColor(pdis->itemID); } // Set the text color CSetTextColor tc(&dcmem, textColor); // Draw the (sub)item text dcmem.DrawText(s, rcText, DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX | align); // Test: dcmem.FillSolidRect(rcDraw, 0); } if(focusLeft > rcDraw.left) { if(drawFocus && i > 0) { pdc->DrawFocusRect(rcFocus); } rcFocus.left = focusLeft; } rcFocus.right = rcDraw.right; pdc->BitBlt(rcItem.left + rcDraw.left, rcItem.top + rcDraw.top, rcDraw.Width(), rcDraw.Height(), &dcmem, rcDraw.left, rcDraw.top, SRCCOPY); } if(drawFocus) { pdc->DrawFocusRect(rcFocus); } }
// CClipboardListBox void CClipboardListBox::DoCopy() { CArray<int,int> sels; int n = CListBox::GetSelCount(); if(n <= 0) { return; // nothing to copy } sels.SetSize(n); CListBox::GetSelItems(n, sels.GetData()); CString s; //***************************************************************************** // This segment of code only works if the listbox is non-owner-draw, * // or is owner-draw with LBS_HASSTRINGS * // So first check to make sure this is true * //***************************************************************************** ASSERT( (GetStyle() & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) == 0 || //* (GetStyle() & LBS_HASSTRINGS) == LBS_HASSTRINGS); //* //* // Extract the text //* for(int i = 0; i < n; i++) //* { /* copy items */ //* CString t; //* CListBox::GetText(sels[i], t); //* t += _T("\r\n"); //* s += t; //* } /* copy items */ //* //***************************************************************************** HGLOBAL g = ::GlobalAlloc(GMEM_MOVEABLE, (s.GetLength() + 1) * sizeof(TCHAR)); if(g == NULL) { /* alloc failed */ ASSERT(FALSE); // failed to allocate memory return; } /* alloc failed */ LPTSTR p = (LPTSTR)::GlobalLock(g); if(p == NULL) { /* lock failed */ ASSERT(FALSE); return; } /* lock failed */ strcpy_s(p, s.GetLength() + 1, (LPCTSTR)s); //::StringCchCopy(p, s.GetLength() + 1, (LPCTSTR)s); ::GlobalUnlock(g); if(!OpenClipboard()) { /* clipboard open failed */ ASSERT(FALSE); GlobalFree(g); return; } /* clipboard open failed */ if(!EmptyClipboard()) { /* empty failed */ ASSERT(FALSE); GlobalFree(g); return; } /* empty failed */ if(::SetClipboardData(CF_TEXT, g) == NULL) { /* SetClipboardData failed */ ASSERT(FALSE); // ::CloseClipboard(); ::GlobalFree(g); return; } /* SetClipboardData failed */ ::CloseClipboard(); }