Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

(Mouse Wheel) Exiting program crashes Visual Basic

Posted on 2003-11-17
11
2,278 Views
Last Modified: 2013-11-25
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
Comment
Question by:dbrckovi
  • 6
  • 5
11 Comments
 
LVL 11

Author Comment

by:dbrckovi
ID: 9762266
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
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9762269
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
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9762281
try giving doEvents between the 2 statements
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 11

Author Comment

by:dbrckovi
ID: 9762515
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
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9762597
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
 
LVL 11

Author Comment

by:dbrckovi
ID: 9762687
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
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9762747
dbrckovi : you dont need to write a piece of code the scroll starts working like it works on ie or excel.
0
 
LVL 11

Author Comment

by:dbrckovi
ID: 9762820
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
 
LVL 9

Accepted Solution

by:
bhagyesht earned 50 total points
ID: 9768821
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
 
LVL 11

Author Comment

by:dbrckovi
ID: 9795605
Well. I guess i will have to cheat, and use a control.
Thanx!
0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9808310
glad could help!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question