/* Autor: Leandro Bernsmuller
Implementa uma caixa de dialogo que serah usada para: exibir mensagens
recebidas do tutor ou colega e para entrar dados que serao 
transmitidos para o colega. Usado principalmente pelos
modulos de comunicao entre sistemas. */



#include <windows.h>
#include <windowsx.h>
#include "..\princip\defs.h"
#define IDIRECTPLAY2_OR_GREATER
#include <dplay.h>
     
#include "..\comunic\dplayinf.h"                          
#include "..\comunic\dialog.h"
#include "..\comunic\dpcomu.h"

#include "dlgconve.h"



HWND hCHATWND = NULL; // referencia estah janela



/* Recebe as mensagens do Windows
**********************************************************/
BOOL CALLBACK ChatWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   DWORD dwTextLen;

   switch(uMsg) {

      case WM_INITDIALOG:

         // store global window
         hCHATWND = hWnd;
         break;

      case WM_DESTROY:
         hCHATWND = NULL;
         break;

      // this is a user-defined message used to add strings to the log window
      case WM_USER_ADDSTRING:
         // get length of text in log window
         dwTextLen = SendDlgItemMessage(hWnd, IDC_LOGEDIT, WM_GETTEXTLENGTH,
                                 (WPARAM) 0, (LPARAM) 0);

         // put selection at end
         dwTextLen = SendDlgItemMessage(hWnd, IDC_LOGEDIT, EM_SETSEL,
                                 (WPARAM) dwTextLen, (LPARAM) dwTextLen);

         // add string in lParam to log window
         SendDlgItemMessage(hWnd, IDC_LOGEDIT, EM_REPLACESEL,
                        (WPARAM) FALSE, (LPARAM) lParam);
         GlobalFreePtr((LPVOID) lParam);
      break;

      case WM_COMMAND:

         switch ( LOWORD ( wParam ) ) {

            case IDC_SENDBUTTON:
               if ( bUSANDO_REDEDP )
                  SendChatMessage ( hWnd, &DPInfo );
            break;         

            case IDCANCEL:
               EndDialog ( hWnd, FALSE );
               break;
         }

         break;

   }

   // Allow for default processing
   return FALSE;
}



/* Abre janela de chat.
hInstance - handler da aplicacao, fornecido pelo Windows
**********************************************************/
int FazDialogo_Conversar ( HINSTANCE hInstance )  
{
   int
      nResult = 0;

   // show the chat window
   nResult = DialogBoxParam ( hInstance, MAKEINTRESOURCE ( IDD_CHATDIALOG), NULL, (DLGPROC) ChatWndProc, (LPARAM) &DPInfo );

   return nResult;
}
