Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mouse Cursor
Message
From
03/09/1997 18:18:35
 
 
To
03/09/1997 15:02:46
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Miscellaneous
Thread ID:
00047287
Message ID:
00048390
Views:
40
I don't understand what's the use of the LoadCursorFromFile in your code (since you use only standard cursors).

Vlad

>Hi Vlad,
>
>I don't understand either, but it's obviously a "feature", not a bug :-).
>
>Here's what I did to solve my particular situation with the mouse pointers. Since I am only replacing the I-beam with the arrow temporarily, first, I created my own I-beam cursor icon which is essentially a duplicate of the standard system I-beam.
>
>In the startup of my application I store a copy of the system I-beam to an application property using LoadCursor() and CopyIcon().
>
>In my forms with grids that require it, I change the I-beam to an arrow in the appropriate column MouseMove methods required using LoadCursorFromFile() and SetSystemCursor() and change it back to an I-beam in appropriate column.MouseMove, grid.MouseMove, form.MouseMove and form.Unload ( for good measure ) methods using same functions.
>
>When application shuts down I restore system I-beam. Since I am manipulating only standard I-beam and arrow, this seems to work fine for my scenario. Probably not the most elegant solution and not sure of the long-term potential problems :-), but it does seem to get the job done reasonably well. Been fun working thru this problem, but I wish there was a more straightforward, easy method :-).
>
>Thanks for all the input and let me know if you have any other thoughts.
>Bill
>
>
>>It does, somehow. Only that you can't control it over an entire column of a grid. :) I don't understand why, but...
>>
>>Vlad
>>
>>>Hi Vlad,
>>> Thanks for the clarification on the various points. I am going to digest this for awhile and see what I can work out. It would be so much better if MS would simply let us control the cursor shape at all times with internal VFP properties/functions :-).
>>>
>>>Bill
>>>
>>>
>>>>>Hi Vlad,
>>>>> As I suspected the MouseIcon and MousePointer properties only work when the cursor is over the active cell of the grid. I wan the pointer changed for the whole column.
>>>>>
>>>>> Here is my scenario. My test grid has 10 columns. Column4 contains a text box and a combo box. I want the pointer to be an arrow over this column at all times ( other columns too but I am just testing for usage right now :-) ). when the cursor moves over column4 I want the I-beam changed to an arrow. When the cursor then moves over Coulmn3, Column5 or some part of the grid I want it changed back to the default I-beam. Following are the methods and the code I have been testing to accomplish this:
>>>>>
>>>>>Grid Init code:
>>>>>
>>>>>DECLARE INTEGER LoadCursorFromFile in Win32API string
>>>>>DECLARE INTEGER SetSystemCursor in Win32API integer, integer
>>>>>DECLARE INTEGER CopyIcon in Win32API integer
>>>>>PUBLIC ARRAY MouseCursors[2,2]
>>>>
>>>>This part is good.
>>>>
>>>>>MouseCursors[1,1] = 32512 && Normal Arrow
>>>>>lnCursorHandle = LoadCursor( 0, 32512 )
>>>>>MouseCursors[1,2] = CopyIcon( lnCursorHandle )
>>>>>MouseCursors[2,1] = 32513 && I-beam
>>>>>lnCursorHandle = LoadCursor( 0, 32513 )
>>>>>wait window ( "IBeam cursor handle " + str( lnCursorHandle ) )
>>>>>MouseCursors[2,2] = CopyIcon( lnCursorHandle )
>>>>>wait window ( "CopyIcon return " + str( MouseCursors[2,2] ) )
>>>>
>>>>I understand what you wanna do, but you must be aware that: you cannot use SetSystemCursor twice with the same cursor handle (this is why you have that error) because: SetSystemCursor sets the cursor to the new specified one and calls DestroyCursor for the handle you used. If you create a cursor handle (with LoadCursor, LoadCursorFromFile, etc) and you don't use it with SetSystemCursor, you MUST destroy it with DestroyCursor. This is why you must create cursors only when you need them. So, it's not good to create them as you do.
>>>>
>>>>>The above wait windows indicate valid return values
>>>>>
>>>>>
>>>>>Grid Column3 MouseMove, Column5 MouseMove, Grid MouseMove, Form Destroy code to restore I-beam cursor:
>>>>>
>>>>>lnOk = SetSystemCursor( MouseCursors[2,2], 32513 )
>>>>>wait window ( "Reset Cursor " + str( lnOk ) )
>>>>>RELEASE MouseCursors && In Form Destroy only
>>>>
>>>>This is not good. I bet that if you move the mouse very fast the cursor is not restored. This is because you don't have a MouseMove event at every mouse move from one pixel to another, but only at regular time intervals (very small).
>>>>
>>>>>Grid Column4 MouseMove code to change I-beam to arrow:
>>>>>
>>>>>lnHandle = LoadCursorFromFile( "Normal01.cur" )
>>>>>lnOk = SetSystemCursor( lnHandle, 32513 )
>>>>>
>>>>>
>>>>>With the above scenario, when I start up the form and grid, if I move the cursor over Column3 first ( restore I-beam ), I get a WAIT WINDOW indicating success from SetSystemCursor() ( return value 1 ). If I then move the cursor to Column4, the I-beam is successfully changed to an arrow. If I then move the cursor to Column3 or Column5 to reset it to an I-beam, I get a WAIT WINDOW indicating failure from SetSystemCursor() ( return value 0 ). From that point on
>>>>As I said: Mouse on column 3 calls SetSystemCursor with the first saved cursor and destroies this handle. After that, the handle doesn't exist anymore, so SetSystemCursor fails. (A cursor handle is just a pointer to a mouse cursor that exists somewhere in the memory. If the cursor is not there anymore, the pointer is invalid.)
>>>>
>>>>> the cursor is stuck as an arrow and cannot be changed back to an I-beam. The grid MouseMove and Form Destroy code also fail to restore the I-beam. Either I am missing something ( that is probably obvious ) or else there is a system bug or it is not possible to do what I am trying to do. i would appreciate any thoughts you have on this. OS is WinNT 4.0 SP3, VFP 5.0a.
>>>>
>>>>How I see all this (I haven't test it, but I hope it works):
>>>>
>>>>1. Keep somewhere a flag (IBeamFlag) to know what's the status of IBeam cursor.
>>>>2. Keep a list of columns you want to have the modified cursor.
>>>>3. In the grid's Init, call the AddObject and create a timer. The timer should be enabled, Interval in the range 100..500 (test to find a good value) and in Timer method:
>>>>oCurrentObject = sys(1270) && Take a reference to the object under the cursor
>>>>If the object (or its parent if the object is the active textbox in the grid) is not in the list of columns and the cursor was modified, restore the cursor, update the flag.
>>>>4. In the MouseMove for the columns in your list: change the cursor if it was not already changed (test the flag), and update the flag. Probably you will want to have a method somewhere to be called from all these MouseMove methods in order to have the code in only one place. Here is the place to create the new cursor handle (as you do now for the first line in the array)
>>>>5. In the grid's destroy: restore the cursor if it was changed (in case that the user can close the form using the keyboard).
>>>>
>>>>Hope all this works! :)
>>>>
>>>>Vlad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform