|
Never heard of a GASP table, and google wasn't much help, either.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i'd recommend "Christian GURUs".
He is like a one-legged man in a bum kicking competition. -Novjot Sidhu
--[v]--
|
|
|
|
|
|
Hi,
How can I resize a pic (make it smaller) and store it on my hard disc?
I found this code on the web. Now I can load and store every pic, but cannot store it with other size. Who can help me with some codes? Thank you very very much!
BOOL CPicture::Load(CString sFilePathName)
{
BOOL bResult = FALSE;
CFile PictureFile;
CFileException e;
int nSize = 0;
if(m_IPicture != NULL) FreePictureData();
if(PictureFile.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e))
{
nSize = PictureFile.GetLength();
BYTE* pBuffer = new BYTE[nSize];
if(PictureFile.Read(pBuffer, nSize) > 0)
{
if(LoadPictureData(pBuffer, nSize)) bResult = TRUE;
}
PictureFile.Close();
delete [] pBuffer;
}
else
{
TCHAR szCause[255];
e.GetErrorMessage(szCause, 255, NULL);
HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
MessageBoxEx(hWnd, szCause, ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
bResult = FALSE;
}
m_Weight = nSize;
if(m_IPicture != NULL)
{
m_IPicture->get_Height(&m_Height);
m_IPicture->get_Width(&m_Width);
m_Height = MulDiv(m_Height, 96, HIMETRIC_INCH);
m_Width = MulDiv(m_Height, 96, HIMETRIC_INCH);
}
else
{
m_Height = 0;
m_Width = 0;
bResult = FALSE;
}
return(bResult);
}
BOOL CPicture::SaveAsBitmap(CString sFilePathName)
{
BOOL bResult = FALSE;
ILockBytes *Buffer = 0;
IStorage *pStorage = 0;
IStream *FileStream = 0;
BYTE *BufferBytes;
STATSTG BytesStatistics;
DWORD OutData;
long OutStream;
CFile BitmapFile; CFileException e;
double SkipFloat = 0;
DWORD ByteSkip = 0;
_ULARGE_INTEGER RealData;
CreateILockBytesOnHGlobal(NULL, TRUE, &Buffer);
HRESULT hr = ::StgCreateDocfileOnILockBytes(Buffer,
STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage);
hr = pStorage->CreateStream(L"PICTURE",
STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, 0, &FileStream);
m_IPicture->SaveAsFile(FileStream, TRUE, &OutStream);
FileStream->Release();
pStorage->Release();
Buffer->Flush();
Buffer->Stat(&BytesStatistics, STATFLAG_NONAME);
SkipFloat = (double(OutStream) / 512);
if(SkipFloat > DWORD(SkipFloat)) ByteSkip = (DWORD)SkipFloat + 1;
else ByteSkip = (DWORD)SkipFloat;
ByteSkip = ByteSkip * 512;
ByteSkip = (DWORD)(BytesStatistics.cbSize.QuadPart - ByteSkip);
RealData.LowPart = 0;
RealData.HighPart = 0;
RealData.QuadPart = ByteSkip;
BufferBytes = (BYTE*)malloc(OutStream);
if(BufferBytes == NULL)
{
Buffer->Release();
HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
MessageBoxEx(hWnd, "Can not allocate enough memory\t", ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
}
Buffer->ReadAt(RealData, BufferBytes, OutStream, &OutData);
if(BitmapFile.Open(sFilePathName, CFile::typeBinary | CFile::modeCreate | CFile::modeWrite, &e))
{
BitmapFile.Write(BufferBytes, OutData);
BitmapFile.Close();
bResult = TRUE;
}
else
{
TCHAR szCause[255];
e.GetErrorMessage(szCause, 255, NULL);
HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
MessageBoxEx(hWnd, szCause, ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
bResult = FALSE;
}
Buffer->Release();
free(BufferBytes);
return(bResult);
}
|
|
|
|
|
Why on earth did you post all this code ?
To resize an image, create a new image of the size you want and use StretchBlt to draw the resized image onto it.
Or, if you use GDI+, you can use DrawImage in the same way.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you Christian,
After using "StretchBlt" I can use the method mentioned upon to save the image, then I'll have a small pic (with small file size) on my hard disc drive?
|
|
|
|
|
Doesn't look like it. Your best bet overall is probably to read my GDI+ articles, GDI+ makes it trivial to load and save images in a variety of formats. What VC are you using ? If VC6, you need to install a PSDK to get GDI+, if a .NET version, you should have it already.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you very much!
I will try your articles.
|
|
|
|
|
Christian Graus wrote: Why on earth did you post all this code ?
No offence meant, but surely you have noticed the normal response when someone asks for help, but does not post the code that is giving problems / does not do what they want / etc?
I think posting the code shows how he is doing things so far, so we can tell him the most appropriate way to do what he wants to do.
|
|
|
|
|
No, he posted a class that he copied from the web. If it was his code, I would not have said anything. And it's not a complete class, you can't tell how images are stored in it, although I suspect a COM object.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Don't you ever sleep? How can you always respond in minutes, no matter what time anyone posts?
I see your point. But if he hadn't posted the code, someone would have replied "if you don't post your code, how can you expect anyone to help?" And then he would have posted it, etc.
|
|
|
|
|
Hi, I have to create a thread that read a hardware port less than 60ms. so I create a thread with TIME_CRITICAL_PRIORITY, but it would help. Is there any advice?
Thank you
|
|
|
|
|
I think you also need to use SetPriorityClass(...).
BOOL SetPriorityClass(<br />
HANDLE hProcess,<br />
DWORD dwPriorityClass<br />
);
Set dwPriorityClass = HIGH_PRIORITY_CLASS;
And set the thread priority around: THREAD_PRIORITY_HIGHEST or THREAD_PRIORITY_ABOVE_NORMAL .
If you set it to THREAD_PRIORITY_TIME_CRITICAL , then your program might miss hard disk writes!!!. It can also hang the system.
this is this.
|
|
|
|
|
Hello,
In window's, you can never know at what frequency your get a timeslice. You can say to windows that your thread is the most important one in the system by settings the priority class[^] and the thread priority[^]. You can safely set them to any value except the maximum. This might hang the system.
In that case, you should create an other small program that contains only your thread. You can lock this thread ot the desired time and suspend it when you get more time than you need. This way you won't dry up the CPU resources..
Hope this helps.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi, I need to detect the color of some pixels in another application running on my desktop. I am able to retrieve the DC of the window just fine when it is the top window, but can't when it is hidden behind another window! Is there a flag I can set or any other way for me to retrieve the color of a pixel on the application window if it is not directly visible to the monitor? i.e. if portion of the window is covered by another window, that new window's display is instead included in the DC I retrieve.
Currently I am using:
CDC *windc = window->GetDCEx( NULL, DCX_PARENTCLIP );
Where 'window' is a handle to the CWnd of the application window. Also I'm not sure that I require the DCX_PARENTCLIP flag -- I don't entirely understand the descriptions provided for the flags for GetDCEx.
Thanks in advance for your help!!
Jeremy.
|
|
|
|
|
Jeremy Pfund wrote: Is there a flag I can set or any other way for me to retrieve the color of a pixel on the application window if it is not directly visible to the monitor?
no, because screen DCs don't actually store pixels.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
You could try sending a WM_PRINT or WM_PRINTCLIENT message to the window. Not all widows handle those messages, but yours just might.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Hello,
I would like that users be able to launch my application from the Shell "Open with" menu.
Can somebody explain how to achieve that?
Thanks
|
|
|
|
|
See here.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Hello,
Thank you for replying. I followed your link.
But I've already call EnableShellOpen in the CWinApp::InitInstance. And my application is listed under "Open with" menu.
When I open a file with the "Open with" menu, the shell actually launch my app. However I don't know how to do further processing like retrieving the file being launched and open it.
Can you help me doing that?
|
|
|
|
|
Allad wrote: However I don't know how to do further processing like retrieving the file being launched and open it.
I'm assuming you have either an SDI or MDI application. Yes? If clicking on a particular file opened your application, then the file is already opened and its name can be obtained from the document's GetPathName() method.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
|
Hello,
Thank you for replying. I followed your link.
But I've already call EnableShellOpen in the CWinApp::InitInstance. And my application is listed under "Open with" menu.
When I open a file with the "Open with" menu, the shell actually launch my app. However I don't know how to do further processing like retrieving the file being launched and open it.
Can you help me doing that?
|
|
|
|
|
Hello,
Thank you for replying. I followed your link.
But I've already call EnableShellOpen in the CWinApp::InitInstance. And my application is listed under "Open with" menu.
When I open a file with the "Open with" menu, the shell actually launch my app. However I don't know how to do further processing like retrieving the file being launched and open it.
Can you help me doing that?
|
|
|
|
|
Hi all,
I need to know that when i create a function, say:
int add(int,int);
then I create a pointer to that function:
int(*fp)(int,int); //I think this is the syntax...
the big question is that:
since this pointer points to data in memory, can I copy these data (the actual function code in memory) and copy it to a new location in memory?
I want to have to copies of the function in memory, and use them both.
if I can, how can I deteremine the length(in bytes) of that function? what are the explicit steps do I need to do?????????
Thanx all,
Mohammad Gdeisat
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|