|
Then remove the unwanted pp and go on...
You know C++ code maybe converted into C one.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I want to develop a tool .The function is when I drag a image from browser on it which can save image to my desktop or manger(rename ) the image.
with google and other's help,I gain the HGLOBAL data from clipboard with pDataObject->GetGlobalData (CF_DIB) and I also can get the URL of image.but when I want to save this image to my desktop and I find two way can do this:
1.Save the data of CF_DIB format
The problem is:
I gain a string of binary system from CF_DIB data, how can i save it as image without changed it? I try to save all of those image to my desktop as format of bmp,it's can do the work but seem not good for the image on the desktop often larger then the browser.so I think it's not a good mothod to do this.for I have to save file without change I should save the format of image sam as browsers' ,but with many format like gif,jpg and so on....so I want to find a easy way how can I save image without changed it.
2. Download the image
The problem is:
Many URL is not right which can not find the image correctly,may be need parse it.
So The last questions is which way should I select can better solve my problem ?
Thanks in advance for your help and sorry for my English.
notenking
|
|
|
|
|
For your first solution i would check out CxImage[^].
For your second i would try using WinInet[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Thanks Code-o-mat.
I try to use CxImage before ask this question and find it's not a best solution when drag a picture from browser ,since the size of image may be changed ,So I want to know it's really need I do like this? any other easy way can I do?
Best Regards
notenking
modified on Tuesday, August 4, 2009 12:11 AM
|
|
|
|
|
How do you mean "the size of image may be changed"? You could try using GDI+[^] too, and how about the second options, downloading the original image?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
"the size of image may be changed" :
For example,when i save a image which is bmp format,and I use a method like this
HGLOBAL hg = pDataObject->GetGlobalData (CF_DIB);
CFile file;
file.Open(_T(deskpath+"//"+"temp.bmp"),CFile::modeCreate|CFile::modeWrite);
SaveToFile(hg,file);
file.Close();
when I get the image and find it larger than the original image,I thinks the reason may be for the way I save.and also I should save different format with differ method. so i thinks when I save a image with my method and I with changed it.but I don't want to change it,However ,I do not know what's should I do? use other libary like CxImage can solve this?
"download the original image": I can gain the url of the image ,so I think if I can not get the original image with the first solution and I can download it. but....It's also seem not easy for some of URL is not correct,may be need prase to get the true URL.
So I feel confused which is the easy way to get the correct image?
notenking
|
|
|
|
|
Well, one way you could go is to use CreateDIBSection[^] using the BITMAPINFO[^] structure and the pixel data you get with CF_DIB[^]. Once you have a HBITMAP handle you can use CxImage's CreateFromHBITMAP and then CxImage's Save methods to save your image in any format you like. There are probably more efficient ways but this is the first one i could think of.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Yes,Code-o-mat Thank you,It's a way to solve it.I'll try later.
and I also want to know did the size of image will be changed do like this ?
|
|
|
|
|
I doubt it but to tell you the truth i still don't quite understand how you mean that the image size changes... do you mean that for example you drag a 800x600 image on your application and it saves a smaller, let's say 400x300 pixels image? Are you sure that in the drag operation you get the original image as a DIB and not some scaled-down preview? Also, if you have a site with small images as links to their big versions, then dragging the image will surely contain the original, small image's URL, not the bigger version's.
[EDIT] You mean the filesize, don't you? The file you save is smaller than the file in your browser's cache, right? Well, did you try opening the BMPs you saved? Does for example Paint open them OK? If you simply take the CF_DIB data and just write it to a file that shouldn't actually produce a valid Bitmap since Bitmaps have to begin with a BITMAPFILEHEADER[^] structure and CF_DIB does not contain that. Could this be what you mean?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
modified on Tuesday, August 4, 2009 5:22 AM
|
|
|
|
|
Yes,Code-o-mat,Sorry for my English,It's filesize changed ,but it become larger than the orignial.
actually ,I want to know how can I get the image without CF_DIB data ,if I have to take CF_DIB data without any select,can the image be saved as cache?
Thanks Code-o-mat for your patient.
notenking
|
|
|
|
|
If you drag a JPG or PNG image (since BMP formats are rarely used on websites i supose you are experimenting with those) and then save it as a BMP (from the CF_DIB) then it is no wonder the file size is bigger since JPG and PNG are compressed while the BMP (from the DIB) is not. When you save the DIB data to file you are actually not getting the very same file your browser downloaded (maybe unless it originally was a BMP) but you convert the image from JPG or PNG to uncompressed Windows Bitmap format, thus the filesize will be bigger. If you are using the CxImage aproach you are still not saving the very original file but what you are doing -in case of a JPG for example- is to let the browser decompress the JPG and store the pixel data into a DIB and then re-compressing that DIB back into a JPG again and saving that to file and nothing garantees that you will receive a "perfect copy" of the original JPG image.
shi baoshi wrote: I want to know how can I get the image without CF_DIB data ,if I have to take CF_DIB data without any select,can the image be saved as cache?
I'm not sure i understand what you mean here but i guess what you want is to get the image from the browser's cache and copy it to wherever. I currently have no idea how you could figure out where the browser cached the image, but imho relying on that is not necesarily a good idea. I'm not sure how IE or any other browser handles caching but what if for example caching is turned off by the user completely? Could be that the browser does not save the image to any local file but only stores it in memory. I'd say if you want the very original file as it is, your best bet is still downloading it yourself again, i think using WinInet could be much of a help to you with that. You said that you tried the download aproach already but there were problems with the URLs. What problems? Could these maybe handled by Wininet's InternetOpenURL[^] function?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Code-o-mat wrote: You said that you tried the download aproach already but there were problems with the URLs. What problems? Could these maybe handled by Wininet's InternetOpenURL[^] function?
Yes,some url not the true url for some website's setting,if I want to get the true URL of those image ,may be need parse the URL again. but this seem not the problem at present.With your patient explain,I think I should download the image in order to get the original image.
Thanks Code-o-mat again.
notenking
|
|
|
|
|
Good morning,
last week I already wrote about my little problem. Then I got sick and and couldn´t take part in the conversation. Even though I got an answer it didn´t help (or I misunderstood). Now I wanted to ask/clarify and would be glad for some help.
The code:
SOCKET m_oUDPSocket;
SOCKADDR_IN m_oUDPAddress;
.
.
.
m_oUDPSocket = socket(AF_INET,SOCK_DGRAM,0);
memset(&m_oUDPAddress,0,sizeof(SOCKADDR_IN));
m_oUDPAddress.sin_family=AF_INET;
m_oUDPAddress.sin_port=htons(m_iClientPort);
m_oUDPAddress.sin_addr.s_addr=inet_addr(m_sClientIP.data());
.
.
.
int rc=sendto(m_oUDPSocket,(char*)packet,size+12,0,(SOCKADDR*)&m_oUDPAddress,sizeof(SOCKADDR_IN));
The problem: I´d like to send the data via 'sendto' ALWAYS on the same outgoing port.
The question: Where and how do I define this outgoing port? Do I have to create another SOCKADDR_IN with the server port and address and bind it to m_oUDPSocket?
Like this?
SOCKADDR_IN addr;
memset(&addr,0,sizeof(SOCKADDR_IN));
addr.sin_family=AF_INET;
addr.sin_port=htons(desiredPort);
addr.sin_addr.s_addr=INADDR_ANY;
rc=bind(m_oUDPSocket,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN));
Or am I on the wrong path here? And how can I test if it indeed sends from the desired port?
Thanks for any help.
Souldrift
|
|
|
|
|
What do u mean by outgoing port?
Normally the ipaddr and the port number on which u need to send the data will be fixed.
client must have the PortNo and Ipaddr to send the data in UDP to server.
|
|
|
|
|
Well, by outgoing port I mean simply the UDP port. The question was, how do I get a fixed one?
By now I figured that it is the 'bind' command that will do that. Though, what UDP port does the server use if I do NOT specify a bind?
Regards
Souldrift
|
|
|
|
|
IIRC random between 1024 and 65535, or maybe between 50k and 65535
|
|
|
|
|
Yes, thanks. It was just that I hadn´t thought of binding the socket to a certain port (like I mused in the second code block of my initial post). Now it´s working.
Cheers
Souldrift
|
|
|
|
|
I need to store my data into database from C++ using Pure C++ with out using MFC Classes can any body help me out or any links so that i can browse for API's.
|
|
|
|
|
POCO[^] has data access libraries. Have a look at Poco::Data namespace.
|
|
|
|
|
There are many ways to do this. You may use, for instance, ODBC API [^], or you may go through ADO [^] (You've also the option to embed SQLite [^] in your application).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
you can ask on Professional Win32 api newsgroup :
news://nntp.aioe.org/comp.os.ms-windows.programmer.win32
or http://tinyurl.com/cmhb5g by Google
for all methods (MS and others, pure Win32 code...)
|
|
|
|
|
Not sure what you mean by "pure" C++, but in any case you'll need some external library to access a database; database access is not covered by standard C++.
|
|
|
|
|
In our project, we have a MFC screen. In this screen, we have 2 buttons along with other controls. One button is OK and otherone is Cancel button.
In this screen when focus goes to the "Cancel" button, it get stuck on it.
After focusing on Cancel button, Tab does not work and focus does not move to any of controls on the screen.
It is something like when focus goes to "Cancel" button, Tab is not working.
Please help to resolve this issue.
modified on Monday, August 3, 2009 8:31 AM
|
|
|
|
|
By default, this should not happen. What code do you have in place that would be handling the tab key or the WM_SETFOCUS message? Have you created a new "test" application to see how it behaves, and then start adding your app-specific code until the problem appears?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I want to fetch excel data and store in database .how it is possible
Trioum
|
|
|
|