Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8577029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:04:16+00:00 2026-06-11T20:04:16+00:00

Can we have a message box with cancel button only ? If so ,

  • 0

Can we have a message box with cancel button only ? If so , any hints ? Is there a built in api method to get only messagebox with cancel button alone/

How to create custom modal dialog ? Any Links ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:04:17+00:00Added an answer on June 11, 2026 at 8:04 pm

    You can use a thread-local CBT hook via SetWindowsHookEx() to customize the MessageBox() dialog however you want.

    For instance, you can change the text of the “OK” button to say “Cancel” instead, eg:

    HHOOK hHook = NULL;
    
    LRESULT CALLBACK CBTHookProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
        if (nCode < 0)
            return CallNextHookEx(hHook, nCode, wParam, lParam);
    
        if (nCode == HCBT_ACTIVATE)
        {
            HWND hWnd = reinterpret_cast<HWND>(wParam);
            SetWindowText(GetDlgItem(hWnd, IDOK), TEXT("Cancel"));
            return 0;
        }
    
        return CallNextHookEx(hHook, nCode, wParam, lParam);
    }
    
    {
        ...
        hHook = SetWindowsHookEx(WH_CBT, reinterpret_cast<HOOKPROC>(&CBTHookProc), NULL, GetCurrentThreadId());
        int iResult = MessageBox(..., MB_OK);
        if (iResult == IDOK) iResult = IDCANCEL;
        UnhookWindowsHookEx(hHook);
        ...
    }
    

    Or you can hide the standard “OK” button and let the dialog still use its native “Cancel” button:

    HHOOK hHook = NULL;
    
    LRESULT CALLBACK CBTHookProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
        if (nCode < 0)
            return CallNextHookEx(hHook, nCode, wParam, lParam);
    
        if (nCode == HCBT_ACTIVATE)
        {
            HWND hWnd = reinterpret_cast<HWND>(wParam);
            ShowWindow(GetDlgItem(hWnd, IDOK), SW_HIDE);
            // optionally reposition the IDCANCEL child window as well....
            return 0;
        }
    
        return CallNextHookEx(hHook, nCode, wParam, lParam);
    }
    
    {
        ...
        hHook = SetWindowsHookEx(WH_CBT, reinterpret_cast<HOOKPROC>(&CBTHookProc), NULL, GetCurrentThreadId());
        int iResult = MessageBox(..., MB_OKCANCEL);
        UnhookWindowsHookEx(hHook);
        ...
    }
    

    Update: on Vista and later, you can (and should) use TaskDialog() or TaskDialogIndirect() instead of MessageBox(). Task dialogs are much more flexible, including the ability to let you specify which buttons are on the dialog, and even use custom buttons. So you can easily display a Cancel-only dialog without using any hooks at all, eg:

    TaskDialog(..., TDCBF_CANCEL_BUTTON, ..., &iResult);
    

    TASKDIALOGCONFIG TaskConfig = {0};
    TaskConfig.cbSize = sizeof(TaskConfig);
    TaskConfig.dwCommonButtons = TDCBF_CANCEL_BUTTON;
    ...
    TaskDialogIndirect(&TaskConfig, &iResult, ...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any easy and clean way to show a message box in Qt4
How can I make cancel button in javascript prompt box to do nothing like
In C++, a console application can have a message handler in its WinMain procedure,
I have a SOAP message (see below). Using Xpath, how can I extract the
I have the following error message: SQLSTATE[HY000] [2003] Can't connect to MySQL server on
I have an object of class Message, which can be written and subsequently updated.
I have created an inbox system. Signed in user can message other signed in
I have: void add_all_msgs(std::deque<Message>::iterator &iter); How can I make that function generic, so it
I have a question about joptionpane. Using JOptionPane.showMessageDialog(...), we can create a message dialog.
I have a MainForm. I can close it by using a close button (upper

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.