April 27, 2024, 11:34:06 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Shopping or ToDo List using Combobox

Started by AdrianFox, December 17, 2009, 11:34:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

Here is a simple program making use of a combobox in a window for an alphabetized or prioritized To Do list or shopping list or whatever.

The zip contains all the project files plus the compiled exe.

http://www.loire-gites.eu/software/Shopping.zip

I thought these files might be useful for beginners who are getting to grips with the capabilities of comboboxes, file writing, reading and printing.  Thanks to Ficko for helping me out with getting RETURN to work with a combobox entry.  (Using @notifycode=9 seems to do it in the message handler from the combobox)

Also has a graphic (imgscalable) and a wav music file included as  resources.  Thanks to Copex for showing me how to do the latter.

Apologies to any expert programmers who look at my code and think 'What the heck!' 

Adrian Fox

mrainey

Adrian,

If I click an item twice, it's duplicated on the list.
Software For Metalworking
http://closetolerancesoftware.com

AdrianFox

Thanks for that. 
I've now used

if GETKEYSTATE(0x0D)then
gosub updatecombo

to respond to the enter key in the combobox edit area... and I can't replicate the double entry now.

However, I've discovered that the 'delete item' button is now deleting two entries at a time, so must spend some time today tinkering and testing the program properly before re-posting.

Seasons greetings..... We're snowed in here so I've got lots of time to play with Emergence today!
:)
Adrian Fox

mrainey

QuoteI've discovered that the 'delete item' button is now deleting two entries at a time

You must have fixed it, because I can't see it.   :)
Software For Metalworking
http://closetolerancesoftware.com

Copex

-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

AdrianFox

Slightly odd... when capturing the 'Enter' key with @notifycode=9 in the Combobox handler case statement, the double clicking making a double entry seemed to be a problem. 
Now it's changed to  "IF GETKEYSTATE(0x0D) then...." the double clicking problem is solved, but the way the delete item code worked it deleted more positions than intended...

Originally, I discovered that after 'Delete Item' code below, a blank space was created and left in position 0, so I added another line (remarked out below) which deleted position 0 too. When I changed the code for the Enter key, the blank space was no longer being created so the extra line deleted a second item.

sub deleteitem
x=GETSELECTED (shopping, 0x101)
DELETESTRING shopping, 0x101, x
REM    DELETESTRING SHOPPING, 0x101,0  'SEE IF THIS AVOIDS CREATING A BLANK SPACE ''
RETURN
endsub


I'm intrigued as to how and why @NOTIFYCODE=9 and IFGETSTATE (0x0D) produce different results in clicking modes, when effectively both are just capturing the ENTER key being pressed.

Anyway, I think everything works as intended now.   When I was a teacher, I used to give programs to students to play with.  Usually they managed to hang them within ten minutes, no matter how long I'd tested them myself.  Though that was when I used to produce very poor programs in Liberty Basic which is a 'proper' programming language I now understand!

Joyeux Noel ÃÆ'Ã,  tous,
:)
Adrian Fox

Johnny

Hello Adrian,
About using GetKeyState, I used it several times with success in different programs, so it is a good solution.
But there are few things to think about...
Even when another program is in the foreground, your program can capture that key and react to it, so you have to check that your program is indeed the one on the foreground...
Another thing is that when you press the key a bit longer longer, the key can repeat itself...

So usually I solve this in this way:

DECLARE import, GetForegroundWindow(),INT
...
...
...
IF GETKEYSTATE(0x0D) Then
    IF (GetForegroundWindow() = w1.hwnd) & GETKEYSTATE(0x0D) Then
        Gosub updatecombo
        DO
            WAIT(1)
        UNTIL (GETKEYSTATE(0x0D) = 0)
    ENDIF
ENDIF
...

Greetings,
Johnny

AdrianFox

Johnny,

Thanks for the suggestion.  I see that particularly holding the ENTER key down produces lots of problems, and can appreciate problem of other progs open in foreground.

I have inserted the following code.
IF GETKEYSTATE(0x0D) Then
IF (GetForegroundWindow() = shopping.hwnd) AND  GETKEYSTATE(0x0D) AND getcontroltext (shopping,0x101)<>"" Then
Gosub updatecombo
DO
WAIT(1)
UNTIL (GETKEYSTATE(0x0D) = 0)
ENDIF
ENDIF


I hope I have coded that correctly as I was a bit confused at first by knowing how to define the window name after the = sign in the  'IF (GetForegroundWindow() = '

I added the extra AND as a condition to check that the edit part of the combobox was not empty when ENTER is pressed. 

To what does  the ' .hwnd'  denominator refer ?  Is this just an inbuilt part of that particular function?

Anyway, that all seems to work just fine now, and I will have to try the program with another running in the foreground.

Good of you to take the time to help me improve my coding.  Really appreciated.

Adrian Fox

Johnny

Hello Adrian,

I'm happy that you could use the small sample I gave.
Sorry that I didn't explain further the workings of it, but I know there are people here that know these things much better than I do...  :)

"shopping" is (just like "w1") a window "type" or structure, created while opening a new window (OPENWINDOW).
Inside that structure are several variables stored, one of them is the window's handle (hwnd), this is a unique number identifying that particular window for the operating system.
To address this "hwnd" variable inside the structure, you use it this way in your program: shopping.hwnd

Thanks for sharing your code too!  8)
Johnny


PS: You can find the whole "WINDOW" type/structure in the file "c:\Program Files\EBDev\bin\ebstd.incc" (unless you installed EB elsewhere)

TYPE WINDOW
DEF hWnd as UINT
DEF hBitmap as UINT
DEF hFont as UINT
DEF hPen as UINT
DEF hClient as UINT
DEF m_pos as POINT
DEF m_iBkMode as INT
DEF m_iROP2 as INT
DEF m_nPenStyle as INT
DEF m_nPenWidth as INT
DEF m_cBack as UINT
DEF m_cWindow as UINT
DEF m_bAutoDraw as INT
DEF m_bTabEnable as UINT
DEF m_hCursor as UINT
DEF m_hBackDC as UINT
DEF m_hCacheDC as UINT
DEF m_nCacheCount as INT
DEF m_bDialog as INT
DEF m_pDlgTemplate as POINTER
DEF m_pIB2DScreen as POINTER
DEF m_pIB2DSurface as POINTER
DEF hProcedure as UINT
DEF m_pBrowser as POINTER
DEF m_hPrintDC as UINT
ENDTYPE

AdrianFox

Thanks Johnny,

That certainly makes it much clearer and thanks for the reference to that file.

It's clear I need to do far more reading about the basic principles of Windows programming if I want to progress beyond the simplest of programs.  There's so much information available on line I should have no difficulty studying this.

Perhaps I'm a bit long in the tooth at 63 to learn new tricks, but it's fun trying!

Seasons greetings,

Adrian
Adrian Fox