Compile error: Function of interface marked as restricted...

I'm trying to set the moveable property of a form when it opens, depending on a system option.  My code is as follows:

   If fpConfig.TouchScreen = True Then
      Me.Moveable = False
   Else
      Me.Moveable = True
   End If

When I try to compile this code, I'm getting the error "Compile Error:  Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic" on the first reference to Moveable.

I'm able to set the Moveable property at design time and it works properly, but at compile-time, I'm getting the problem.

Any ideas?
TravisMSAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

connah0047Commented:
Hi. You can't do it that way. You have to subclass it. Try this:

Create a new project and place a check box controlon the form and leave it named "Check1". Add this code to the form:

Private Sub Check1_Click()
    bAllowMove = Check1.Value
End Sub

Private Sub Form_Load()
    Check1.Move 100, 100, 2000, 100
    Check1.Caption = "Allow Move"
    Check1.Value = vbChecked
    lppwp = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub



Then create a new standard module and add this code to it. Then run it and try it out!

Option Explicit

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Const WM_WINDOWPOSCHANGING = &H46
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1


Public Const GWL_WNDPROC = -4
Public bAllowMove As Boolean
Public lppwp As Long 'pointer to the previous window procedure

Private Type WINDOWPOS
    hwnd As Long
    hWndInsertAfter As Long
    x As Long
    y As Long
    cx As Long
    cy As Long
    flags As Long
End Type

Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If uMsg = WM_WINDOWPOSCHANGING Then
        If Not bAllowMove Then
            Dim wp As WINDOWPOS
            CopyMemory wp, ByVal lParam, Len(wp)
            wp.flags = wp.flags Or SWP_NOMOVE 'Or SWP_NOSIZE
            CopyMemory ByVal lParam, wp, Len(wp)
        End If
    End If
    WndProc = CallWindowProc(lppwp, hwnd, uMsg, wParam, lParam)
End Function



Hope this helps!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TravisMSAuthor Commented:
That worked great - thanks!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

connah0047Commented:
No problem, thanks for the points. Good luck on your project.
0
TravisMSAuthor Commented:
Thanks.  Actually, I do have a couple additional questions regarding the code you posted.  When my form open in 'non-moveable' mode, I'd like to center it on the screen rather than putting it in the top left (which actually leaves some space on the left side and cuts off the title bar).  Also, the form remains behind the taskbar, whereas if I set the Moveable property to True (at design time), the form remains in front of the taskbar, which is what I'd like to happen.  

This app is one that can be run on a desktop pc or a touchscreen tablet.  If run on a tablet pc, I want to user to be able to do as little as possible (besides using this app) while they're logged in (no taskbar, no start menu, nothing, unless they exit the app).

Any pointers?

Man, it would be so much nicer if I could just say Moveable = True!! :)
0
connah0047Commented:
Well, as for centering the form on the screen, you can set the StartupPosition property to CenterScreen at design time, or, if you need to center it at run time, you can do this:

Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2

Let me get back to you in a minute about the form on top of taskbar thing.
0
TravisMSAuthor Commented:
Actually, that doesn't work for centering.  Something with the routines you posted before is setting it in one position and that's where it stays.  Didn't know if there was a way to set it to be centered there?
0
connah0047Commented:
Are you trying to center the form before or after you set it unmovable?
0
TravisMSAuthor Commented:
Whenever I need to so that it will be centered.  Before adding your code, the form has always been centered.  After adding your code, if setting the form moveable, it remains centered.  If setting it unmoveable, it is placed in the top left corner of the screen (although not exactly at 0,0 as I mentioned before).
0
connah0047Commented:
So when you set it unmoveable, it moves to the top left of the screen? Hmm, I am unable to reproduce that. When I set it and unset it, the form remains in the same place. Can you put a stop in the code where you set it unmoveable then step through it to see what line of code is moving it to the top left? Sorry if I'm missing your point!
0
TravisMSAuthor Commented:
Yeah.  Unfortunately, I'm not able to find the line that's causing it when stepping through.  Something is getting set when SetWindowLong is being called to make the form unmoveable that makes the form open in the top left.  I can't actually see the form move from center to the top left - that's just where it opens to.  

hmmm....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.