2016-01-07 86 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函數