Results 1 to 3 of 3

Thread: Can an ocx control be terminated by a call within?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    4

    Can an ocx control be terminated by a call within?

    Hello there!

    I've created a property's page for an ocx control. I've created a End button on the property's page. I would like to be able to click the end button to terminated the property's page. Is this possible? Is so, how can I do this?

    Thanks!

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    You can cheat & do this. Each property page in with control are contained within a general vb form when they are shown, you have to find the handle to this form, then find the cancel button & send a click event as though the user clicked on the button themself:
    VB Code:
    1. [size="1"]Option Explicit
    2.  
    3. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    4. (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    5.  
    6. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    7. (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
    8. ByVal lpsz2 As String) As Long
    9.  
    10. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
    11. (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    12. ByVal lParam As Long) As Long
    13.  
    14. Private Const BM_CLICK = &HF5
    15.  
    16.  
    17. Private Sub cmdExitPropPages_Click()
    18.     Dim lngPropPagesContainerHwnd As Long
    19.     Dim lngContainerCancelBtnHwnd As Long
    20.  
    21.     lngPropPagesContainerHwnd = FindWindow(vbNullString, "Property Pages")
    22.     lngContainerCancelBtnHwnd = FindWindowEx(lngPropPagesContainerHwnd, 0, _
    23.     vbNullString, "Cancel")
    24.     PostMessage lngContainerCancelBtnHwnd, BM_CLICK, ByVal CLng(0), ByVal CLng(0)
    25. End Sub[/size]

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    BTW, if you wanted to hit the okay button instead of the cancel, alter the following line:

    vbNullString, "Cancel")

    to

    vbNullString, "ok")

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width