About   -   Contact   -   Purchase   -   Search   -   What's New

No Drag and Drop
I have been writing some new components that take advantage of PowerBuilder's drag and drop features. However one thing I tried to do using the native PowerBuilder functions was to put up a NO ENTRY cursor when the user drags the mouse over a control that they are not allowed to drop in to. However I could not find a way to do this as the SetPointer function does not support the no entry cursor. So I resorted to the API and found the following code works a treat!

Declare the following API calls in your window:

function long LoadCursorA( long al_happ, long al_hind ) library 'user32'
function long SetCursor( long al_hcur ) library 'user32'
function boolean DestroyCursor( long al_hcur ) library 'user32'

Then declare an instance variable of type long called il_Image. Then add the following code to your open event:

//32648 is the constant for the no entry cursor
Long IDC_NO = 32648 
il_Image = LoadCursorA( 0, IDC_NO )

Now in the dragwithin event of your object you can add the following code which shows the no entry cursor when an object that cannot be dragged onto this control is dragged:

IF source = dw_top THEN	
	// if the user drags from the tree, display the system
	// no entry symbol.
	SetCursor( il_Image )

The last thing we need to do is to cleanup the allocation of the cursor image as follows:

DestroyCursor( il_Image )


Top of Page

Legal Notice

Ken Howe 2011