CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Guest

    Getting a handle to the OK button

    On a standard OK MessageBox, how would you get the handle to the OK button? I need to be able to press the OK button programmaitcally (which I can do with dialogs I've made) but I need to be able to get the handle of a MessageBox button. How do I do this?

    Regards,

    -Tim Manchester
    [email protected]


  2. #2
    Join Date
    May 1999
    Posts
    12

    Re: Getting a handle to the OK button

    Hi Tim,
    I am not very clear about exactly what you want. If you could kindly be more clear I could try my level best to solve the problem
    Thanks


  3. #3
    Join Date
    Apr 1999
    Posts
    5

    Re: Getting a handle to the OK button

    I am not quite sure what you want but here are a few attempts at solving your problem.

    1. Just call your OnOK() fuction if that is where you want the code to go else
    2. if you need all the CButton member functions then just add a variable to you button.

    If this is not what you want then please try and explain again so I know exactly what you need to do.



  4. #4
    Join Date
    May 1999
    Location
    Toronto, Ontario, Canada
    Posts
    155

    Re: Getting a handle to the OK button

    Well, OK buttons always have an ID of 'IDOK', at least the standard dialogs are.
    So, if you have the handle to the window, you can call GetDlgItem(hWnd, IDOK) and it will return the HWND of the OK button.


    -Safai

  5. #5
    Join Date
    May 1999
    Posts
    4

    Re: Getting a handle to the OK button

    Try this:

    CDialog* pDlg = (CDialog*)CWnd::FindWindow("32770(Dialog)","Put the Dialog Title Text Here");
    CButton* pButOK = (CButton*)pDlg->GetDlgItem(IDOK);
    HWND hWnd = pButOK->m_hWnd;



  6. #6
    Join Date
    May 1999
    Posts
    53

    Re: Getting a handle to the OK button


    pWnd->GetDlgItem(IDOK);
    pWnd->SendMessage(WM_LBUTTONDOWN);
    Sleep(100);
    pWnd->SendMessage(WM_LBUTTONUP);



    That should work, of course 'pWnd' should point to the message box.
    I've made a program called dismiss (http://ftp://shellreef.dynip.com/dismiss.zip) which can
    automatically dismiss dialog boxes and more. You can download it from the address above
    (it's on my comp and I go offline often so get it as soon as possible if you want it..)



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

Featured