Page 1 of 1
Background Images in ListIcons
Posted: Wed Apr 28, 2004 3:50 pm
by Shopro
Hello,
I was playing with the ListIcon_BackgroundImage.pb by El_Choni included in the CodeArciv 1.8, and was impressed by the results.
But there seems to be a problem with it on PB3.9.
After changing
[code]
Buffer = AllocateMemory(0, 512)
[/code]
to
[code]
Buffer = AllocateMemory(512)
[/code]
the program runs fine except that it gives a fatal error when shut down.
After deleting the line
[code]
OleUninitialize_()
[/code]
everything seems to be fine.
Erm, is this safe? I looked up what an "OLE" is and have a vague understanding what it it is, but still don't get what's really going on in the code.
Basicly what I'd like to know is, is it ok to assume everything is ok with "OleUninitialize_()" gone?
Thanks:)
-Shopro
Posted: Wed Apr 28, 2004 4:10 pm
by El_Choni
This works, only changed Ole...() to Co...(), no crash on exit:
Code: Select all
; English forum: http://jconserv.net/purebasic/viewtopic.php?t=5208&highlight=
; Author: El_Choni
; Date: 25. February 2003
#LVBKIF_SOURCE_NONE = 0
#LVBKIF_SOURCE_HBITMAP = 1
#LVBKIF_SOURCE_URL = 2
#LVBKIF_SOURCE_MASK = 3
#LVBKIF_STYLE_NORMAL = 0
#LVBKIF_STYLE_TILE = $10
#LVBKIF_STYLE_MASK = $10
#LVM_SETBKIMAGE = #LVM_FIRST + 68
#LVM_SETBKIMAGEW = #LVM_FIRST + 138
#LVM_GETBKIMAGE = #LVM_FIRST + 69
#LVM_GETBKIMAGEW = #LVM_FIRST + 139
#CLR_NONE = -1
Structure LVBKIMAGE
ulFlags.l
hbm.l
pszImage.l
cchImageMax.l
xOffsetPercent.l
yOffsetPercent.l
EndStructure
CoInitialize_(0)
If OpenWindow(0, 384, 288, 640, 480, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget, "ListIconGadget background image example")
LVWidth = WindowWidth()
LVCWidth = Int(LVWidth/4)-1
If CreateGadgetList(WindowID())
ListIconGadget = ListIconGadget(0, 0, 0, LVWidth, WindowHeight(), "Column 0", LVCWidth, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(0, 1, "Column 1", LVCWidth)
AddGadgetColumn(0, 2, "Column 2", LVCWidth)
AddGadgetColumn(0, 3, "Column 3", LVCWidth)
AddGadgetItem(0, 0, "Aaa 1"+Chr(10)+"Bcc 3"+Chr(10)+"Cdd 2"+Chr(10)+"Eee 3"+Chr(10), 0)
AddGadgetItem(0, 1, "Aab 2"+Chr(10)+"Bbc 2"+Chr(10)+"Ddd 3"+Chr(10)+"Dde 1"+Chr(10), 0)
AddGadgetItem(0, 2, "Abb 3"+Chr(10)+"Baa 1"+Chr(10)+"Ccd 1"+Chr(10)+"Dee 2"+Chr(10), 0)
SendMessage_(ListIconGadget, #LVM_SETTEXTCOLOR, 0, $ff0000)
SendMessage_(ListIconGadget, #LVM_SETBKCOLOR, 0, #CLR_NONE)
SendMessage_(ListIconGadget, #LVM_SETTEXTBKCOLOR, 0, #CLR_NONE)
Buffer = AllocateMemory(512)
GetModuleFileName_(GetModuleHandle_(0), Buffer, 512)
InitialDir$ = GetPathPart(PeekS(Buffer))
FreeMemory(Buffer)
File$ = OpenFileRequester("Select image", InitialDir$, "ListIcon supported images|*.bmp;*.ico;*.gif;*.jpg;*.wmf;*.emf", 0)
If File$
lbk.LVBKIMAGE
lbk\ulFlags = #LVBKIF_STYLE_NORMAL|#LVBKIF_SOURCE_URL;|#LVBKIF_STYLE_TILE
lbk\pszImage = @File$
; lbk\xOffsetPercent;
; lbk\yOffsetPercent;
SendMessage_(ListIconGadget, #LVM_SETBKIMAGE, 0, lbk)
EndIf
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow
EndIf
EndIf
CoUninitialize_()
End
Posted: Wed Apr 28, 2004 4:16 pm
by Shopro
El_Choni:
Thanks for the very quick reply:)
Er, it still crashes on exit. The weird part is, it doesn't crash when the Debugger is on, but it does when it is off.
The original code did this as well, but was fixed when I deleted "Ole...()". The same for the new one, it doesn't crash without the "Co...()"
Any comment on this

?
-Shopro
Posted: Wed Apr 28, 2004 4:20 pm
by El_Choni
*Could* be that there's some other CoUninitialize_() going on somewhere, hard to know. You can check if CoInitialize_() succeeded, and only call CoUninitialize_() if it did.
The PSDK says:
"Because the list-view control uses OLE COM to manipulate the background images, the calling application must call CoInitialize or OleInitialize before sending this message [LVM_SETBKIMAGE]. It is best to call one of these functions when the application is initialized and call either CoUninitialize or OleUninitialize when the application is terminating. "
Posted: Wed Apr 28, 2004 4:31 pm
by Shopro
*Could* be that there's some other CoUninitialize_() going on somewhere, hard to know. You can check if CoInitialize_() succeeded, and only call CoUninitialize_() if it did.
Ahh, I understand. Thanks, El_Choni, I'll do that
-Shopro
Posted: Wed Apr 28, 2004 4:38 pm
by El_Choni
(note: CoInitialize_(0) suceeds if it's equal to #S_OK, that is, 0)