Hi all,
REALbasic 5.5.3
Mac OS 10.3.5
this do not works with REALbasic 5.5.3 Windows Standard Edition.
[I just had a crazy idea: build the .exe from Macintosh and run in on the
Windows hardware: failed ! The MouseCursor is not changed. I tried...]
Here is a single/simple explanation of what I have done and why.
<introduction>
I was playing around with the MouseCursor and the ListBox Control. After some
times (I started yesterday - same time !), I was asking myself how I could use
this 'new to me knowledge'.
What did I had ?
a. The Hand cursor (the one we get when the Mouse is over a link),
b. The Hand with all visible fingers
(appears when the Mouse is over something that can be taken or moved),
c. The Hand with all the fingers (second and third phalanges invisibles)
(appears to tells the user (s)he have taken something)
So I will use CURS a when the Mouse is above the ListBox, CURS b when the Mouse
is down "in a Row" and CURS c when I move a Row.
Here is the code step by step:
1. Launch REALbasic,
2. Add a ListBox to the new Project,
Check the ListBox Properties: EnableReorder and EnableDragReorder CheckBox,
(See far bottom of the Properties Window, in the Behavior section)
3. Add a Module and call it mCURS,
4. Open the Module and add a new Method:
Method name: setListBoxCurs
Parameters: LB As ListBox, CursID As Integer
5. Click in the OK button,
6. Copy / Paste the source code noted Part II: setListBoxCurs (far below in the
Source Code Section)
7. Close the mCURS module,
8. Open the Code Editor and Copy / Paste source code in the respective ListBox
Events (Source Code section Part I)
9. Run the project, move the Mouse above the ListBox and outside of the ListBox,
10. Make some Drag Row Reorder...
Nice, isn't it ?
Use this information at will _in your projects_ and send me your comments (if
any),
Emile
BTW: you want to know how I know about these CURS resources / resources ID ?
Very simple... Go to the end of this message, section "Get the Project available
CURS"
Source Code:
------------
Part I: the Code for the ListBox events
a. ListBox1.Change:
// Use the Hand-Click CURS
mCURS.setListBoxCurs Me,44659
b. ListBox1.DragReorderRows:
// Use the Hand-Close CURS
mCURS.setListBoxCurs Me,44661
c. ListBox1.DragRow:
// Use the Hand-Close CURS
mCURS.setListBoxCurs Me,44661
d. ListBox1.MouseDown
// Use the Hand-Open CURS
mCURS.setListBoxCurs Me,44660
e. ListBox1.MouseEnter
// Use the Hand-Click CURS
mCURS.setListBoxCurs Me,44659
f. ListBox1.MouseExit
// Clear the ListBox Control Cursor
mCURS.setListBoxCurs Me,-1
g. ListBox1.Open
Dim i As Integer
// Add 10 Rows for the demonstration
For i = 0 To 9
ListBox1.AddRow "Hi, this is Row " + Str(i)
Next
Part II: setListBoxCurs
// ********** ********** ********** ********** ********** **********
//
// Name: setListBoxCurs
// Inputs: LB As ListBox, CursID As Integer
// Outputs: None
// Syntax: setListBoxCurs LB,CursID
//
// ---------- ---------- ---------- ----------
//
// Created: Saturday, October 30th, 2004
// Creator: Emile Schwarz
//
// ---------- ---------- ---------- ----------
//
// Purposes: Set the MouseCursor CursID for the passed ListBox
//
// ---------- ---------- ---------- ----------
//
// CursID: CURS resource ID value
// -------
// Value ListBox Event
// -1: MouseExit
// 44659: MouseEnter / MouseUp / Open
// 44660: MouseDown / MouseMove
// 44661: MouseDrag
//
//
//
// ********** ********** ********** ********** ********** **********
// Dim the local variables
Dim rf As ResourceFork
Dim mc As MouseCursor
// ---------- ---------- ---------- ---------- ---------- ----------
// 1. The Mouse exits the ListBox: CursID = -1
// Special case: the mouse exits the target ListBox: Nil it
If CursID = -1 Then
// Clears the ListBox MouseCursor
LB.MouseCursor = Nil
// Exits the Method here
Return
End If
// ---------- ---------- ---------- ---------- ---------- ----------
// 2. Other cases: use the passed CURS ID value
// and load the CURS resource from the application
// Get an instance of the Application’s ResourceFork
rf = App.ResourceFork
If rf = Nil Then
MsgBox "Sorry: unable to open the Application ResourceFork"
Return
End If
// Get the wanted MouseCursor
mc = rf.GetCursor(CursID)
If mc = Nil Then
MsgBox "Sorry, I didn't found the CURS ID=" + Str(CursID) + "."
Return
End If
// Set the 'MouseDown' MouseCursor
LB.MouseCursor = mc
More goodies...
Get the Project available CURS
------------------------------
In a new project,
Add a ListBox with 4 Columns,
Add a PopupMenu,
Add a BevelButton (or PushButton if you prefer),
Copy / Paste the following source code in BevelButton.Action:
Dim rf As ResourceFork
Dim mc As MouseCursor
Dim mcCnt As Integer
Dim i As Integer
Dim locRow As Integer
// Get an instance of the Application’s ResourceFork
rf = App.ResourceFork
If rf = Nil Then
MsgBox "Sorry: I was unable to open the Application ResourceFork."
Return
End If
// Get the number of MouseCursor Resources available
mcCnt = rf.ResourceCount("CURS")
If mcCnt = 0 Then
MsgBox "Sorry: I do not found a MouseCursor (CURS) available."
Return
End If
// Make a simple report header
// a. Add a Row
ListBox1.AddRow "CURS found:"
// b. Get the just added Row #
locRow = ListBox1.LastIndex
// Add the number of found CURS resources
ListBox1.Cell(locRow,1) = Str(mcCnt)
i = 0
Do
If rf.GetCursor(i) = Nil Then
// No Cursor ID / Name to display
Else
// Add a brand new Row
ListBox1.AddRow "Mouse Cursor"
locRow = ListBox1.LastIndex // get the just added Row #
// Fill this Cell with the CURS ID #
ListBox1.Cell(locRow,1) = "ID=" + Str(i)
// Fill this Cell with the CURS ID # (same, but as Hex)
ListBox1.Cell(locRow,2) = "ID=$" + Hex(i)
// Fill this Cell with the CURS Name (when one is available)
ListBox1.Cell(locRow,3) = rf.ResourceName("CURS",i)
// Decrease the # of found CURS resource
mcCnt = mcCnt - 1
// Populates the PopupMenu
PMCursors.AddRow Str(i)
End If
// Increase the 'loop indice'
i = i + 1
// To avoid infinite loop(s)
If USerCancelled Then Exit
Loop Until mcCnt = 0 // No more available CURS
Copy / Paste the following source code in ListBox1.Open:
// Fill the header
ListBox1.Heading(0) = "Object Kind"
ListBox1.Heading(1) = "ID (Dec)"
ListBox1.Heading(2) = "ID (Hex)"
ListBox1.Heading(3) = "Resource Name"
At last, Copy / Paste the following source code in PopupMenu1.Action:
Dim rf As ResourceFork
Dim mc As MouseCursor
Dim CURSid As Integer
// Get an Application’s ResourceFork Instance
rf = App.ResourceFork
If rf = Nil Then
MsgBox "Sorry: unable to open the Application ResourceFork."
Return
End If
// Get the value of the choosen entry
CURSid = Val(Me.Text) // Convert String to Integer
// Get the MouseCursor resource
mc = rf.GetCursor(CURSid)
If mc = Nil Then
MsgBox "Sorry: there is no CURS resource ID " + Str(CURSid) + "."
Return
End If
// Set the choosed MouseCursor
ListBox1.MouseCursor = mc
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>
|