Thread View: borland.public.cppbuilder.nativeapi
16 messages
16 total messages
Started by Fernando Alvarez
Sun, 20 Apr 2003 15:52
change wallpaper gif/jpg
Author: Fernando Alvarez
Date: Sun, 20 Apr 2003 15:52
Date: Sun, 20 Apr 2003 15:52
11 lines
1208 bytes
1208 bytes
Hi! I try to change the wallpaper with this instruction: SystemParametersInfo(SPI_SETDESKWALLPAPER,0,"c:\\picture.JPG",SPIF_UPDATEINI FILE || SPIF_SENDWININICHANGE); It works with bmp pictures but it doesn�t work with gif/jpg pictures. How can I use gif/jpg pictures? Thank you.
Re: change wallpaper gif/jpg
Author: Nico Bendlin
Date: Sun, 20 Apr 2003 18:39
Date: Sun, 20 Apr 2003 18:39
8 lines
1237 bytes
1237 bytes
Fernando Alvarez wrote: > It works with bmp pictures but it doesn�t work with gif/jpg pictures. > How can I use gif/jpg pictures? IMHO, 'Active Desktop' must be enbaled. -- how to get rid of this damn sig
Re: change wallpaper gif/jpg
Author: Remy Lebeau (TeamB)
Date: Sun, 20 Apr 2003 21:51
Date: Sun, 20 Apr 2003 21:51
20 lines
1721 bytes
1721 bytes
"Fernando Alvarez" <ferjat@lycos.es> wrote in message news:3ea2c223$1@newsgroups.borland.com... > It works with bmp pictures but it doesn�t work > with gif/jpg pictures. How can I use gif/jpg pictures? You don't. Windows only supports bmps for wallpaper. What you ask for will require you to either: 1) simply convert the images to bmp first 2) use the IActiveDesktop interface instead (ActiveDesktop is a feature introduced in InternetExplorer4). Note that this requires IE4 to be installed (all systems running Win98 or higher already have that - Win95 and WinNT need a separate installation), and that ActiveDesktop needs to be enabled by the user before it can be utilized. Gambit
Re: change wallpaper gif/jpg
Author: Fernando Alvarez
Date: Sun, 20 Apr 2003 22:05
Date: Sun, 20 Apr 2003 22:05
30 lines
1869 bytes
1869 bytes
Thank you for the help. How can I convert gif/jpg to bmp? Thank you. "Remy Lebeau (TeamB)" <gambit47@yahoo.com> escribi� en el mensaje news:3ea3164d$1@newsgroups.borland.com... > > "Fernando Alvarez" <ferjat@lycos.es> wrote in message > news:3ea2c223$1@newsgroups.borland.com... > > > It works with bmp pictures but it doesn�t work > > with gif/jpg pictures. How can I use gif/jpg pictures? > > You don't. Windows only supports bmps for wallpaper. What you ask for will > require you to either: > > 1) simply convert the images to bmp first > > 2) use the IActiveDesktop interface instead (ActiveDesktop is a feature > introduced in InternetExplorer4). Note that this requires IE4 to be > installed (all systems running Win98 or higher already have that - Win95 and > WinNT need a separate installation), and that ActiveDesktop needs to be > enabled by the user before it can be utilized. > > > Gambit > > >
Re: change wallpaper gif/jpg
Author: Remy Lebeau (TeamB)
Date: Mon, 21 Apr 2003 05:03
Date: Mon, 21 Apr 2003 05:03
18 lines
1799 bytes
1799 bytes
"Fernando Alvarez" <ferjat@lycos.es> wrote in message news:3ea319ae$1@newsgroups.borland.com... > How can I convert gif/jpg to bmp? For JPG, Builder has a native TJPEGImage class for working with jpg images. You can load the jpg into an instance of TJPEGImage and then simply Assign() the TJPEGImage to a TBitmap. As for GIF, Builder has no native support for that format. You will have to use a third-party solution instead. There are numerous third-party GIF components available for download. For example, if you go to http://www.torry.net and do a search, TGIFImage by Anders Melander is a very good component for working with GIF images, and you'll be able to Assign() it to TBitmap as well for conversion purposes. Gambit
Re: change wallpaper gif/jpg
Author: Fernando Alvarez
Date: Tue, 22 Apr 2003 10:51
Date: Tue, 22 Apr 2003 10:51
28 lines
1957 bytes
1957 bytes
Thank you very much. "Remy Lebeau (TeamB)" <gambit47@yahoo.com> escribi� en el mensaje news:3ea37c3b$1@newsgroups.borland.com... > > "Fernando Alvarez" <ferjat@lycos.es> wrote in message > news:3ea319ae$1@newsgroups.borland.com... > > How can I convert gif/jpg to bmp? > > For JPG, Builder has a native TJPEGImage class for working with jpg images. > You can load the jpg into an instance of TJPEGImage and then simply Assign() > the TJPEGImage to a TBitmap. > > As for GIF, Builder has no native support for that format. You will have to > use a third-party solution instead. There are numerous third-party GIF > components available for download. For example, if you go to > http://www.torry.net and do a search, TGIFImage by Anders Melander is a very > good component for working with GIF images, and you'll be able to Assign() > it to TBitmap as well for conversion purposes. > > > Gambit > >
Re: change wallpaper gif/jpg
Author: Damon Chandler (TeamB)
Date: Wed, 23 Apr 2003 06:28
Date: Wed, 23 Apr 2003 06:28
172 lines
5495 bytes
5495 bytes
Hi Fernando,
> How can I convert gif/jpg to bmp?
The following function uses the IPicture interface to convert a GIF or JPEG
to a bitmap; it returns a TBitmap object which you can dump to a file via
TBitmap::SaveToFile()...
#include <ole2.h>
#include <olectl.h>
#include <memory>
Graphics::TBitmap* LoadImageFromFile(
AnsiString filename
)
{
// open the file for shared reading
HANDLE const hFile = CreateFile(
filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
);
if (hFile == INVALID_HANDLE_VALUE)
{
throw EWin32Error("Error opening file.");
}
// allocate a global memory object of the file's size
DWORD const dwSize = GetFileSize(hFile, NULL);
HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, dwSize);
if (hData == NULL)
{
CloseHandle(hFile);
throw EWin32Error("Error allocating memory.");
}
// grab a pointer to the memory
LPVOID pData = GlobalLock(hData);
if (pData == NULL)
{
GlobalFree(hData);
CloseHandle(hFile);
throw EWin32Error("Error accessing memory.");
}
// read the data from the file
DWORD dwRead = 0;
bool read_ok = ReadFile(hFile, pData, dwSize, &dwRead, NULL);
if (!read_ok || (dwRead != dwSize))
{
GlobalUnlock(hData);
GlobalFree(hData);
CloseHandle(hFile);
throw EWin32Error("Error reading file.");
}
// clean up
GlobalUnlock(hData);
CloseHandle(hFile);
// create an IStream object on hData
IStream* pStream;
HRESULT hRes = CreateStreamOnHGlobal(hData, false, &pStream);
if (FAILED(hRes))
{
GlobalFree(hData);
throw EWin32Error("Failed to create IStream.");
}
// load the picture (create an IPicture object)
IPicture* pPicture;
hRes = OleLoadPicture(
pStream, 0, false, IID_IPicture,
reinterpret_cast<void**>(&pPicture)
);
if (FAILED(hRes))
{
pStream->Release();
GlobalFree(hData);
throw EWin32Error("Failed to create IPicture.");
}
// grab a handle to the Picture's palette, if present
HPALETTE hPal = NULL;
pPicture->get_hPal(reinterpret_cast<OLE_HANDLE*>(hPal));
if (hPal != NULL)
{
int const num_entries =
GetPaletteEntries(hPal, 0, 0, NULL);
long const size = sizeof(LOGPALETTE) +
(num_entries - 1) * sizeof(PALETTEENTRY);
// copy the palette (because IPicture owns it)
LPLOGPALETTE pLogPal =
reinterpret_cast<LPLOGPALETTE>(GlobalAlloc(GPTR, size));
if (pLogPal != NULL)
{
int const num_got = GetPaletteEntries(
hPal, 0, num_entries, pLogPal->palPalEntry
);
pLogPal->palVersion = 0x300;
pLogPal->palNumEntries = num_got;
hPal = CreatePalette(pLogPal);
GlobalFree(pLogPal);
}
}
// retrieve the width and height of the picture
SIZE SHiMetric = {0, 0};
pPicture->get_Width(&SHiMetric.cx);
pPicture->get_Height(&SHiMetric.cy);
// convert HIMETRIC units to pixels
HDC hScreenDC = GetDC(NULL);
int const width = MulDiv(
SHiMetric.cx, GetDeviceCaps(hScreenDC, LOGPIXELSX), 2540
);
int const height = MulDiv(
SHiMetric.cy, GetDeviceCaps(hScreenDC, LOGPIXELSY), 2540
);
ReleaseDC(NULL, hScreenDC);
// create a TBitmap object
std::auto_ptr<Graphics::TBitmap> Bitmap(new Graphics::TBitmap());
try
{
// set the bitmap's attributes
Bitmap->PixelFormat = pf24bit;
Bitmap->Width = width;
Bitmap->Height = height;
// grab a handle to the bitmap's memory DC
HDC const hMemDC = Bitmap->Canvas->Handle;
// associate the palette (if present) with the bitmap's DC
HPALETTE hOldPal = NULL;
if (hPal != NULL)
{
Bitmap->Palette = hPal;
hOldPal = SelectPalette(hMemDC, hPal, false);
RealizePalette(hMemDC);
}
// render the picture to the memory DC
pPicture->Render(
hMemDC, 0, 0, width, height, 0, SHiMetric.cy,
SHiMetric.cx, -SHiMetric.cy, NULL
);
// clean up
if (hOldPal != NULL)
{
SelectPalette(hMemDC, hOldPal, false);
}
pPicture->Release();
pStream->Release();
GlobalFree(hData);
}
catch (...)
{
// clean up
pPicture->Release();
pStream->Release();
GlobalFree(hData);
throw;
}
// retun the bitmap (caller assumes ownership)
return Bitmap.release();
}
HTH,
--
Damon (TeamB)
BCBCAQ--http://bcbcaq.bytamin-c.com
Re: change wallpaper gif/jpg
Author: Subliminal
Date: Thu, 24 Apr 2003 12:19
Date: Thu, 24 Apr 2003 12:19
7 lines
1371 bytes
1371 bytes
how could I use that in a project? what would I need to call the function....? I assume it should be defined as so in the header: Graphics::TBitmap* LoadImageFromFile(AnsiString filename); so far all my attempts at creating a TBitmap and then assigning it the bitmap from the function have failed, could you show me how to do it? --Sub
Re: change wallpaper gif/jpg
Author: Subliminal
Date: Thu, 24 Apr 2003 14:33
Date: Thu, 24 Apr 2003 14:33
5 lines
1223 bytes
1223 bytes
How could I do this using IActiveDesktop? what headers are needed and how do I access the SetWallPaper function? could you post and example please as all the ones I can find are VC++ oriantated and have som header files which create errors rather than fix them. --Sub
Re: change wallpaper gif/jpg
Author: Remy Lebeau (TeamB)
Date: Thu, 24 Apr 2003 17:45
Date: Thu, 24 Apr 2003 17:45
12 lines
1345 bytes
1345 bytes
"Subliminal" <doug@cowie3.fsnet.co.uk> wrote in message news:3ea7d63a@newsgroups.borland.com... > so far all my attempts at creating a TBitmap and then > assigning it the bitmap from the function have failed, > could you show me how to do it? Please show your actual source code. Gambit
Re: change wallpaper gif/jpg
Author: Remy Lebeau (TeamB)
Date: Thu, 24 Apr 2003 17:57
Date: Thu, 24 Apr 2003 17:57
36 lines
1975 bytes
1975 bytes
"Subliminal" <doug@cowie3.fsnet.co.uk> wrote in message
news:3ea7f5ab@newsgroups.borland.com...
> what headers are needed
shlobj.h
> and how do I access the SetWallPaper function?
You need to create an instance of the IActiveDesktop interface, then you
simply call SetWallPaper() like you would any other class method.
> could you post and example please
#include <shlobj.h>
#include <utilcls.h>
TComInterface<IActiveDesktop> ActiveDesktop;
CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (LPVOID*)&ActiveDesktop);
if( ActiveDesktop )
{
ActiveDesktop->SetWallpaper(WideString("path to file"), 0);
WALLPAPEROPT opt;
opt.dwSize = sizeof(WALLPAPEROPT);
opt.dwStyle = WPSTYLE_STRETCH;
ActiveDesktop->SetWallpaperOptions(&opt, 0);
ActiveDesktop->ApplyChanges(AD_APPLY_ALL);
}
Gambit
Re: change wallpaper gif/jpg
Author: Fernando Alvarez
Date: Fri, 25 Apr 2003 10:55
Date: Fri, 25 Apr 2003 10:55
177 lines
6043 bytes
6043 bytes
Cool!!!!. It works fine fine fine!!!!! Thank you, thank you very much.
"Damon Chandler (TeamB)" <dmc27@cornell.edu> escribi� en el mensaje
news:3EA63274.D0D9367F@cornell.edu...
> Hi Fernando,
> > How can I convert gif/jpg to bmp?
>
> The following function uses the IPicture interface to convert a GIF or
JPEG
> to a bitmap; it returns a TBitmap object which you can dump to a file via
> TBitmap::SaveToFile()...
>
> #include <ole2.h>
> #include <olectl.h>
> #include <memory>
> Graphics::TBitmap* LoadImageFromFile(
> AnsiString filename
> )
> {
> // open the file for shared reading
> HANDLE const hFile = CreateFile(
> filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL,
> OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
> );
> if (hFile == INVALID_HANDLE_VALUE)
> {
> throw EWin32Error("Error opening file.");
> }
>
> // allocate a global memory object of the file's size
> DWORD const dwSize = GetFileSize(hFile, NULL);
> HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, dwSize);
> if (hData == NULL)
> {
> CloseHandle(hFile);
> throw EWin32Error("Error allocating memory.");
> }
>
> // grab a pointer to the memory
> LPVOID pData = GlobalLock(hData);
> if (pData == NULL)
> {
> GlobalFree(hData);
> CloseHandle(hFile);
> throw EWin32Error("Error accessing memory.");
> }
>
> // read the data from the file
> DWORD dwRead = 0;
> bool read_ok = ReadFile(hFile, pData, dwSize, &dwRead, NULL);
> if (!read_ok || (dwRead != dwSize))
> {
> GlobalUnlock(hData);
> GlobalFree(hData);
> CloseHandle(hFile);
> throw EWin32Error("Error reading file.");
> }
>
> // clean up
> GlobalUnlock(hData);
> CloseHandle(hFile);
>
> // create an IStream object on hData
> IStream* pStream;
> HRESULT hRes = CreateStreamOnHGlobal(hData, false, &pStream);
> if (FAILED(hRes))
> {
> GlobalFree(hData);
> throw EWin32Error("Failed to create IStream.");
> }
>
> // load the picture (create an IPicture object)
> IPicture* pPicture;
> hRes = OleLoadPicture(
> pStream, 0, false, IID_IPicture,
> reinterpret_cast<void**>(&pPicture)
> );
> if (FAILED(hRes))
> {
> pStream->Release();
> GlobalFree(hData);
> throw EWin32Error("Failed to create IPicture.");
> }
>
> // grab a handle to the Picture's palette, if present
> HPALETTE hPal = NULL;
> pPicture->get_hPal(reinterpret_cast<OLE_HANDLE*>(hPal));
> if (hPal != NULL)
> {
> int const num_entries =
> GetPaletteEntries(hPal, 0, 0, NULL);
> long const size = sizeof(LOGPALETTE) +
> (num_entries - 1) * sizeof(PALETTEENTRY);
>
> // copy the palette (because IPicture owns it)
> LPLOGPALETTE pLogPal =
> reinterpret_cast<LPLOGPALETTE>(GlobalAlloc(GPTR, size));
> if (pLogPal != NULL)
> {
> int const num_got = GetPaletteEntries(
> hPal, 0, num_entries, pLogPal->palPalEntry
> );
> pLogPal->palVersion = 0x300;
> pLogPal->palNumEntries = num_got;
> hPal = CreatePalette(pLogPal);
> GlobalFree(pLogPal);
> }
> }
>
> // retrieve the width and height of the picture
> SIZE SHiMetric = {0, 0};
> pPicture->get_Width(&SHiMetric.cx);
> pPicture->get_Height(&SHiMetric.cy);
>
> // convert HIMETRIC units to pixels
> HDC hScreenDC = GetDC(NULL);
> int const width = MulDiv(
> SHiMetric.cx, GetDeviceCaps(hScreenDC, LOGPIXELSX), 2540
> );
> int const height = MulDiv(
> SHiMetric.cy, GetDeviceCaps(hScreenDC, LOGPIXELSY), 2540
> );
> ReleaseDC(NULL, hScreenDC);
>
> // create a TBitmap object
> std::auto_ptr<Graphics::TBitmap> Bitmap(new Graphics::TBitmap());
> try
> {
> // set the bitmap's attributes
> Bitmap->PixelFormat = pf24bit;
> Bitmap->Width = width;
> Bitmap->Height = height;
>
> // grab a handle to the bitmap's memory DC
> HDC const hMemDC = Bitmap->Canvas->Handle;
>
> // associate the palette (if present) with the bitmap's DC
> HPALETTE hOldPal = NULL;
> if (hPal != NULL)
> {
> Bitmap->Palette = hPal;
> hOldPal = SelectPalette(hMemDC, hPal, false);
> RealizePalette(hMemDC);
> }
>
> // render the picture to the memory DC
> pPicture->Render(
> hMemDC, 0, 0, width, height, 0, SHiMetric.cy,
> SHiMetric.cx, -SHiMetric.cy, NULL
> );
>
> // clean up
> if (hOldPal != NULL)
> {
> SelectPalette(hMemDC, hOldPal, false);
> }
> pPicture->Release();
> pStream->Release();
> GlobalFree(hData);
> }
> catch (...)
> {
> // clean up
> pPicture->Release();
> pStream->Release();
> GlobalFree(hData);
> throw;
> }
>
> // retun the bitmap (caller assumes ownership)
> return Bitmap.release();
> }
>
> HTH,
> --
> Damon (TeamB)
> BCBCAQ--http://bcbcaq.bytamin-c.com
Re: change wallpaper gif/jpg
Author: Subliminal
Date: Fri, 25 Apr 2003 21:16
Date: Fri, 25 Apr 2003 21:16
20 lines
2028 bytes
2028 bytes
I copy and pasted your code directly and only added a button and TOpenDialog to the form yet receive the following errors: Build [C++ Error] shobjidl.h(2193): E2238 Multiple declaration for 'FOLDERSETTINGS' [C++ Error] shobjidl.h(8095): E2238 Multiple declaration for 'DESKBANDINFO' [C++ Error] shlobj.h(1422): E2238 Multiple declaration for 'FVSHOWINFO' [C++ Error] shlobj.h(3457): E2238 Multiple declaration for 'SHELLFLAGSTATE' [C++ Error] Unit1.cpp(25): E2015 Ambiguity between 'CLSID_ActiveDesktop' and 'Shlobj::CLSID_ActiveDesktop' using C++Builder v6, I assume the active desktop is declared somewere else (obviously) but I am unsure of where, if I commecnt out shlobj.h then IActiveDesktop is called an undefined symbol and therefore there are other errors. When I click an error it opens up shobjidl.h btw. Hope you can locate the problem --Sub
Re: change wallpaper gif/jpg
Author: Remy Lebeau (TeamB)
Date: Fri, 25 Apr 2003 21:42
Date: Fri, 25 Apr 2003 21:42
13 lines
1431 bytes
1431 bytes
"Subliminal" <doug@cowie3.fsnet.co.uk> wrote in message news:3ea9a584@newsgroups.borland.com... > I copy and pasted your code directly and only > added a button and TOpenDialog to the form > yet receive the following errors: <snip> Go into the Project Options and add NO_WIN32_LEAN_AND_MEAN to the Conditionals list. Gambit
Re: change wallpaper gif/jpg
Author: Subliminal
Date: Sun, 27 Apr 2003 09:43
Date: Sun, 27 Apr 2003 09:43
9 lines
1454 bytes
1454 bytes
Thanks thats reduced the errors to the last one: [C++ Error] Unit1.cpp(25): E2015 Ambiguity between 'CLSID_ActiveDesktop' and 'Shlobj::CLSID_ActiveDesktop' which I still get when I comment "#include <shlobj.h>" out. I changed CoCreateInstance(Shlobj::CLSID_ActiveDesktop...... and it worked fine. Thanks Remy
Re: change wallpaper gif/jpg
Author: Remy Lebeau (TeamB)
Date: Sun, 27 Apr 2003 20:37
Date: Sun, 27 Apr 2003 20:37
13 lines
1611 bytes
1611 bytes
"Subliminal" <doug@cowie3.fsnet.co.uk> wrote in message news:3eaba62f@newsgroups.borland.com... > [C++ Error] Unit1.cpp(25): E2015 Ambiguity between > 'CLSID_ActiveDesktop' and 'Shlobj::CLSID_ActiveDesktop' Are you including the VCL's ShlObj.hpp header file as well as the API's shlobj.h header file? If so, don't. They can't be included together. Choose one or the other, not both. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads