Previous | Index | Next 

[HOWTO] Get rid of warnings related to Screen.MousePointer property

VB Migration Partner partially supports the Screen.MousePointer property, by mapping it to the MousePointer property of the Screen6 object, defined in the support library. This property internally delegates to the MousePointer property of the active form, because there is no easy way to affect the global screen pointer under the .NET Framework.

The Screen6.MousePointer property is marked as obsolete, which causes both a migration warning to be issued and a compiler warning that is listed inside Visual Studio’s Error List. With dozens or hundreds of such warnings, you might easily want to suppress them.

Suppressing the migration warning is simple: you just issue a DisableMessage pragma for message 80F4. Suppressing the compilation warning requires that you transforms the reference to Screen6.MousePointer into a reference to Screen6.ActiveForm.MousePointer:

 	'## project:DisableMessage 80F4
	'## project:PostProcess "\bScreen6\.MousePointer\b", "Screen6.ActiveForm.MousePointer"

The pragmas used when converting to C# are slightly different:

 	'## project:DisableMessage 80F4
	'## project:PostProcess "\bScreen6\.MousePointer\b", "Screen6.ActiveForm.MousePointer"

If you are inside a form, you can transform the Screen6.MousePointer reference into Me.MousePointer, which delivers more concise code. A typical VB6 project contains more forms than modules or classes, therefore you’d better form having a project-level pragma that transforms into Me.MousePointer and then one pragma in each module or class that transforms into Screen6.ActiveForm.MousePointer:

 	' use these pragmas at the project-level...
	'## project:DisableMessage 80F4
	'## project:PostProcess "\bScreen6\.MousePointer\b", "Me.MousePointer"

	' ...but use this pragma in each module or class that references Screen.MousePointer
	'## PostProcess "\bScreen6\.MousePointer\b", "Screen6.ActiveForm.MousePointer"

This are the pragmas to be used when converting to C#

	' use these pragmas at the project-level...
	'## project:DisableMessage 80F8
	'## project:PostProcess "\bVB6Project\.Screen\.MousePointer\b", "this.MousePointer"

	' ...but use this pragma in each module or class that references Screen.MousePointer
	'## PostProcess "\bVB6Project.Screen.MousePointer\b", 
	"VB6Project.Screen.ActiveForm.MousePointer"

You can easily apply these pragmas to all the projects you plan to convert by saving it into the VBMigrationPartner.pragmas file.

A completely different – and more effective – approach can be used when the Screen.MousePointer property is used to display the “wait” cursor (the hourglass) during a lengthy operation and to later restore the mouse pointer to its default when the operation is completed. In this cases you really want to change the global cursor, not just the cursor of the current form. In .NET this is possible by means of the Application.UseWaitCursor property. The following two pragmas do the trick:

  '## project:PostProcess "\bScreen6\.MousePointer = 
      (11|13|VBRUN\.MousePointerConstants\.vbHourglass|
      VBRUN\.MousePointerConstants\.vbArrowHourglass)\b", "Application.UseWaitCursor = True" 

  '## project:PostProcess "\bScreen6\.MousePointer = (0|1|VBRUN\.MousePointerConstants\.vbDefault|
      VBRUN\.MousePointerConstants\.vbArrow)\b", "Application.UseWaitCursor = False"

Use these pragmas when converting to C#:

  '## project:PostProcess "\bVB6Project.Screen\.MousePointer = (11|13|VBRUN\
  .MousePointerConstants\.vbHourglass|VBRUN\.MousePointerConstants\.vbArrowHourglass)\b", 
  "Application.UseWaitCursor = true"
  '## project:PostProcess "\bVB6Project.Screen\.MousePointer = (0|1|VBRUN\
  .MousePointerConstants\.vbDefault|VBRUN\.MousePointerConstants\.vbArrow)\b", 
  "Application.UseWaitCursor = false"

 

Previous | Index | Next