|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Create Icon File From ResourceI want to run this from Sub Main. I have tried several methods and all error out. Here is one failed example. Verified that FLAME is in resources under Icon. Dim picIcon As PictureBox picIcon.Picture = LoadResPicture("FLAME", vbResIcon) ' FAILS HERE Object variable or With block variable not set picIcon.Refresh m_sDPIcon = BuildPath(m_sIconFolder, cIconNameFlame0) SavePicture picIcon, m_sDPIcon Set picIcon = Nothing How do I do this? I also tried to Dim As StdPicture but failed with that too. I cannot find any Help for StdPicture. Where is that? "Lorin" <lor***@hotmail.com> wrote Two suggestions:> I have tried several methods and all error out. > picIcon.Picture = LoadResPicture("FLAME", vbResIcon) ' FAILS HERE 1. Use Set.Set picIcon.Picture = ... 2. Use an Image control. See if either of those get you farther along.... LFS
Show quote
Hide quote
"Lorin" <lor***@hotmail.com> wrote in message If doing this from Sub Main, you'd need to first load a form which has a news:C2792067-EA26-4131-98FD-3817532C538D@microsoft.com... >I want to create an icon file from resource. > I want to run this from Sub Main. > I have tried several methods and all error out. > > Here is one failed example. > Verified that FLAME is in resources under Icon. > > Dim picIcon As PictureBox > picIcon.Picture = LoadResPicture("FLAME", vbResIcon) ' FAILS HERE > Object variable or With block variable not set > picIcon.Refresh > m_sDPIcon = BuildPath(m_sIconFolder, cIconNameFlame0) > SavePicture picIcon, m_sDPIcon > Set picIcon = Nothing > > How do I do this? PictureBox control on it. Then, if you were going to use a local variable for that PictureBox (no real reason to though), you'd need to set a reference. You cannot instantiate a "new" PictureBox control (you get an "Invalid use of New keyword" compile-time error), but you *can* use <formreference>.Controls.Add to dynamically add a PictureBox to a form. Either way, however, you must have a loaded form. > StdPicture is an object so you need to instantiate it.> I also tried to Dim As StdPicture but failed with that too. > I cannot find any Help for StdPicture. > Where is that? > Dim oStdPicture As StdPicture Set oStdPicture = New StdPicture The problem here is that StdPicture doesn't have any way of saving to a file. So, you'd still need to use a PictureBox or API functions to save the icon resource as an ICO file. No idea why you can't find StdPicture in MSDN Library because it's in there. Just type "StdPicture" into the find field of the Index tab. You could also look it up in Object Browser to see the properties and methods that it has. Another option is to use LoadResData to assign the icon resource's binary data to a Byte array and then use VB's file I/O statements and functions to save the file. I don't know if you'd have to do anything more such as writing header information to the file first. The icon resource might already include that information. I don't know for sure about that but I do know that ICO file's have a header. If you do need to write a header, you'd need to read up on the ICO file format so you knew what information to include in the header. I'm curious why you need to do this. The whole point of putting icons, bitmaps, or anything else into a resource that is then compiled into your program is so you don't need the individual ICO, BMP, or whatever files. If you must have this icon as an ICO file, it might be better for you to distribute the ICO file with your app and install it as part of your app's installation. Of course, the risk then is that a user could potentially delete the file. But if it's installed in the application's installation folder, that's not likely (and re-installing would fix it). -- Mike Thanks for the responses.
No StdPicture is not there. Maybe you have a MSDN version later than the last VB version (was it Oct 2001 ?). I have later MSDNs too but was not sure if installing would benefit. I went to MS site and found a very short blurb on it and it was just enough to see what was wrong. (1) should I install the latest MSDN? or not and why? This is what finally worked. Dim picIcon As StdPicture Set picIcon = LoadResPicture("FLAME", vbResIcon) Note: the Set and no .Picture, per MS website m_sDPAssocIcon = BuildPath(m_sIconFolder, cIconNameFlame0) SavePicture picIcon, m_sDPAssocIcon Set picIcon = Nothing Why? I need a file icon to use in the routine that follows that assigns my icon to the files associated with my app. I do not know how to do that otherwise (yet). (2) is there a way to assign associated an icon without using an icon file? (3) I am using a standard icon that works properly on the Caption Bar, however, as a icon on a file it has a black background. (tested in Vista only so far) On the caption bar its background is transparent. What is wrong with my icon? What are the restrictions for the file icon? I tried to web search this but found nothing. I will probably post these new questions if I do not get responses here. Not sure if posting new questions here is the right thing to do. Show quoteHide quote "MikeD" <nob***@nowhere.edu> wrote in message news:Oeojg7K3JHA.1372@TK2MSFTNGP05.phx.gbl... > > "Lorin" <lor***@hotmail.com> wrote in message > news:C2792067-EA26-4131-98FD-3817532C538D@microsoft.com... >>I want to create an icon file from resource. >> I want to run this from Sub Main. >> I have tried several methods and all error out. >> >> Here is one failed example. >> Verified that FLAME is in resources under Icon. >> >> Dim picIcon As PictureBox >> picIcon.Picture = LoadResPicture("FLAME", vbResIcon) ' FAILS HERE >> Object variable or With block variable not set >> picIcon.Refresh >> m_sDPIcon = BuildPath(m_sIconFolder, cIconNameFlame0) >> SavePicture picIcon, m_sDPIcon >> Set picIcon = Nothing >> >> How do I do this? > > If doing this from Sub Main, you'd need to first load a form which has a > PictureBox control on it. Then, if you were going to use a local variable > for that PictureBox (no real reason to though), you'd need to set a > reference. You cannot instantiate a "new" PictureBox control (you get an > "Invalid use of New keyword" compile-time error), but you *can* use > <formreference>.Controls.Add to dynamically add a PictureBox to a form. > Either way, however, you must have a loaded form. > >> >> I also tried to Dim As StdPicture but failed with that too. >> I cannot find any Help for StdPicture. >> Where is that? >> > > StdPicture is an object so you need to instantiate it. > > Dim oStdPicture As StdPicture > Set oStdPicture = New StdPicture > > The problem here is that StdPicture doesn't have any way of saving to a > file. So, you'd still need to use a PictureBox or API functions to save > the icon resource as an ICO file. > > No idea why you can't find StdPicture in MSDN Library because it's in > there. Just type "StdPicture" into the find field of the Index tab. You > could also look it up in Object Browser to see the properties and methods > that it has. > > Another option is to use LoadResData to assign the icon resource's binary > data to a Byte array and then use VB's file I/O statements and functions > to save the file. I don't know if you'd have to do anything more such as > writing header information to the file first. The icon resource might > already include that information. I don't know for sure about that but I > do know that ICO file's have a header. If you do need to write a header, > you'd need to read up on the ICO file format so you knew what information > to include in the header. > > I'm curious why you need to do this. The whole point of putting icons, > bitmaps, or anything else into a resource that is then compiled into your > program is so you don't need the individual ICO, BMP, or whatever files. > If you must have this icon as an ICO file, it might be better for you to > distribute the ICO file with your app and install it as part of your app's > installation. Of course, the risk then is that a user could potentially > delete the file. But if it's installed in the application's installation > folder, that's not likely (and re-installing would fix it). > > -- > Mike > > "Lorin" <lor***@hotmail.com> wrote in message Yep. Use your EXE file and specify the index for the specific icon you news:5DEECC66-C23A-4CE2-85F3-62ABF62AF108@microsoft.com... > > Why? I need a file icon to use in the routine that follows that assigns my > icon to the files associated with my app. > I do not know how to do that otherwise (yet). > > (2) is there a way to assign associated an icon without using an icon > file? want. For an example, run REGEDIT and take a look at some other file extensions under HKEY_CLASSES_ROOT....txtfile would be a good one to look at. Notice the DefaultIcon key. -- Mike "Lorin" <lor***@hotmail.com> wrote in message No. Oct 2001 is the latest that integrates with VB6. I don't think that news:5DEECC66-C23A-4CE2-85F3-62ABF62AF108@microsoft.com... > (1) should I install the latest MSDN? or not and why? later MSDN have VB6 help. I have the 2003 edition, and VB6 help is not part of it. > (3) I am using a standard icon that works properly on the Caption Bar, In addition to assigning an indexed icon from your EXE,> however, as a icon on a file it has a black background. (tested in Vista > only so far) On the caption bar its background is transparent. What is > wrong with my icon? What are the restrictions for the file icon? I tried > to web search this but found nothing. > you could also ust save the file as a custom resource and write the bytes to disk. On the black background: That's the mask bitmap showing. I've seen that on XP when it wasn't a problem on Win9x. I don't remember the exact cause. I think it was that there was a wrong byte in the header that Win9x ignored but which confused XP. You might try comparing the icon header (ICONDIR and ICONDIRENTRY(s)) with a valid icon to see if there's a problem with the standard values. Also check the icon that you originally put into the resource, to see if that displays OK. It may be getting corrupted in its trip through the PictureBox. (I know that the docs say SavePicture will save an icon if an icon was loaded, but I'm not certain that's true.) Show quoteHide quote > I will probably post these new questions if I do not get responses here. > Not sure if posting new questions here is the right thing to do. > > > > "MikeD" <nob***@nowhere.edu> wrote in message > news:Oeojg7K3JHA.1372@TK2MSFTNGP05.phx.gbl... > > > > "Lorin" <lor***@hotmail.com> wrote in message > > news:C2792067-EA26-4131-98FD-3817532C538D@microsoft.com... > >>I want to create an icon file from resource. > >> I want to run this from Sub Main. > >> I have tried several methods and all error out. > >> > >> Here is one failed example. > >> Verified that FLAME is in resources under Icon. > >> > >> Dim picIcon As PictureBox > >> picIcon.Picture = LoadResPicture("FLAME", vbResIcon) ' FAILS HERE > >> Object variable or With block variable not set > >> picIcon.Refresh > >> m_sDPIcon = BuildPath(m_sIconFolder, cIconNameFlame0) > >> SavePicture picIcon, m_sDPIcon > >> Set picIcon = Nothing > >> > >> How do I do this? > > > > If doing this from Sub Main, you'd need to first load a form which has a > > PictureBox control on it. Then, if you were going to use a local variable > > for that PictureBox (no real reason to though), you'd need to set a > > reference. You cannot instantiate a "new" PictureBox control (you get an > > "Invalid use of New keyword" compile-time error), but you *can* use > > <formreference>.Controls.Add to dynamically add a PictureBox to a form. > > Either way, however, you must have a loaded form. > > > >> > >> I also tried to Dim As StdPicture but failed with that too. > >> I cannot find any Help for StdPicture. > >> Where is that? > >> > > > > StdPicture is an object so you need to instantiate it. > > > > Dim oStdPicture As StdPicture > > Set oStdPicture = New StdPicture > > > > The problem here is that StdPicture doesn't have any way of saving to a > > file. So, you'd still need to use a PictureBox or API functions to save > > the icon resource as an ICO file. > > > > No idea why you can't find StdPicture in MSDN Library because it's in > > there. Just type "StdPicture" into the find field of the Index tab. You > > could also look it up in Object Browser to see the properties and methods > > that it has. > > > > Another option is to use LoadResData to assign the icon resource's binary > > data to a Byte array and then use VB's file I/O statements and functions > > to save the file. I don't know if you'd have to do anything more such as > > writing header information to the file first. The icon resource might > > already include that information. I don't know for sure about that but I > > do know that ICO file's have a header. If you do need to write a header, > > you'd need to read up on the ICO file format so you knew what information > > to include in the header. > > > > I'm curious why you need to do this. The whole point of putting icons, > > bitmaps, or anything else into a resource that is then compiled into your > > program is so you don't need the individual ICO, BMP, or whatever files. > > If you must have this icon as an ICO file, it might be better for you to > > distribute the ICO file with your app and install it as part of your app's > > installation. Of course, the risk then is that a user could potentially > > delete the file. But if it's installed in the application's installation > > folder, that's not likely (and re-installing would fix it). > > > > -- > > Mike > > > > >
Help with a bit of maths
OT: The bloated get bloatier MBF to IEEE (Beg. Q) Changing a property on a control Toolbar Dilema Where are the VB6 Reference entries kept? Sort UDT vs Database How do I stop opportunistic record locking from causing massive de calling (and deleting) a string from an unmanaged dll Vista and AutoRedraw |
|||||||||||||||||||||||