Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2301
  • Last Modified:

(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!
0
dbrckovi
Asked:
dbrckovi
  • 6
  • 5
1 Solution
 
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?
0
 
bhagyeshtCommented:
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.
0
 
bhagyeshtCommented:
try giving doEvents between the 2 statements
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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?
0
 
bhagyeshtCommented:
vb6 supports mouse wheel. only it doesnt support the default scroll mouse driver.

check this
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20315857.html

I have been using VB6 with scroll for quite some time
0
 
dbrckoviAuthor Commented:
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)
0
 
bhagyeshtCommented:
dbrckovi : you dont need to write a piece of code the scroll starts working like it works on ie or excel.
0
 
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.
0
 
bhagyeshtCommented:
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
0
 
dbrckoviAuthor Commented:
Well. I guess i will have to cheat, and use a control.
Thanx!
0
 
bhagyeshtCommented:
glad could help!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now