LB Booster
Programming >> Liberty BASIC language >> Putting text into a listview "cell" - return value
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1431185289

Putting text into a listview "cell" - return value
Post by datwill on May 9th, 2015, 3:28pm

Hi, I'm creating this programme with a listview and I try to add text into a "cell", but it isn't working... I've checked the return value of the DLL call with the debugger and it equals -1 ??? what does this mean? What I know for sure is that it didn't work because nothings being presented in the "cells"
Code:
nomainwin
global hwndListView1
tableHeight = DisplayHeight-62
stylebits #table, _WS_MAXIMIZE, 0, 0, 0
open "Awakening Errors" for window as #table
#table "trapclose [quit] ; resizehandler [resize]": hWin = hwnd(#table)
struct LVITEM, mask as ulong, iItem as long, iSubItem as long, state as ulong, stateMask as ulong, pszText$ as ptr, cchTextMax as long, iImage as long, lParam as long, iIndent as long
struct LVCOLUMN, mask as ulong, fmt as long, cx as long, pszText$ as ptr, cchTextMax as long, iSubItem as long, iImage as long, iorder as long
style = _WS_CHILD or _WS_VISIBLE or 32768 or 1 or 4 or 8
calldll #comctl32, "InitCommonControls", r as void
calldll #user32, "GetWindowLongA", hWin as ulong, _GWL_HINSTANCE as long, hInstance as ulong
calldll #user32, "CreateWindowExA", _WS_EX_CLIENTEDGE as long, "SysListView32" as ptr, "" as ptr, style as long, 0 as long, 0 as long, DisplayWidth as long, tableHeight as long, hWin as ulong, 0 as long, hInstance as ulong, "" as ptr, hwndListView1 as ulong
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4150 as long, 32 as long, 32 as long, re as long
LVCOLUMN.mask.struct = 2 or 4: LVCOLUMN.cx.struct = 45: LVCOLUMN.pszText$.struct = "Code"
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4123 as long, 0 as long, LVCOLUMN as struct, r as long
LVCOLUMN.cx.struct = 200: LVCOLUMN.pszText$.struct = "Message"
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4123 as long, 1 as long, LVCOLUMN as struct, r as long
LVCOLUMN.cx.struct = 400: LVCOLUMN.pszText$.struct = "What does this mean?"
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4123 as long, 2 as long, LVCOLUMN as struct, r as long
LVCOLUMN.cx.struct = 260: LVCOLUMN.pszText$.struct = "How hard is it for this error to be made/occur?"
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4123 as long, 3 as long, LVCOLUMN as struct, r as long
LVCOLUMN.cx.struct = 500: LVCOLUMN.pszText$.struct = "How is this so hard or easy?"
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4123 as long, 4 as long, LVCOLUMN as struct, r as long
LVITEM.mask.struct = 1 'place all entries between here and the wait statement!
call cell 70, "Couldn't create tooltip structure", "This means Awakening could not create a block of memory used for the main menu tooltips (the boxes which appear over a list or button in a window which explain a bit about what it does)", 4, "This means there isn't enough memory on this computer to support this structure - very unlikely considering how much memory computer's have now a days!"
wait

[quit]
close #table: end

[resize]
calldll #user32, "MoveWindow", hwndListView1 as ulong, 0 as long, 0 as long, WindowWidth as long, WindowHeight as long, 1 as long, r as long
wait

sub cell errorCode, errorMessage$, errorAbout$, errorLevel, errorAboutLevel$
    LVITEM.iItem.struct = errorCode-70: LVITEM.pszText$.struct = str$(errorCode)
    calldll #user32, "SendMessageA", hwndListView1 as ulong, 4103 as long, 0 as long, LVITEM as struct, r as long
    LVITEM.iSubItem.struct = 1: LVITEM.pszText$.struct = errorMessage$
    calldll #user32, "SendMessageA", hwndListView1 as ulong, 4103 as long, 0 as long, LVITEM as struct, r as long
    LVITEM.iSubItem.struct = 2: LVITEM.pszText$.struct = errorAbout$
    calldll #user32, "SendMessageA", hwndListView1 as ulong, 4103 as long, 0 as long, LVITEM as struct, r as long
    LVITEM.iSubItem.struct = 3: LVITEM.pszText$.struct = word$("QUITE EASY,EASY,QUITE HARD,HARD", errorLevel, ",")
    calldll #user32, "SendMessageA", hwndListView1 as ulong, 4103 as long, 0 as long, LVITEM as struct, r as long
    LVITEM.iSubItem.struct = 4: LVITEM.pszText$.struct = errorAboutLevel$
    calldll #user32, "SendMessageA", hwndListView1 as ulong, 4103 as long, 0 as long, LVITEM as struct, r as long
