Link to home
Start Free TrialLog in
Avatar of dbrckovi
dbrckoviFlag for Croatia

asked on

(Mouse Wheel) Exiting program crashes Visual Basic

Hi!

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
        MWheel1.DisableWheel
        End
    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.

Questions:

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?

Thanx!
Avatar of dbrckovi
dbrckovi
Flag of Croatia image

ASKER

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
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
https://www.experts-exchange.com/questions/20315857/Mouse-wheel-not-scroll-VB6-IDE.html

I have been using VB6 with scroll for quite some time
OK.

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.
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.
ASKER CERTIFIED SOLUTION
Avatar of bhagyesht
bhagyesht
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well. I guess i will have to cheat, and use a control.
Thanx!
glad could help!