首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

小弟我的程序应该如何改?怎么实现"打开对话框"那样,窗体以外部分不接受操作

2012-01-30 
我的程序应该怎么改?如何实现"打开对话框"那样,窗体以外部分不接受操作?我的本意是想自己画一form,实现

我的程序应该怎么改?如何实现"打开对话框"那样,窗体以外部分不接受操作?
我的本意是想自己画一form,实现 "打开对话框 "那样的功能,在弹出form后只响应form内的操作,以外部分不响应,但是为什么我用ClipCursor在父窗体可以实现鼠标限制在窗体里面,但是当作为子窗体或被调用窗体时,且窗体属性设置StartUPposition=2窗体中心时,就没办法实现所要的功能呢了?

或者哪位高手知道 "打开对话框 "如何实现的方法,给小弟提供一个思路,谢谢!

Private   Type   RECT
        left   As   Long
        top   As   Long
        right   As   Long
        bottom   As   Long
End   Type
Private   Type   POINT
        x   As   Long
        y   As   Long
End   Type
Private   Declare   Sub   ClipCursor   Lib   "user32 "   (lpRect   As   Any)
Private   Declare   Sub   GetClientRect   Lib   "user32 "   (ByVal   hWnd   As   Long,   lpRect   As   RECT)
Private   Declare   Sub   ClientToScreen   Lib   "user32 "   (ByVal   hWnd   As   Long,   lpPoint   As   POINT)
Private   Declare   Sub   OffsetRect   Lib   "user32 "   (lpRect   As   RECT,   ByVal   x   As   Long,   ByVal   y   As   Long)
Private   Sub   Form_Load()
        Command1.Caption   =   "Limit   Cursor   Movement "
        Command2.Caption   =   "Release   Limit "
End   Sub
Private   Sub   Command1_Click()
        'Limits   the   Cursor   movement   to   within   the   form.
        Dim   client   As   RECT
        Dim   upperleft   As   POINT
        'Get   information   about   our   wndow
        GetClientRect   Me.hWnd,   client
        upperleft.x   =   client.left
        upperleft.y   =   client.top
        ClientToScreen   Me.hWnd,   upperleft
        'move   our   rectangle
        OffsetRect   client,   upperleft.x,   upperleft.y
        'limit   the   cursor   movement
        ClipCursor   client
End   Sub
Private   Sub   Command2_Click()
        'Releases   the   cursor   limits
        ClipCursor   ByVal   0&
End   Sub
Private   Sub   Form_Unload(Cancel   As   Integer)
        'Releases   the   cursor   limits
        ClipCursor   ByVal   0&
End   Sub


[解决办法]
打开文件对话框不用自己画啊,用api就可以show出来了。
Private Declare Function GetOpenFileName Lib "comdlg32.dll " Alias "GetOpenFileNameA " (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long


lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type


Dim ofn As OPENFILENAME
Dim rtn As String

ofn.lStructSize = Len(ofn)
ofn.hwndOwner = me.hwnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "所有图片文件 " & chr(0) & "*.bmp;*.jpg;*.gif;*.ico " & chr(0)
ofn.lpstrFile = Space(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = App.Path
ofn.lpstrTitle = "打开文件 "
ofn.flags = 6148


rtn = GetOpenFileName(ofn)

文件名存在ofn.lpstrFile里
[解决办法]
你把你的msgbox窗体固定在最上面就行了啊
可以show me,1
或者用API

'窗口在最前显示
Declare Function CopyFile Lib "Kernel32 " Alias "CopyFileA " (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Private Declare Function SetWindowPos& Lib "user32 " (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal CX As Long, ByVal CY As Long, ByVal wFlags As Long)
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1


Public Function PutWindowOnTopS(pFrm As Form)
Dim lngWindowPosition As Long
lngWindowPosition = SetWindowPos(pFrm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Function
Public Function PutWindowOnTop(pFrm As Form)
' Dim lngWindowPosition As Long
' lngWindowPosition = SetWindowPos(pFrm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Function

Public Function RemoveOnTop(pFrm As Form)
Dim lngWindowPosition As Long
lngWindowPosition = SetWindowPos(pFrm.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Function

[解决办法]
form.show 1
就可以了
[解决办法]
form.show vbmodal

热点排行