News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Problems with List boxes

Started by inich, April 27, 2006, 06:21:52 PM

Previous topic - Next topic

inich

Greetings to All!

I have recently encountered a problem with list boxes in my projects.  When I open the list box and arrow up or down to the desired item, then press Enter, no matter which item I have selected, it is always the first item in the list which is activated.  I have checked the return value, and LB_GETCURSEL always returns NULL.  No error is generated.

This is a recent problem, and whether its a coincidence or not, I have observed that the problem is not there on projects compiled before I downloaded, installed and began to use MASM32 version 9.  I have a .exe file dating from before that on my laptop, and it works fine.  If I make a new copy of the project on my laptop with version 9 installed, the problem occurs.

The dialog has an edit control, a list box, and OK and Cancel buttons.  It is  used either to type in a filename or to select a filename from a list generated from the current folder when the dialog is created.  The idea is that if the edit control is empty the selected item in the list box will be copied to FileName[].  However, the same problem occurs in another use of a list box that, apart from an OK button, is the only control in the dialog.

I know that MASM has a GetOpenFileName procedure available, but I am a totally blind computer user, and GetOpenFileName is unfriendly to me, apparently because something in it is non-standard.

I append  a couple of code snipits.  Can anyone suggest what is happening?  I'd be grateful for any thoughts, and would gladly supply more information.

inich
Toronto, Canada


From the DlgProc (note that some lines below may wrap, but are not wrapped in my source file

.elseif uMsg==WM_COMMAND
   .if wParam  == IDOK
   invoke GetDlgItemText, hwnd, IDC_Edit1, ADDR FileName, 96 ; Copy anything in the edit control

   .if BYTE PTR FileName[0] == NULL  ; If edit box is empty, get filename from ListBox
   invoke SendMessage, hList, LB_GETCURSEL, 0, 0
   cmp   eax, LB_ERR  ; (= 0FFFFFFFFh)
   jne   @F

   invoke MessageBeep, 10h  ; Sound an alarm!
invoke EndDialog, hwnd, FALSE

@@:   mov   SelectedItem, eax  ; Store selected item index
   invoke SendMessage, hList, LB_GETTEXT, SelectedItem, ADDR FileName  ; Copy text of selection from ListBox
   .endif
   invoke EndDialog, hwnd, TRUE

   .elseif wParam  == IDCANCEL
invoke EndDialog, hwnd, FALSE
   .endif
.endif


From the .rc file:

690 DIALOGEX MOVEABLE IMPURE LOADONCALL DISCARDABLE   10, 10, 480, 200
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME
CAPTION "Get Filename"
BEGIN
CTEXT   "Enter filename:  ", IDC_STATIC, 4, 16, 100, 16, SS_LEFT, , 0
        EDITTEXT         IDC_Edit1, 100, 16, 300, 16, ES_AUTOHSCROLL | ES_LEFT | WS_TABSTOP
LISTBOX         IDC_List1, 4, 32, 480, 110, ES_AUTOVSCROLL | ES_LEFT |WS_TABSTOP
    DEFPUSHBUTTON   "OK", IDOK, 10, 4, 52, 12
    PUSHBUTTON      "Cancel", IDCANCEL, 72, 4, 52, 12
END



MichaelW

Hello inich,

I cannot find any problems in the code you posted. I coded my own app using the essential parts of your code and LB_GETCURSEL works OK. Perhaps the problem is somewhere in the code that you did not post.


eschew obfuscation

inich

Hi Michael,

Thanks for taking the time to check out my code.

I'm still puzzled by the fact that this code worked fine until earlythis month, when I upgraded to MASM32 version 9.  Could I have gotten a corrupt download?  I used the same downloaded file to install on both my PC and my laptop.

I'll continue to experiment to see if there is a problem elsewhere.

Ian
Toronto, Canada

inich

Hello again, everyone,

Well, I'm feeling a bit stupid and sheepish, and I have egg all over my face.  I continued looking at this problem, keeping very much in mind what MichaelW suggested, that the problem may be in code that I did not put into my initial post.

Although I said that this code was working until early in April, I discovered that I had made a change -- why, I am not sure.  The problem turned out to be a  bad handle for the List box; bad because I had moved

   invoke GetDlgItem, hwnd, IDC_List1
   mov   hList,eax

to after

.if uMsg == WM_INITDIALOG

Unfortunately my previous investigations had not pointed to the handle as being the problem.

My apologies and my thanks to all those who wasted time looking at this.  I'll try to be more careful in the future.  My apologies also to Version 9 for thinking it might have been the culprit.  It was obviously a sheer coincidence that beginning to use it and "fixing" code that wasn't broken were events that came close together.

Yours in embarrassment,

Ian
inich
Toronto, Canada


hutch--

Hi Ian,

I would not worry too much about the odd blunder, we have all done a few masterpieces in our time. I hav4e learnt that anything I write after midnight should be rechecked the next morning.  :bg
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

zcoder

Anything I write after midnight should be added to the programmers "DO NOT DO"  Hall of Fame. ::)

Zcoder....
Back in 1979, My computer ran so fine.
And there was no such thing,
As a Microsoft Crashed Machine.
http://zcoder.110mb.com
http://www.dietzel.com/partner/idevaffiliate.php?id=345_6  Free Domain Names