masterz的代码怎么我不会用呢?

北京的雾霾天 2009-12-14 12:20:59
我在网上找到了masterz大侠的代码,但我没有执行成功,请各位大侠给分析一下,就是注释那里不正确:


void SaveIcon()
{
LPBYTE lpBits=NULL;
long size=0;
HICON hicon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
PICTDESC pdiconsrc;
pdiconsrc.cbSizeofstruct=sizeof(PICTDESC);
pdiconsrc.icon.hicon=hicon;
pdiconsrc.picType=PICTYPE_ICON;
IPicture* pIPicture=NULL;
HRESULT hr;
IDispatch* pDisp=NULL;
hr = OleCreatePictureIndirect(&pdiconsrc,
IID_IDispatch,
TRUE,
(void**)&pDisp);
if(SUCCEEDED(hr))
{
hr = pDisp->QueryInterface(&pIPicture);
if(SUCCEEDED(hr))
{
lpBits = (LPBYTE) GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD, 64*1024);
IStream* pStream;
CreateStreamOnHGlobal(lpBits,false,&pStream);
//下面的第二个参数为false时hr为E_FAIL,是True时倒是S_OK,但是size一直是766,结果也不对。
hr=pIPicture->SaveAsFile(pStream,true,&size);
if(pStream)
pStream->Release();
if(SUCCEEDED(hr)&&size>0)
{
//you can use
char* pchar=(char*)lpBits;
//icon is stored in pchar, length is size
//to create another hicon
//use OleLoadPicture(pStream,...)
//IPicture::get_Handle to get the icon handle
}
pIPicture->Release();
if(lpBits)
GlobalFree((HGLOBAL)lpBits);
}
pDisp->Release();
}
}
...全文
131 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
MoXiaoRab 2009-12-16
  • 打赏
  • 举报
回复
我不擅长图形方面,很抱歉
这不是鸭头 2009-12-16
  • 打赏
  • 举报
回复

菜鸟路过学习..
北京的雾霾天 2009-12-16
  • 打赏
  • 举报
回复
在你眼里,啥样的才算真高手?你认为真高手会无聊到在CSDN里答帖子么。
------------------
我认为知道来龙去脉的就是高手,一问三不知的当然就不是了。
起码,在没事的时候也过来给答答问题啊。只看问题不解答,只回答会的不理会难的算什么高手,我哪里知道这样的高手是高手呢,怎么也要发表一下对问题的看法啊,没法解决就说没法解决,指个明路的也行。什么也不说,还以为没人在呢。当然不要求高手一定回答,但是也不要中途而止啊。说一句话就没有影了,或一句话也不说,难道我还说这是高手?
lwd4210 2009-12-16
  • 打赏
  • 举报
回复
哎,看来我们长期被鄙视,混口饭吃难啊
快乐鹦鹉 2009-12-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 hbxtlhx 的回复:]
结论:
1:使用pIPicture->SaveAsFile方法只能得到32*32的16色的图标。这个图标文件大小正好是766。
2:CSDN的真高手越来越少了。。。
[/Quote]
在你眼里,啥样的才算真高手?你认为真高手会无聊到在CSDN里答帖子么。
北京的雾霾天 2009-12-16
  • 打赏
  • 举报
回复
结论:
1:使用pIPicture->SaveAsFile方法只能得到32*32的16色的图标。这个图标文件大小正好是766。
2:CSDN的真高手越来越少了。。。
北京的雾霾天 2009-12-14
  • 打赏
  • 举报
回复
是这个:
www.fruitfruit.com/vc/graphics/icon.cpp

出现在这个帖子里了:
http://topic.csdn.net/t/20050822/16/4223697.html
快乐鹦鹉 2009-12-14
  • 打赏
  • 举报
回复
源码在哪里
北京的雾霾天 2009-12-14
  • 打赏
  • 举报
回复
可以得到高色彩的Icon吗?
MoXiaoRab 2009-12-14
  • 打赏
  • 举报
回复
色彩失真是正常的
北京的雾霾天 2009-12-14
  • 打赏
  • 举报
回复
好像是我搞错了,可以取出数据并保存了,但是好像现在只是16色的。。。并且,还只是766K,仍不解中。。。

SHFILEINFO sfi;
SHGetFileInfo(docfileName,0,&sfi,sizeof(sfi),SHGFI_ICON|SHGFI_LARGEICON|SHGFI_USEFILEATTRIBUTES);

PICTDESC pdiconsrc;
pdiconsrc.cbSizeofstruct=sizeof(PICTDESC);
pdiconsrc.icon.hicon=sfi.hIcon;
pdiconsrc.picType=PICTYPE_ICON;

IPicture* pIPicture=NULL;
HRESULT hr;
LPBYTE lpBits=NULL;
long size=0;
hr = OleCreatePictureIndirect(&pdiconsrc, IID_IPicture, TRUE, (VOID**)&pIPicture);
if(SUCCEEDED(hr))
{
IStream* pStream;
lpBits = new BYTE[100*1024];
hr = CreateStreamOnHGlobal(lpBits,true,&pStream);
if(SUCCEEDED(hr))
{
hr=pIPicture->SaveAsFile(pStream,TRUE,&size);

if(pStream)
{
writeToFile(lpBits, size, L"D:\\a.ico");
pStream->Release();
}
pIPicture->Release();
if(lpBits)
{
delete[] lpBits;
}
}
}
北京的雾霾天 2009-12-14
  • 打赏
  • 举报
