?
Solved

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

Posted on 2004-11-23
11
Medium Priority
?
1,197 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:TravisMS
  • 5
  • 5
11 Comments
 
LVL 1

Accepted Solution

by:
connah0047 earned 500 total points
ID: 12655632
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
 

Author Comment

by:TravisMS
ID: 12657718
That worked great - thanks!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:connah0047
ID: 12657754
No problem, thanks for the points. Good luck on your project.
0
 

Author Comment

by:TravisMS
ID: 12658174
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
 
LVL 1

Expert Comment

by:connah0047
ID: 12658337
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
 

Author Comment

by:TravisMS
ID: 12658447
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
 
LVL 1

Expert Comment

by:connah0047
ID: 12658460
Are you trying to center the form before or after you set it unmovable?
0
 

Author Comment

by:TravisMS
ID: 12658548
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
 
LVL 1

Expert Comment

by:connah0047
ID: 12658592
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
 

Author Comment

by:TravisMS
ID: 12659052
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question