• Hide và Unhide nút Close của Access
  • Hide và Unhide nút Close của Access

    Xuân Thanh > 02-07-12, 04:35 PM

    1/ Hide

    Mã:
    Private Const GWL_EXSTYLE = (-20)
        Private Const GWL_STYLE = (-16)
        Private Const WS_MAXIMIZEBOX = &H10000
        Private Const WS_MINIMIZEBOX = &H20000
        Private Const WS_SYSMENU = &H80000
        Private Const HWND_TOP = 0
        Private Const SWP_NOMOVE = &H2
        Private Const SWP_NOSIZE = &H1
        Private Const SWP_FRAMECHANGED = &H20
        Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
        Private Declare Function SetWindowLong Lib "user32" _
        Alias "SetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex As Long, ByVal dwNewLong As Long) _
        As Long
        Private Declare Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex 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) As Long

        Sub HideAccessCloseButton()
            Dim lngStyle As Long
            lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
            lngStyle = lngStyle And Not WS_SYSMENU
            Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
            Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME)
        End Sub


    2/ Unhide

    Mã:
    Private Const GWL_EXSTYLE = (-20)
        Private Const GWL_STYLE = (-16)
        Private Const WS_MAXIMIZEBOX = &H10000
        Private Const WS_MINIMIZEBOX = &H20000
        Private Const WS_SYSMENU = &H80000
        Private Const HWND_TOP = 0
        Private Const SWP_NOMOVE = &H2
        Private Const SWP_NOSIZE = &H1
        Private Const SWP_FRAMECHANGED = &H20
        Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
        Private Declare Function SetWindowLong Lib "user32" _
        Alias "SetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex As Long, ByVal dwNewLong As Long) _
        As Long
        Private Declare Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex 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) As Long

        Sub UnHideAccessCloseButton()
            Dim lngStyle As Long
            lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
            lngStyle = lngStyle Or WS_SYSMENU
            Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
            Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME)
        End Sub

    Lưu ý là nút Close của Access nha các bạn
  • RE: Hide và Unhide nút Close của Access

    cannguyen > 02-07-12, 04:41 PM

    (02-07-12, 04:35 PM)Xuân Thanh Đã viết: 1/ Hide

    Mã:
    Private Const GWL_EXSTYLE = (-20)
        Private Const GWL_STYLE = (-16)
        Private Const WS_MAXIMIZEBOX = &H10000
        Private Const WS_MINIMIZEBOX = &H20000
        Private Const WS_SYSMENU = &H80000
        Private Const HWND_TOP = 0
        Private Const SWP_NOMOVE = &H2
        Private Const SWP_NOSIZE = &H1
        Private Const SWP_FRAMECHANGED = &H20
        Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
        Private Declare Function SetWindowLong Lib "user32" _
        Alias "SetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex As Long, ByVal dwNewLong As Long) _
        As Long
        Private Declare Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex 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) As Long

        Sub HideAccessCloseButton()
            Dim lngStyle As Long
            lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
            lngStyle = lngStyle And Not WS_SYSMENU
            Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
            Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME)
        End Sub


    2/ Unhide

    Mã:
    Private Const GWL_EXSTYLE = (-20)
        Private Const GWL_STYLE = (-16)
        Private Const WS_MAXIMIZEBOX = &H10000
        Private Const WS_MINIMIZEBOX = &H20000
        Private Const WS_SYSMENU = &H80000
        Private Const HWND_TOP = 0
        Private Const SWP_NOMOVE = &H2
        Private Const SWP_NOSIZE = &H1
        Private Const SWP_FRAMECHANGED = &H20
        Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
        Private Declare Function SetWindowLong Lib "user32" _
        Alias "SetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex As Long, ByVal dwNewLong As Long) _
        As Long
        Private Declare Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex 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) As Long

        Sub UnHideAccessCloseButton()
            Dim lngStyle As Long
            lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
            lngStyle = lngStyle Or WS_SYSMENU
            Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
            Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME)
        End Sub

    Lưu ý là nút Close của Access nha các bạn

    Gán vào sự kiện nào vậy Xuân Thanh?
  • RE: Hide và Unhide nút Close của Access

    ledangvan > 03-07-12, 03:27 PM

    (02-07-12, 04:35 PM)Xuân Thanh Đã viết: 1/ Hide

    Mã:
    Private Const GWL_EXSTYLE = (-20)
        Private Const GWL_STYLE = (-16)
        Private Const WS_MAXIMIZEBOX = &H10000
        Private Const WS_MINIMIZEBOX = &H20000
        Private Const WS_SYSMENU = &H80000
        Private Const HWND_TOP = 0
        Private Const SWP_NOMOVE = &H2
        Private Const SWP_NOSIZE = &H1
        Private Const SWP_FRAMECHANGED = &H20
        Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
        Private Declare Function SetWindowLong Lib "user32" _
        Alias "SetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex As Long, ByVal dwNewLong As Long) _
        As Long
        Private Declare Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex 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) As Long

        Sub HideAccessCloseButton()
            Dim lngStyle As Long
            lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
            lngStyle = lngStyle And Not WS_SYSMENU
            Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
            Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME)
        End Sub


    2/ Unhide

    Mã:
    Private Const GWL_EXSTYLE = (-20)
        Private Const GWL_STYLE = (-16)
        Private Const WS_MAXIMIZEBOX = &H10000
        Private Const WS_MINIMIZEBOX = &H20000
        Private Const WS_SYSMENU = &H80000
        Private Const HWND_TOP = 0
        Private Const SWP_NOMOVE = &H2
        Private Const SWP_NOSIZE = &H1
        Private Const SWP_FRAMECHANGED = &H20
        Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
        Private Declare Function SetWindowLong Lib "user32" _
        Alias "SetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex As Long, ByVal dwNewLong As Long) _
        As Long
        Private Declare Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" (ByVal hwnd As Long, _
        ByVal nIndex 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) As Long

        Sub UnHideAccessCloseButton()
            Dim lngStyle As Long
            lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
            lngStyle = lngStyle Or WS_SYSMENU
            Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
            Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME)
        End Sub

    Lưu ý là nút Close của Access nha các bạn

    Bác Xuân Thanh ơi cái này là nó làm ẩn Menu của ACC (Gồm cả nút Min, Max, và nút Close) Bác có cách nào chỉ ẩn một nút Close không vì người dùng nhiều lúc muốn thu nhỏ để sử dụng chương trình khác ?
  • RE: Hide và Unhide nút Close của Access

    Xuân Thanh > 03-07-12, 04:09 PM

    (03-07-12, 03:27 PM)ledangvan Đã viết: Bác Xuân Thanh ơi cái này là nó làm ẩn Menu của ACC (Gồm cả nút Min, Max, và nút Close) Bác có cách nào chỉ ẩn một nút Close không vì người dùng nhiều lúc muốn thu nhỏ để sử dụng chương trình khác ?

    Mấu chốy của nó nằm ở hàm API này

    Mã:
    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) As Long

    · hWnd
    Handle của cửa sổ cần thực hiện.

    · hWndInsertAfter
    Gồm 1 trong các giá trị sau :
    HWND_BOTTOM : Đưa cửa sổ xuống vị trí cuối cùng
    HWND_NOTOPMOST : Đưa cửa sổ lên trên tất cả các cửa sổ notopmost nhưng bên dưới topmost.
    HWND_TOP : Đưa cửa sổ lên vị trí trên cùng (top).
    HWND_TOPMOST : Đưa cửa sổ lên vị trí cao nhất (topmost), ngay cả khi nó không được kích hoạt (deactived).

    · X
    Vị trí mới bên trái (left).

    · Y
    Vị trí mới phía trên (top).

    · cx
    Độ rộng mới của cửa sổ (width), đơn vị là pixel.

    · cy
    Độ cao mới của cửa sổ (height), đơn vị là pixel.

    · uFlags
    Cờ định vị trí và kích thước. Có thể sử dụng kết hợp các tham số :

    SWP_NOACTIVATE : không kích hoạt cửa sổ
    Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
    SWP_NOMOVE : giữ nguyên vị trí hiện tại
    Retains the current position (ignores the X and Y parameters).
    SWP_NOSIZE : giữ nguyên kích thước hiện tại
    Retains the current size (ignores the cx and cy parameters).
    SWP_SHOWWINDOW : hiển thị cửa sổ
    Displays the window.

    Tham khảo thêm cái này để biết về API
    http://www.allAPI.net

    Thân mến
  • RE: Hide và Unhide nút Close của Access

    ledangvan > 03-07-12, 04:34 PM

    (03-07-12, 04:09 PM)Xuân Thanh Đã viết:
    (03-07-12, 03:27 PM)ledangvan Đã viết: Bác Xuân Thanh ơi cái này là nó làm ẩn Menu của ACC (Gồm cả nút Min, Max, và nút Close) Bác có cách nào chỉ ẩn một nút Close không vì người dùng nhiều lúc muốn thu nhỏ để sử dụng chương trình khác ?

    Mấu chốy của nó nằm ở hàm API này

    Mã:
    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) As Long

    · hWnd
    Handle của cửa sổ cần thực hiện.

    · hWndInsertAfter
    Gồm 1 trong các giá trị sau :
    HWND_BOTTOM : Đưa cửa sổ xuống vị trí cuối cùng
    HWND_NOTOPMOST : Đưa cửa sổ lên trên tất cả các cửa sổ notopmost nhưng bên dưới topmost.
    HWND_TOP : Đưa cửa sổ lên vị trí trên cùng (top).
    HWND_TOPMOST : Đưa cửa sổ lên vị trí cao nhất (topmost), ngay cả khi nó không được kích hoạt (deactived).

    · X
    Vị trí mới bên trái (left).

    · Y
    Vị trí mới phía trên (top).

    · cx
    Độ rộng mới của cửa sổ (width), đơn vị là pixel.

    · cy
    Độ cao mới của cửa sổ (height), đơn vị là pixel.

    · uFlags
    Cờ định vị trí và kích thước. Có thể sử dụng kết hợp các tham số :

    SWP_NOACTIVATE : không kích hoạt cửa sổ
    Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
    SWP_NOMOVE : giữ nguyên vị trí hiện tại
    Retains the current position (ignores the X and Y parameters).
    SWP_NOSIZE : giữ nguyên kích thước hiện tại
    Retains the current size (ignores the cx and cy parameters).
    SWP_SHOWWINDOW : hiển thị cửa sổ
    Displays the window.

    Tham khảo thêm cái này để biết về API
    http://www.allAPI.net

    Thân mến

    Em hỏi là bác có cách nào làm ẩn nút close chứ có hỏi ý nghĩa và học hàm Api đâu bác, vì tiêu đề của bài viết của bài viết của bác là ẩn và hiện nút Close trong Acc mà