C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-22-2004, 01:33 PM   #1
Registered User
 
Join Date: Jul 2002
Posts: 3
Question Modeless Dialogs in Multiple threads

I've recently been trying to implement a console like interface using modeless dialog boxes. The interface has a Create function which should create a new modeless dialog and allow it to function in more or less the same way as a console. The problem is that I don't want someone using the interface to have to implement a message loop; I'd like it self contained. So I tried creating a thread for the dialogs message loop. The problem with that was that the message loop and the window must be created in the same thread. To get around this, I changed things to create a thread each time Create is called and that thread creates a new dialog box and then goes into the message loop. I thought this should work but the message loop isn't working correctly and the dialogs dont respond to anything. Below is the code I use to create the threads and dialogs as well as how I check the messages. Currently, I am not doing anything in my dialogProc, so I have not included it. Additionally, I don't think it matters, but the implementation of this class is in a DLL.

First, the call to create the console
Code:
bool Console::CreateConsole(void)
{
   // hDialog and bConsole are class members		
   if(hDialog || bConsole)
      return false;

   if(!(hRichEdit = LoadLibrary("RichEd20.dll")))
      return false;

   if(!bConsole)
   {
      // Spawn a new thread
      hThread = _beginthread(ThreadLoop, 0, this);
      bConsole = true;
   }

   return true;
}
The thread code
Code:
void CDECL ThreadLoop(void* vp)
{
   MSG msg;
   msg.message = WM_NULL;

   Console* p = (Console*)vp;

   // dllhInst is stored globably when the DLL is loaded
   p->hDialog = CreateDialog(dllhInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc);

   while(msg.message != WM_QUIT)
   {
      if(GetMessage(&msg, 0, 0, 0))
      {
         if(p->hDialog == NULL || !IsDialogMessage(p->hDialog, &msg))
            {
               TranslateMessage(&msg);
               DispatchMessage(&msg);
            }
      }
   }
}
I'd appreciate any advice or suggestions you may have. I'm also open to any alternative implementations as long as they allow me to create multiple dialogs and they dont require additional code to be written by the user of the interface. Thanks for any help you can offer.
MrGrieves is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with multiple threads Cogman Windows Programming 2 07-05-2009 09:40 AM
Multiple Threads, One listener. PING Networking/Device Communication 3 03-27-2009 12:19 PM
Multiple Threads NuNn C Programming 3 03-14-2009 11:29 PM
unresponsive modeless dialogs reanimated Windows Programming 3 05-04-2006 03:53 PM
More Winsock threads: Proper way to recv() and send() to multiple clients Unregistered Windows Programming 2 03-05-2002 05:52 AM


All times are GMT -6. The time now is 02:21 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22