end sub 

Re: Putting text into a listview "cell" - return v
Post by Richard Russell on May 9th, 2015, 5:08pm

on May 9th, 2015, 3:28pm, Daniel Atwill wrote:
Hi, I'm creating this programme with a listview and I try to add text into a "cell", but it isn't working

The reason you are finding it difficult to debug is that you're using 'magic' constants like 4103 which give no indication of their function! If you used proper Windows Constants it would be immediately obvious why it isn't working - and there's no excuse not to because LBB has them built in.

Specifically, 4103 is _LVM_INSERTITEM which of course is correct for the first reference to the item - you are initially inserting it - but it isn't correct for the subsequent writes to the sub-items. At that stage you don't want _LVM_INSERTITEM you want _LVM_SETITEM!

So go through your program replacing the 'magic' numbers with the corresponding Windows Constants, and be careful where you use _LVM_INSERTITEM and where you use _LVM_SETITEM.

Richard.
Re: Putting text into a listview "cell" - return v
Post by datwill on May 9th, 2015, 7:34pm

Thank you for that, but it will not display the code number column :(
Here's the new code:
Code:
nomainwin
global hwndListView1
tableHeight = DisplayHeight-62
stylebits #table, _WS_MAXIMIZE, 0, 0, 0
open "Awakening Errors" for window as #table
#table "trapclose [quit] ; resizehandler [resize]": hWin = hwnd(#table)
struct LVITEM, mask as ulong, iItem as long, iSubItem as long, state as ulong, stateMask as ulong, pszText$ as ptr, cchTextMax as long, iImage as long, lParam as long, iIndent as long
struct LVCOLUMN, mask as ulong, fmt as long, cx as long, pszText$ as ptr, cchTextMax as long, iSubItem as long, iImage as long, iorder as long
style = _WS_CHILD or _WS_VISIBLE or 32768 or 1 or 4 or 8
calldll #comctl32, "InitCommonControls", r as void
calldll #user32, "GetWindowLongA", hWin as ulong, _GWL_HINSTANCE as long, hInstance as ulong
calldll #user32, "CreateWindowExA", _WS_EX_CLIENTEDGE as long, "SysListView32" as ptr, "" as ptr, style as long, 0 as long, 0 as long, DisplayWidth as long, tableHeight as long, hWin as ulong, 0 as long, hInstance as ulong, "" as ptr, hwndListView1 as ulong
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4150 as long, 32 as long, 32 as long, re as long
LVCOLUMN.mask.struct = 2 or 4: LVCOLUMN.cx.struct = 45: LVCOLUMN.pszText$.struct = "Code"
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4123 as long, 0 as long, LVCOLUMN as struct, r as long
LVCOLUMN.cx.struct = 300: LVCOLUMN.pszText$.struct = "Message"
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4123 as long, 1 as long, LVCOLUMN as struct, r as long
LVCOLUMN.cx.struct = 1010: LVCOLUMN.pszText$.struct = "What does this mean?"
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4123 as long, 2 as long, LVCOLUMN as struct, r as long
LVCOLUMN.cx.struct = 260: LVCOLUMN.pszText$.struct = "How hard is it for this error to be made/occur?"
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4123 as long, 3 as long, LVCOLUMN as struct, r as long
LVCOLUMN.cx.struct = 1350: LVCOLUMN.pszText$.struct = "How is this so hard or easy?"
calldll #user32, "SendMessageA", hwndListView1 as ulong, 4123 as long, 4 as long, LVCOLUMN as struct, r as long
LVITEM.mask.struct = 1 'place all entries between here and the wait statement!

for loopVar = 0 to 9
    LVITEM.iItem.struct = loopVar
    calldll #user32, "SendMessageA", hwndListView1 as ulong, _LVM_INSERTITEM as long, 0 as long, LVITEM as struct, r as long
next
call cell 70, "Couldn't create tooltip structure", "This means Awakening could not create a block of memory used for the main menu tooltips (the boxes which appear over a list or button in a window which explain a bit about what it does)", 4, "This means there isn't enough memory on this computer to support this structure - very unlikely considering how much memory computer's have now a days!"
call cell 71, "Couldn't create the main menu combobox array", "This is another block of data dedicated to display the options in the combobox which appears in the main menu", 4, "The same reasoning as code 70"
call cell 72, "Couldn't create local variables", "This means Awakening could not create the memory for data to do with the main menu window and other GUI elements", 4, "Again, the same reason as code 70"
call cell 73, "Couldn't create global variables", "This means Awakening could not create the memory for the actual game and for functions (see code 76) - this is "+chr$(34)+"more important"+chr$(34)+" then the local variables, but all data is important!", 4, "See code 70"
call cell 74, "Couldn't open the profile database", "Awakening was not able to load all the user's files!", 4, "This is hard to achieve as Awakening, even if it cannot find the game files.dat file, will create a new one - therefore the game doesn't crash. This is prone; however; to the loss of Awakening profiles (if the file is not found for whatever reason) so BE CAREFUL!"
call cell 75, "Couldn't create byte lengths to database entries", "Awakening creates appropriate character lengths for all the profile data (this is the reason for the 50 length for the name of your file!). This means Awakening wasn't able to perform this task", 4, "For this to not work, you'd have to do something hideously wrong with the application itself (edit the contents of it), which you should NEVER do!"
call cell 76, "Couldn't perform function: functionName()", "For whatever reason, Awakening wasn't able to call the function (a piece of code) named functionName()", 4, "See code 75"
call cell 77, "Couldn't form main menu UI", "The main menu window and all it's elements could not be created", 1, "See code 78"
call cell 78, "Couldn't create tooltips", "Awakening's tooltips could not be graphically constructed", 1, "This part uses things called DLLs, basically external functions (pieces of code) which are in files with extensions of .dll. This error can be made if you delete the appropriate DLL (which isn't in the Awakening folder) - this is worse than to mess around with the application (see code 75) and SHOULD NEVER BE DONE FOR ANY REASONS! If you do it will mess up the WHOLE computer, not just Awakening"
call cell 79, "Couldn't create the main menu status bar", "Awakening's footer bar in the main menu (which tells you which file you have selected out of the file list) could not be constructed", 1, "See code 78"
wait

[quit]
close #table: end

[resize]
calldll #user32, "MoveWindow", hwndListView1 as ulong, 0 as long, 0 as long, WindowWidth as long, WindowHeight as long, 1 as long, r as long
wait

sub cell errorCode, errorMessage$, errorAbout$, errorLevel, errorAboutLevel$
    LVITEM.iItem.struct = errorCode-70: LVITEM.pszText$.struct = str$(errorCode)
    calldll #user32, "SendMessageA", hwndListView1 as ulong, _LVM_SETITEM as long, 0 as long, LVITEM as struct, r as long
    LVITEM.iSubItem.struct = 1: LVITEM.pszText$.struct = errorMessage$
    calldll #user32, "SendMessageA", hwndListView1 as ulong, _LVM_SETITEM as long, 0 as long, LVITEM as struct, r as long
    LVITEM.iSubItem.struct = 2: LVITEM.pszText$.struct = errorAbout$
    calldll #user32, "SendMessageA", hwndListView1 as ulong, _LVM_SETITEM as long, 0 as long, LVITEM as struct, r as long
    LVITEM.iSubItem.struct = 3: LVITEM.pszText$.struct = word$("QUITE EASY,EASY,QUITE HARD,HARD", errorLevel, ",")
    calldll #user32, "SendMessageA", hwndListView1 as ulong, _LVM_SETITEM as long, 0 as long, LVITEM as struct, r as long
    LVITEM.iSubItem.struct = 4: LVITEM.pszText$.struct = errorAboutLevel$
    calldll #user32, "SendMessageA", hwndListView1 as ulong, _LVM_SETITEM as long, 0 as long, LVITEM as struct, r as long
end sub     

Re: Putting text into a listview "cell"
Post by Richard Russell on May 9th, 2015, 7:38pm

on May 9th, 2015, 7:34pm, Daniel Atwill wrote:
Thank you for that, but it will not display the code number column sad

Read my message again, and do what I said!

Richard.


Re: Putting text into a listview "cell" - return v
Post by datwill on May 9th, 2015, 8:21pm

Thank you, after a bit of editing it worked! I hope I didn't make you mad sad
Re: Putting text into a listview "cell"
Post by Richard Russell on May 9th, 2015, 8:55pm

on May 9th, 2015, 8:21pm, Daniel Atwill wrote:
I hope I didn't make you mad sad

Not at all. I hope you didn't mind me 'leading you to the answer'. My wife is a retired teacher! cheesy

Richard.

Re: Putting text into a listview "cell" - return v
Post by datwill on May 9th, 2015, 9:10pm

No I don't and I hope your happy together!