回复
SaveAsFile为什么会出错啊,怎么能查到出错的原因?
北京的雾霾天 2009-12-14
  • 打赏
  • 举报
回复
因为获取不到正确的数据,所以pStream虽然能保存成文件,但是文件的内容都是一样的,而且是错的。
郁闷中。。。
MoXiaoRab 2009-12-14
  • 打赏
  • 举报
回复
换另外一种方式看看

char pathbuf[1024];
strcpy(pathbuf,sIconFileName);
CFile iconfile;
iconfile.Open(pathbuf, CFile::modeCreate|CFile::modeWrite);
LARGE_INTEGER li;
li.HighPart =0;
li.LowPart =0;
ULARGE_INTEGER ulnewpos;
pStream->Seek( li,STREAM_SEEK_SET,&ulnewpos);
ULONG uReadCount = 1;
while(uReadCount>0)
{

pStream->Read(pathbuf,sizeof(pathbuf),&uReadCount);
if(uReadCount>0)
iconfile.Write(pathbuf,uReadCount);
}
pStream->Release();
iconfile.Close();

这种行不行呢
主  题: 在VC中使用XMLHTTP,怎样初始化,怎样建立连接?在线等。 我的一段代码在.NET中用C#已经调通,我想搬到VC++ 6.0上,但不知道任何各种写法规则。 C# 中为: MSXML2.XMLHTTP xmlHttp_ = new XMLHTTP(); xmlHttp_.open("PROPFIND", serverUrl, false, username, password); xmlHttp_.send(null); 放到VC++ 6.0 中应为什么? 以下是我写的,但运行出错。 #import "msxml4.dll" using namespace MSXML2; HRESULT hr; //MSXML2::IXMLHTTPRequest pIXMLHttpRequest; CString serverUrl ="http://services.msn.com/svcs/hotmail/httpmail.asp"; MSXML2::IXMLHTTPRequestPtr pIXMLHttpRequest; pIXMLHttpRequest.CreateInstance("Msxml2.XMLHTTP.4.0"); if (pIXMLHttpRequest==NULL) AfxMessageBox("pIXMLHttpRequest error"); try { // Create XMLHttpRequest object and initialize pIXMLHttpRequest. hr = pIXMLHttpRequest->open(_bstr_t(_T("PROPFIND")), _bstr_t(_T(serverUrl)), _variant_t(VARIANT_FALSE), _variant_t("test5_12"), _variant_t("1234567")); if(SUCCEEDED(hr)) ::MessageBox(NULL, _T("Success !"), _T(""), MB_OK); } catch(...) { //DisplayErrorToUser(); AfxMessageBox("error"); } 在调用方法open的时候出错! 回复人: masterz(www.fruitfruit.com) ( ) 信誉:273 2003-06-10 21:34:02Z 得分:20 ? #import "msxml.dll" #import "msxml2.dll" using namespace MSXML2; int main(int argc, char* argv[]) { printf("Test of XMLHTTP by masterz!\n"); CoInitialize(NULL); try { IXMLHTTPRequestPtr xmlrequest; xmlrequest.CreateInstance("Msxml2.XMLHTTP"); _variant_t varp(false); xmlrequest->open(_bstr_t("GET"),_bstr_t("http://www.csdn.net/expert/topic/855/855052.xml?temp=.176037"),varp); xmlrequest->send(); BSTR bstrbody; xmlrequest->get_responseText(&bstrbody); _bstr_t bstrtbody(bstrbody); printf("%s\n",(LPCTSTR)bstrtbody); } catch (_com_error &e) { printf("Description = '%s'\n", (char*) e.Description()); } CoUninitialize(); printf("program end\n"); return 0; } ///////Post with XMLHTTP/////////////////////// #import "msxml.dll" #import "msxml2.dll" #include "Atlbase.h" using namespace MSXML2; int main(int argc, char* argv[]) { printf("Test of XMLHTTP by masterz!\n"); CoInitialize(NULL); try { IXMLHTTPRequestPtr xmlrequest; //xmlrequest.CreateInstance("Msxml2.XMLHTTP"); xmlrequest.CreateInstance(__uuidof(XMLHTTP)); CComVariant vFalse(FALSE); CComVariant vNull(NULL); xmlrequest->open("POST", _bstr_t("http://211.157.102.21/member/logon.asp"),vFalse,vNull,vNull); xmlrequest->setRequestHeader("Content-Type:","application/x-www-form-urlencoded"); _bstr_t bsdata("name=xxx&pass=xxx&type=1");//use your login name and password xmlrequest->send(_variant_t(bsdata)); BSTR bstrbody; xmlrequest->get_responseText(&bstrbody); _bstr_t bstrtbody(bstrbody); printf("%s\n",(LPCTSTR)bstrtbody); //MessageBox(0,bstrtbody,"",MB_OK); } catch (_com_error &e) { printf("Description = '%s'\n", (char*) e.Description()); } CoUninitialize(); printf("program end\n"); return 0; }

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