Solved

(Mouse Wheel) Exiting program crashes Visual Basic

Posted on 2003-11-17
11
2,267 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now