2016-01-07 41 views
0

我最近购买了34英寸宽屏幕显示器。我正在使用戴尔显示器管理器来设置不同的窗口,使我能够整齐地打开多个Word文档等。访问窗口调整大小

当我使用Access时,我可以将应用程序窗口正确对接至屏幕的1/2或1/3。但是,当我打开表单(因为它可能是一个孩子?)时,它不会保留在父窗口或Dell显示管理器的范围内。

所以,我的想法是调整任何弹出窗体的大小相同的左,顶部,宽度和高度的父访问窗口的尺寸。

然而,尽管尝试了几种不同的技术,我还没有能够实现这一点。

有人有什么想法吗?

谢谢!

编辑:谢谢Jashin。我已经实现了你的代码,但是表单仍然没有按照我的预期显示出来。这是我使用的代码:

SetWindowPos hWndChild, hWndParent, mainRECT.wdw_left, mainRECT.wdw_top, mainRECT.wdw_right, mainRECT.wdw_bottom, &H4

加载窗体时的高度和左稍微偏离,但形式是真的瘦了。我试图从mainRECT.wdw_right获取宽度 - mainRECT.wdw_left,但它有相同的结果。

最终编辑:了解了@Jashin提供的一些代码。下面是最终代码:

Dim hWndParent As LongPtr 
Dim hWndChild As LongPtr 
Dim mainRECT As RECT  

hWndParent = Application.hWndAccessApp 

hWndChild = Me.hwnd 

GetWindowRect hWndParent, mainRECT 

SetParent hWndChild, hWndParent 

SetWindowPos hWndChild, 0, mainRECT.wdw_left, mainRECT.wdw_top, mainRECT.wdw_right - mainRECT.wdw_left, mainRECT.wdw_bottom, &H4 

Me.SetFocus 

DoCmd.MoveSize 0, 0` 

回答

2

我不熟悉戴尔显示管理器但是,如果我理解您的问题,那么您正在寻找一些步骤强制在屏幕上的任何位置放置弹出窗体。由于@ThunderFrame建议您不能使用Access API执行此操作,但可以使用Windows API执行此操作。

创建一个模块,并声明如下功能

Public Type RECT 
    wdw_left As Long 
    wdw_top As Long 
    wdw_right As Long 
    wdw_bottom As Long 
End Type 

Public Declare PtrSafe Function SetParent Lib "user32" _ 
           (ByVal hWndChild As LongPtr, _ 
           ByVal hWndParent As LongPtr) As Long 

Public Declare PtrSafe Function SetWindowPos Lib "user32" _ 
           (ByVal hwnd As LongPtr, _ 
           ByVal hWndInsertAfter As LongPtr, _ 
           ByVal x As Long, _ 
           ByVal y As Long, _ 
           ByVal cx As Long, _ 
           ByVal cy As Long, _ 
           ByVal wFlags As Long) As Long 

Public Declare PtrSafe Function GetWindowRect Lib "user32" _ 
           (ByVal hwnd As LongPtr, _ 
           lpRect As RECT) As Long 

注意我用的PTRSAFELongPtr关键字,因为我是一个64位系统上工作;如果您在32位系统上工作,则可以删除PtrSafe keywork并将Long替换为LongPtr。

然后在弹出窗体的Form_Open()事件中写下面的代码。

Dim hWndParent As LongPtr ' handle of your parent form (access window or 
          ' any other form you want to set as parent 
Dim hWndChild As LongPtr ' handle of the child pop-up form 
Dim mainRECT As RECT  ' coordinates of the parent form 

hWndParent = Form_frm_home.hwnd ' or hWndAccessApp to get the handle of 
           ' the main Access Window 
hWndChild = Form_frm_child.hwnd 

GetWindowRect hWndParent, mainRECT ' this gets the coordinates of the 
            ' parent window 

SetParent hWndChild, hWndParent ' set the pop-up form as child of the 
            ' parent form 

SetWindowPos hWndChild, hWndParent, left, top, width, heigth, &H4 

功能SetWindowPos可以让你在屏幕上放置弹出窗口形式的任何地方。您可以从RECT结构使用下面的代码

mainRECT.wdw_left 
mainRECT.wdw_top 
mainRECT.wdw_right 
mainRECT.wdw_bottom 

功能的setparent允许您创建一个子窗体访问父窗体的坐标,所以它会留下永远的父窗体的边界和意志之间随主窗体(或访问窗口)一起移动。

希望这会有所帮助!

0

你不能做到这一点直接使用访问API,但你可以使用一些Windows API函数来实现你之后的结果。 你需要执行以下

  1. 获取访问应用程序窗口的RECT结构(使用隐藏的hWnd属性)和Windows API函数GetWindowRect
  2. 建立一个新的RECT结构,你想然后使用SetWindowPos Windows API函数