(Mouse Wheel) Exiting program crashes Visual Basic


NOTE: this question is worth more points than I have assigned to it, but this is all I have at the moment. Ill leave it
          open for a few days (a week or more), and increase the points as I get them.

I have added MouseWheel functionality to my app.  (Like in this example http://www.vbthunder.com/source/ui/mousewheel.zip)
Everything works perfectly until I exit my program.

There are three methods to exit my app: By clicking [X] on form, by clicking Command Button and through Menu.
Clicking on Command Button works well, while other methods craches my app.
This is weird becouse Menu Item, and command button execute the same code.

Here is the code:
Private Sub cmdExit_Click()           'Code for 'Exit' Button    (Terminates app without problems)
    Unload frmMain
End Sub

Private Sub mnuExit_Click()           'Code for 'Exit' Menu Item        (CRASH)    
    Unload frmMain
End Sub

Private Sub Form_Unload(Cancel As Integer)                              'Code for frmMain's unload event

    respond = MsgBox("Do you wish to exit?", vbYesNo, "Caution!")
    If respond = vbNo Then Cancel = True

    If Cancel = False Then
    End If

End Sub

I have tried to remove 'End' which comes after  'MWheel1.DisableWheel', and then app doesn't crash, but
it doesn't exit completely. (I have to press VB's 'Stop' button to return to Design Mode)
If I compile an exe without 'End' and run it, app remains in taskbar after exiting.

I have tried to use other examples for capturing Mouse Wheel (from internet), and, alone, they work, but when I try
to implement them in my app they all crash on exit.


What is the problem in my app? Why does it crash?  As far as I can see, there's no reason for crashing becouse it allways unhooks messages before exiting. Or is there something I'm missing?

LVL 11
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dbrckoviAuthor Commented:
I gave discovered something:

I have created a command button which executes:  >>   MWheel1.DisableWheel  << only.
If I click it before exiting, then it works fine (it doesn't crash). But why doesn't it work when  MWheel1.DisableWheel and End are placed in the same Sub?
I have tried DoEvents, but it doesn't help.

Any suggestions?
I dont see a reasom why you would need code to implement mouse wheel. I have mouse wheel working on my vb app without any code. all you need is that the driver is properly installed ie not the microsoft driver but the manufacturer's driver. I am using a logitech mouse and a logitech driver i have scrolling available in vb and the ide too.
try giving doEvents between the 2 statements
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

dbrckoviAuthor Commented:
I forgot to mention that I am using V6, and VB6 doesn't support mouse wheel. As far as I know the only way to implement mouse wheel function into VB6 app is to handle windows messages.
(Some controls like scrollbars, MSFlexgrid, etc. supports mousewheel automaticaly, but I want my form to be able to trap mousewheel)

I tried using DoEvents, but it didn't solve it.

Any more suggestions? Anyone?
vb6 supports mouse wheel. only it doesnt support the default scroll mouse driver.

check this

I have been using VB6 with scroll for quite some time
dbrckoviAuthor Commented:

Thanx  bhagyesht.

I'll download it and try it. As I said, if it works I'll leave a question open for some time before accepting.

BTW. Can you show me some example of how to use mousewheel with that new driver? (If it's not too much to ask)
dbrckovi : you dont need to write a piece of code the scroll starts working like it works on ie or excel.
dbrckoviAuthor Commented:
I downloaded it, and now I'll restart my comp.

But I need the code becouse I don't need it just for scrolling, I need it to trigger some other events. Like changing weapons in some games.

To be more precise:
I'd like my app to display a message "Up" or "Down" when mouse wheel is rotated.
I managed to do this, but it crashes on exit.
I know that some controls support Mouse Wheel automaticaly, but like I said I need it for something else.
take a form and keep the tab focus on one control which works with the scroll let the other controls not have focus with tab now if you scroll you can trap the events within that control

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dbrckoviAuthor Commented:
Well. I guess i will have to cheat, and use a control.
glad could help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.