Problem with CustomMessageBOX MFC

Posted on 2012-09-11
Last Modified: 2015-08-17
My task is to convert the background color of AfxMessageBox in MFC ,I have found lots of codiing in internet,all mentioned how to call customessageBox with button but i want to call
it anywhere in my proyect with a condition of if() else() as like normally we call AfxMessagebox,

Here by i posting my coding and funtion please tell me where how to call the following funtion in my proyect:

MsgBoxEx(hWnd, "Message test" , "title",  MB_YESNOCANCEL | MB_ICONINFORMATION);


HHOOK hMsgBoxHook;
LRESULT CALLBACK MsgBoxProc(int nCode, WPARAM wParam, LPARAM lParam)
TCHAR ach[140];
HWND hwnd;
if(nCode < 0)
return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
// Get handle to the message box!
hwnd = (HWND)wParam;
//Set the window title
SetWindowText(hwnd, _T("Activator"));
//Get IDYES button handle
YES = GetDlgItem(hwnd, IDYES);
SetWindowText(YES, _T("Full License"));
//Get IDNO button handle
NO = GetDlgItem(hwnd, IDNO);
               //Set Button position, width and height
MoveWindow(NO, 185, 60, 100, 23, TRUE);
SetWindowText(NO, _T("Cancel"));
//Get IDCANCEL button handle
CANCEL = GetDlgItem(hwnd, IDCANCEL);
                 //Set Button position, width and height
MoveWindow(CANCEL, 290, 60, 100, 23, TRUE);
SetWindowText(CANCEL, _T("Cancel"));
return 0;
return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
int MsgBoxEx(HWND hwnd, TCHAR *szText, TCHAR *szCaption, UINT uType)
int retval;
// Install a window hook, so we can intercept the message-box
// creation, and customize it
hMsgBoxHook = SetWindowsHookEx(
// Display a standard message box
retval = MessageBox(hwnd, szText, szCaption, uType);
// remove the window hook
return retval;

please help me its urgently
Question by:jit_sco
    1 Comment
    LVL 43

    Accepted Solution

    AfxMessagebox is basically a normal windows message box in disguise, it is just wrapped with some other code specific to MFC.
    Changing the colour / customising it - forget it, as I said it is a normal windows message box.

    If you want to have specific control such as changing background then use one of the custom ones you have found (or code your own).

    ps.  Why did you ask this question in topic areas unrelated to the question - don't bother answering.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now