powered by simpleCommunicator - 2.0.52     © 2025 Programmizd 02
Форумы / Microsoft Access [игнор отключен] [закрыт для гостей] / Узнать положение и размер окна запроса (QueryDef)
8 сообщений из 8, страница 1 из 1
Узнать положение и размер окна запроса (QueryDef)
    #39698405
Фотография 4d_monster
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Есть ли простой(без WinAPI) способ узнать положение и размер окна запроса (QueryDef) ?

IMHO, Mon$te®
...
Рейтинг: 0 / 0
Узнать положение и размер окна запроса (QueryDef)
    #39698452
Predeclared
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Смотря относительно чего, и в каких единицах.
Код: vbnet
1.
2.
3.
    With Screen.ActiveDatasheet
        Debug.Print .WindowHeight, .WindowLeft, .WindowWidth, .WindowTop
    End With
...
Рейтинг: 0 / 0
Узнать положение и размер окна запроса (QueryDef)
    #39698464
Фотография 4d_monster
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Спасибо, то, что надо.
PredeclaredСмотря относительно чего, и в каких единицах.Мне для .Move у универсальной формы "запросо-носителя"
...
Рейтинг: 0 / 0
Узнать положение и размер окна запроса (QueryDef)
    #39698853
Фотография 4d_monster
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
К сожалению, оказалось, что Screen.ActiveDatasheet может работать только когда запрос открыт в режиме просмотра, а в режиме конструктора он его не видит. Не все запросы получается открывать в режиме просмотра, поэтому пришлось комбинировать Гетса и WinApi и получать в пикселях:

Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
Option Compare Database
Option Explicit

Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, _
    ByVal lParam As Long) As Long

Private Declare Function EnumChildWindows _
    Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Private Declare Function GetWindowText _
    Lib "user32" _
    Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Declare Function GetWindowRect _
    Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long

Private Declare Function FindWindowEx _
    Lib "user32" _
    Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Private Declare Function FindWindow _
    Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function GetParent _
    Lib "user32" (ByVal hWnd As Long) As Long

' Store rectangle coordinates.
Public Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

' Windows 95/98/NT4/2000 puts a 2-pixel
' border around the MDI client area, which
' doesn't get taken into account automatically.
' If you're using NT 3.51, you're on your own.
Private Const adhcBorderWidthX = 2
Private Const adhcBorderWidthY = 2

Private captionToFind As String ' not safe
Private currentCaption As String
Private foundHWND As Long

Public Function getChildByCaption(caption As String, Optional inApp As Application) As Long
    If inApp Is Nothing Then
        Set inApp = Application
    End If
    
    captionToFind = caption
    currentCaption = String(100, " ")
    foundHWND = 0
    
    EnumChildWindows inApp.hWndAccessApp, AddressOf EnumWindows_Seek, 1
    
    getChildByCaption = foundHWND
End Function

Private Function EnumWindows_Seek(ByVal hWnd As Long, ByVal lParam As Long) As Long
    Dim l As Long
    l = GetWindowText(hWnd, currentCaption, 100)

    If captionToFind <> Left(currentCaption, l) Then
        ' Return 1 to continue enumeration
        EnumWindows_Seek = 1
    Else
        foundHWND = hWnd
        EnumWindows_Seek = 0
        ' Return 0 to stop enumeration
    End If

End Function

Public Function GetRECT(hWnd As Long) As RECT

    ' modified : return RECT instead of write into byRef COORDS
    ' Fill in rct with the coordinates of the client area.
    ' Fill in rctWindow with coordinates of the window.

    ' From Access 2002 Desktop Developer's Handbook
    ' by Litwin, Getz, and Gunderloy (Sybex)
    ' Copyright 2001.  All rights reserved.
    
    On Error GoTo HandleErrors
    Dim hWndParent As Long
    Dim rctParent As RECT
    Dim rct As RECT

    ' Find the position of the window in question, in
    ' relation to its parent window (the Access desktop,
    ' the MDIClient window).
    hWndParent = GetParent(hWnd)

   ' Get the coordinates of the current window and its parent.
    Call GetWindowRect(hWnd, rct)

    ' Catch the case where the form is Popup (that is,
    ' its parent is NOT the Access main window.)  In that
    ' case, don't subtract off the coordinates of the
    ' Access MDIClient window.
    Select Case 1 'ReferenceType
        Case 0 'rtPopup
            ' No special calculations necessary.
        Case 1 'rtNormal
            ' Get the MDI Client window's coordinates.
            Call GetWindowRect(hWndParent, rctParent)
    
            ' Subtract off the left and top parent coordinates,
            ' since you need coordinates relative to the parent
            ' for the MoveWindow function call.
            ' Also, subtract off the small border of the
            ' MDI Client window that no one will admit to.
            With rct
                .Left = .Left - rctParent.Left - adhcBorderWidthX
                .Top = .Top - rctParent.Top - adhcBorderWidthY
                .Right = .Right - rctParent.Left - adhcBorderWidthX
                .Bottom = .Bottom - rctParent.Top - adhcBorderWidthY
            End With
    End Select
    
    GetRECT = rct

ExitHere:
    Exit Function

HandleErrors:
    Select Case Err.Number
        Case Else
            Debug.Print "FormInfo.GetCoords", Err.Number, Err.Description
    End Select
    Resume ExitHere
End Function

использование :
Код: vbnet
1.
2.
3.
4.
5.
6.
    Dim rectOfQuery As RECT
    Dim hWndOfQuery As Long

    Application.DoCmd.OpenQuery QueryName, acViewDesign
    hWndOfQuery = getChildByCaption(QueryName, Application)
    rectOfQuery = GetRECT(hWndOfQuery)
...
Рейтинг: 0 / 0
Узнать положение и размер окна запроса (QueryDef)
    #39698933
Фотография Панург
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
4d_monster, а для чего все эти изыскания? Для чего размеры? Зачем двигать? Не проще ли использовать форму?
...
Рейтинг: 0 / 0
Узнать положение и размер окна запроса (QueryDef)
    #39698969
Фотография 4d_monster
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Что бы заменить в MDB базе все DoCmd.OpenQuery на открытие универсальной формы и присвоение ей ADODB.Recordsetа от UDF, SP, VIEW или PassThrough запроса.
...
Рейтинг: 0 / 0
Узнать положение и размер окна запроса (QueryDef)
    #39698979
Фотография Панург
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
4d_monsterЧто бы заменить в MDB базе все DoCmd.OpenQuery на открытие универсальной формы и присвоение ей ADODB.Recordsetа от UDF, SP, VIEW или PassThrough запроса.Для этого нужно знать положение/размеры окна в дизайн режиме? Можно не отвечать, но просто любопытно...
...
Рейтинг: 0 / 0
Узнать положение и размер окна запроса (QueryDef)
    #39698981
Фотография 4d_monster
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Тут всё просто - положение окна в дизайн режиме повторяет его положение в обычном. В режиме дизайна можно открыть любой запрос, а в обычном режиме - нет.
...
Рейтинг: 0 / 0
8 сообщений из 8, страница 1 из 1
Форумы / Microsoft Access [игнор отключен] [закрыт для гостей] / Узнать положение и размер окна запроса (QueryDef)
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]