Hi,
Can I create a modeless message box?
Please help.
Regards,
Pabitra
Printable View
Hi,
Can I create a modeless message box?
Please help.
Regards,
Pabitra
Hi,
You can create modeless dlg box & then create a list box inside it. When u want to display a msg, you can do an InsertString() (remove any existing strings) to this listbox, and then bring that window to top & set focus to it. However, u cannot get any Yes/No/Cancel sort of user input. This is output only.
In fact, I use this technique to debug my applications. My debug messages go to this modeless dlg box, instead of OutputDebugString(). I maintain the last 25 messages in the listbox.
You can have a sizing border on the modeless dlg box, so that u can size it acc to your specs.
regards,
anant
If ananta's response was not working for you,let me know i have a solution for a modless dialogue as well.or search for my posts and i have replied to the similar quetsions in the past.
Good Luck
what about this implementation:
#pragma once
/********************************************************************
created: 2008/11/23
created: 23:11:2008 11:16
filename: ModelessMessageBox.h
file path:
file base: ModelessMessageBox
file ext: h
author: Shay
purpose: Creating a message box not on the stack, without
Stopping the code flow.
Using thread and message box data on the heap.
usage: ModelessMessageBox(NULL, sEvent, L"Debug events form menu", MB_OK);
*********************************************************************/
class _ModelessMessageBox
{
protected:
struct MessageData
{
HWND hWnd;
CString lpText;
CString lpCaption;
UINT uType;
};
static DWORD WINAPI DoMessageBoxThreadProc(LPVOID lpParameter)
{
if(lpParameter == NULL)
return 1L;
MessageData * pData= static_cast<MessageData *>(lpParameter);
if (NULL == pData )
return 1L;
//else
::MessageBox(pData->hWnd, pData->lpCaption, pData->lpText, pData->uType);
delete pData;
return 0L;
}
public:
static void Show( HWND hWnd = NULL,
LPCTSTR lpText = L"",
LPCTSTR lpCaption = L"",
UINT uType = MB_OK
)
{
MessageData * pMessageData = new MessageData;
pMessageData->hWnd= hWnd;
pMessageData->lpText = lpText;
pMessageData->lpCaption = lpCaption;
pMessageData->uType = uType;
LPDWORD threadId = 0;
CreateThread(NULL, 0, DoMessageBoxThreadProc, pMessageData/*(LPVOID)&m_messageData*/, 0, threadId);
}
};
void ModelessMessageBox(HWND hWnd = NULL,
LPCTSTR lpText = L"",
LPCTSTR lpCaption = L"",
UINT uType = MB_OK
);
in the cpp file
====================
#include "ModelessMessageBox.h"
void ModelessMessageBox( HWND hWnd /*= NULL*/, LPCTSTR lpText /*= L""*/, LPCTSTR lpCaption /*= L""*/, UINT uType /*= MB_OK */ )
{
_ModelessMessageBox::Show(hWnd /*= NULL*/,
lpText/* = L""*/,
lpCaption /*= L""*/,
uType/* = MB_OK*/
);
}