CString转UINT

今天调试程序的时候,要用无符号整形的位操作来记录座椅的信息,再通过转换为CString发送,结果发现了一点问题。

1.UINT转CString

比如我要发送的信息是1111 1111 1111 1111 1111 1111 1111 1111,在使用CString temp;temp.Format("%d",infor);它打印出来是“-1”,而不是我想要的“4294967295”

到网上一查发现要用;temp.Format("%u",infor);完美解决。

2.

CString转UINT

用atoi(“4294967295”)转出来的值是,3489660927,这是0XCFFFFFFF的值啊。int 的最大值就是3489660927了,

所以又到网上找到方法了。

UINT CString_to_UINT(const CString & value)
{
UINT data=0;
if(value.Find(_T("0x"))==0)
_stscanf_s((LPCTSTR)value,_T("%x"),&data);
else
_stscanf_s((LPCTSTR)value,_T("%d"),&data);
return data;
}

完美解决。





  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
梯形图换语句表,软件测试阶段 IMPLEMENT_DYNCREATE(VDisPlayView, CScrollView) VDisPlayView::VDisPlayView() { //P_LIST cDatList; EnableAutomation(); } VDisPlayView::~VDisPlayView() { } HFONT C_SetFont(UINT uFont) { HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); if (hFont == NULL) hFont = (HFONT)GetStockObject(ANSI_VAR_FONT); return hFont ; } void VDisPlayView::OnFinalRelease() { // When the last reference for an automation object is released // OnFinalRelease is called. The base class will automatically // deletes the object. Add additional cleanup required for your // object before calling the base class. CScrollView::OnFinalRelease(); } BEGIN_MESSAGE_MAP(VDisPlayView, CScrollView) ON_WM_CREATE() // ON_WM_MOUSEMOVE() ON_MESSAGE(WM_DRAWDATA, OnDrawData) // ON_WM_MOUSEHWHEEL() ON_WM_SIZE() // ON_WM_MOUSELEAVE() ON_WM_NCMOUSELEAVE() END_MESSAGE_MAP() BEGIN_DISPATCH_MAP(VDisPlayView, CScrollView) END_DISPATCH_MAP() // Note: we add support for IID_IViScroll to support typesafe binding // from VBA. This IID must match the GUID that is attached to the // dispinterface in the .IDL file. // {C1771C4B-2FF0-46ED-A4FE-D381086A49E4} static const IID IID_IViScroll = { 0xC1771C4B, 0x2FF0, 0x46ED, { 0xA4, 0xFE, 0xD3, 0x81, 0x8, 0x6A, 0x49, 0xE4 } }; BEGIN_INTERFACE_MAP(VDisPlayView, CScrollView) INTERFACE_PART(VDisPlayView, IID_IViScroll, Dispatch) END_INTERFACE_MAP() // VDisPlayView drawing void VDisPlayView::OnInitialUpdate() { //CScrollView::OnInitialUpdate(); //CSize sizeTotal; // TODO: calculate the total size of this view //sizeTotal.cx = sizeTotal.cy = 1000; // SetScrollSizes(MM_TEXT, sizeTotal); SetScrollSizes(MM_TEXT, CSize(VIEW_WIDTH,VIEW_HIGHT)); CScrollView::OnInitialUpdate(); } //void VDisPlayView::OnDraw(CDC* pDC) //{ // CDocument* pDoc = GetDocument(); // //CAutoPanDoc* pDoc = GetDocument(); // ASSERT_VALID(pDoc); // // // Get the invalidated rectangle of the view, or in the case // // of printing, the clipping region of the printer dc. // CRect rectClip; // CRect rectCloud; // pDC->GetClipBox(&rectClip;); // pDC->LPtoDP(&rectClip;); // rectClip.InflateRect(1, 1); // avoid rounding to nothing // // // Note: CScrollView::OnPaint() will have already adjusted the // // viewport origin before calling OnDraw(), to reflect the // // currently scrolled position. ///* for(int x=0; x<1600; x+=50) // { // for(int y=0; yFillSolidRect(rc, RGB(x,y,x*y)); // } // }*/ // // // // // TODO: add draw code here //} // VDisPlayView diagnostics #ifdef _DEBUG void VDisPlayView::AssertValid() const { CScrollView::AssertValid(); } #ifndef _WIN32_WCE void VDisPlayView::Dump(CDumpContext& dc) const { CScrollView::Dump(dc); } #endif #endif //_DEBUG // VDisPlayView message handlers int VDisPlayView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CScrollView::OnCreate(lpCreateStruct) == -1) return -1; m_pDC=new CClientDC(this); uRowNumber=10000;// uColNumber=4; /* UINT uRowNumber ,uColNumber, *uPerCol_Width,*uPerRow_height ,;*/ uPerCol_Width =new WORD[uColNumber]; uPerRow_height=new WORD[uRowNumber]; UINT i; for(i=0;i<uColNumber;i++) { *(uPerCol_Width+i)=123; } *(uPerCol_Width+2)=323; for(i=0;ipvRemark=&cDatList; //LVS_EDITABELS 允许项文本能够适本地进行编辑。父窗口必须运行了LVN_ENDLABLEDIT //ListView_SetExtendedListViewStyle //cDatList.SetExtendedStyle(LVS_EX_GRIDLINES| LVS_EDITLABELS); /* LV_COLUMN lvcol; lvcol.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; lvcol.pszText = L"索引"; lvcol.iSubItem = 0; lvcol.cx = 130; cDatList.InsertColumn(0, &lvcol;); lvcol.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; lvcol.pszText = L"元件"; lvcol.iSubItem = 1; lvcol.cx = 130; cDatList.InsertColumn(1,&lvcol;); lvcol.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; lvcol.pszText = L"注释"; lvcol.iSubItem = 2; lvcol.cx = 130; cDatList.InsertColumn(2,&lvcol;); lvcol.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; lvcol.pszText = L"辅助标号"; lvcol.iSubItem = 3; lvcol.cx = 130; cDatList.InsertColumn(3,&lvcol;); */ // cDatList.InsertColumn(0, L"序号", LVCFMT_LEFT, 40); // cDatList.InsertColumn(1,L"地物名称", LVCFMT_LEFT, 80); // cDatList.InsertColumn(2,L"地物颜色", LVCFMT_LEFT, 120); // CString strName, strIndex; // int m; // for(int i=0; i<32; i++) // { // strIndex.Format(L"%d", i+1); // strName.Format(L"Class%d", i+1); // cDatList.InsertItem( i, strIndex); // cDatList.SetItemText(i, 1, strName); //cDatList.SetItemText(i, 1, strName); //cDatList.SetItemData(i, RGB(rand(), rand(), rand())); // } //cDatList.ApproximateViewRect(CSize(670,700),-1); //cDatList.SetRowHeigt(26); //cDatList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP); //cDatList.Create(_T("CONTROL"),(LPCWSTR) NULL,WS_CHILD|WS_VISIBLE,rect,this,ID_FUNCTION_INSERT); /* if (!cDatList.CreateEx(0L,_T("CSCROLLVIEW"),(LPCWSTR) NULL, WS_CHILD|WS_VISIBLE| ES_AUTOHSCROLL|

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

q472599451

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值