void
BF_GUI_SetupDialog::Invoke_FlagsSetup(int i_Type)
{
	iSetupMainStyle = oSetup.MainStyle();

	EnableDialog(false);
	/* prepare message */
	BMessage oMessage(BF_MSG_MAINVIEW_MAINSETUP_STYLES_UPDATED);
	oMessage.AddPointer("bf_focus",this);
	/* make dialog */	
	BRect oRect(poWinView->Bounds());
	oRect.left=0;
	oRect.right=350;
	oRect.top+=30;
	oRect.bottom-=30;
	/* make dialog */	
	BF_GUI_Dialog *poDialog = new BF_GUI_Dialog(oRect,BF_DictAt(BF_DICT_FONTSETUP_FLAGS),"flags_dialog",
		oMessage,BG_GUI_DIALOG_WINRESIZE_MOVE_CENTER);
			
	/* flags */
	poDialog->LocalBounds(oRect);	
	oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
	////
	switch(i_Type){
	case BF_GUI_SETUPDIALOG_FLAGS_MAIN:{			
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_ASKEXIT),BF_SETUP_MAIN_ASK_EXIT,oRect,poDialog,true);
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_VOLSHOWHOME),BF_SETUP_MAIN_SELECTVOL_SHOWSPEC,oRect,poDialog,false);
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_VOLSTACK),BF_SETUP_MAIN_SELECTVOL_SHOWSTACK,oRect,poDialog,false);
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_VOLICONS),BF_SETUP_MAIN_SELECTVOL_SHOWSICON,oRect,poDialog,false);
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_PATHICON),BF_SETUP_MAIN_FP_HEADERICON,oRect,poDialog,false);	
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_PANBACK),BF_SETUP_NODEPANEL_USE_BACKSPACE,oRect,poDialog,false);	
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_PANRET),BF_SETUP_MAIN_RETURN_REMEMBER,oRect,poDialog,false);		 		
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_CMDPATH),BF_SETUP_CMDLINE_SHOWPATH,oRect,poDialog,false);	
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_TRACKADDICONS),BF_SETUP_FILESPANEL_TRACKERADDONS_SHOWICONS,oRect,poDialog,false);		
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_SEARCHVOLICONS),BF_SETUP_SEARCH_SETUP_VOLICONS,oRect,poDialog,false);		
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_MAINSETUP_AUTOSAVE),BF_SETUP_AUTOSAVE,oRect,poDialog,false);			
		break;}
	case BF_GUI_SETUPDIALOG_FLAGS_FILETASKS:{
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_SETUPFILES_SHOWDLG),BF_SETUP_OPERROSTER_DEFDIALOG,oRect,poDialog,true);
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_SETUPFILES_COPYDES),BF_SETUP_NODEPANEL_DESELECT_AFTER_COPY,oRect,poDialog,false);
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_SETUPFILES_MOVEDES),BF_SETUP_NODEPANEL_DESELECT_AFTER_MOVE,oRect,poDialog,false);
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_SETUPFILES_ASKDEL),BF_SETUP_MAIN_ASK_DELETE,oRect,poDialog,false);
		Insert_MainStyle_Check(BF_DictAt(BF_DICT_SETUPFILES_ASKCOPY),BF_SETUP_MAIN_ASK_COPY,oRect,poDialog,false);	
		break;}		
	case BF_GUI_SETUPDIALOG_FLAGS_DEBUG:{
		Insert_MainStyle_Check("Debug : disable node_monitoring",BF_SETUP_DEB_NOMONITORING,oRect,poDialog,true);
		Insert_MainStyle_Check("Debug : disable filelist_sorting",BF_SETUP_DEB_NOSORTING,oRect,poDialog,false);					
		break;}
	}
	/* menu ok */	
	BL_List *ploMenu = new BL_List();
	ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_OK),"ok"));
	poDialog->AddMenu(oRect,ploMenu);		
	
	/* finish */
	//poDialog->SetHeightFromLastChild();
	poDialog->MoveToCenter( poWinView );					
	BF_GUI_Func_AddChildToMainView ( poDialog );
}
void
BF_GUI_SetupDialog::Invoke_ColorsSetup()
{
	EnableDialog(false);
	/* prepare message */
	BMessage oMessage(BF_MSG_MAINVIEW_MAINSETUP_0);
	oMessage.AddPointer("bf_focus",this);
	/* make dialog */	
	BRect oRect(poWinView->Bounds());
	oRect.left=0;
	oRect.right=400;
	oRect.top+=70;
	oRect.bottom-=70;
	/* make dialog */	
	BF_GUI_Dialog *poDialog = new BF_GUI_Dialog(oRect,BF_DictAt(BF_DICT_MAINSETUP_COLSFONTS),"colors_dialog"
		,oMessage,BG_GUI_DIALOG_WINRESIZE_MOVE_CENTER);

	/* insert colors */		
	BL_List *ploItem = new BL_List();	
	for(int iColor=0;iColor<BF_COLOR_END;iColor++){
		ploItem->AddItem(new BF_GUI_SetupDialog_ColorItem(
			BF_DictAt(poSysSetup->aoColor[iColor].iDictCode),"",&oSetup.aoColor[iColor].rgb));
	}
	
	ploItem->AddItem(new BF_GUI_ViewMenu_Item("",""));
	/* insert fonts */		
	ploItem->AddItem(new BF_GUI_SetupDialog_FontItem(BF_DictAt(BF_DICT_FONTSETUP_FONTPANEL),"back",&oSetup.oFontNode,poFontSIcon?new BBitmap(poFontSIcon):NULL));
	ploItem->AddItem(new BF_GUI_SetupDialog_FontItem(BF_DictAt(BF_DICT_FONTSETUP_FONTDIALOG),"frame",&oSetup.oFontToolView,poFontSIcon?new BBitmap(poFontSIcon):NULL));
	ploItem->AddItem(new BF_GUI_SetupDialog_FontItem(BF_DictAt(BF_DICT_FONTSETUP_FONTMONO),"dir",&oSetup.oFontMono,poFontSIcon?new BBitmap(poFontSIcon):NULL));
	ploItem->AddItem(new BF_GUI_SetupDialog_FontItem(BF_DictAt(BF_DICT_FONTSETUP_FONTCOMMAND),"dir",&oSetup.oFontCMDLine,poFontSIcon?new BBitmap(poFontSIcon):NULL));
	/*-------*/
	poDialog->LocalBounds(oRect);	
	oRect.bottom -= +oSetup.oFontToolView.fHeight*2;
	

	BF_GUI_DlgView_VMenu* poColorsMenu = new BF_GUI_DlgView_VMenu(oRect,"colors_menu",
		B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP_BOTTOM,ploItem,BF_GUI_DLGVIEW_VMENU_SICON|BF_GUI_DLGVIEW_VMENU_SET_VSCROLLBAR);		
	poDialog->AddChild(poColorsMenu);	
	
	/* menu ok */	
	BL_List *ploMenu = new BL_List();
	ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_OK),"ok"));
	poDialog->AddMenu(oRect,ploMenu);		
	
	/*
	// add scroll_bar
	BF_GUI_VScrollBar *poBar = new BF_GUI_VScrollBar(poColorsMenu,"scroll",B_FOLLOW_TOP_BOTTOM|B_FOLLOW_RIGHT);
	poColorsMenu->SetVScroll(poBar);
	poDialog->AddChild(poBar);			
	*/
	
	
	/* finish */
	//poDialog->SetHeightFromLastChild();
	poDialog->MoveToCenter( poWinView );					
	BF_GUI_Func_AddChildToMainView ( poDialog );	
}
void
BF_GUI_SetupDialog::MessageReceived(BMessage* po_Message)
{
	switch(po_Message->what){
	case BF_MSG_MAINVIEW_MAINSETUP_STYLES_UPDATED:{
		EnableDialog(true);		
		poMenu->MakeFocus();
		//
		int32 iMenuRes=-1;
		if(B_OK==po_Message->FindInt32("menu",&iMenuRes)) oSetup.SetMainStyle(iSetupMainStyle);
		//
		break;}
	case BF_MSG_MAINVIEW_MAINSETUP_0:{
		EnableDialog(true);		
		poMenu->MakeFocus();
		break;}
	case BF_MSG_DIALOG_PRESSED_OK:{
		BView 	*po;
		const char 	*pc;
		ASSERT(B_OK==po_Message->FindPointer("bf_DlgView_Focus",(void**)&po),"BF_GUI_SetupDialog::MessageReceived");
		pc = po->Name();
		if(strcmp(pc,"main_menu")==0){			
			InvokeMenu(-1,poMenu->iNavCursorIndex);
		}else{			
			//
			poSysSetup->UpdateFrom(oSetup);			
			if(poSysSetup->MainStyle() & BF_SETUP_AUTOSAVE) poSysSetup->Save();
			//
			BF_GUI_Dialog::MessageReceived(po_Message);
			//
			BMessenger oMessenger(poWin);
			BMessage   oMessage(BF_MSG_SETUP_UPDATED);
			oMessenger.SendMessage(&oMessage);			
		}
		break;}
	default:
		BF_GUI_Dialog::MessageReceived(po_Message);
	};
} 
BOOL CCommentDialog::OnSetActive()
{
	if (!CResizablePage::OnSetActive())
		return FALSE;
	if (m_bDataChanged)
	{
		bool bContainsSharedKnownFile = false;;
		int iRating = -1;
		m_bMergedComment = false;
		CString strComment;
		for (int i = 0; i < m_paFiles->GetSize(); i++)
		{
			if (!(*m_paFiles)[i]->IsKindOf(RUNTIME_CLASS(CKnownFile)))
				continue;
			CKnownFile* file = STATIC_DOWNCAST(CKnownFile, (*m_paFiles)[i]);
			// we actually could show, add and even search for comments on kad for known but not shared files,
			// but we don't publish coments entered by the user if the file is not shared (which might be changed at some point)
			// so make sure we don't let him think he can comment and disable the dialog for such files
			if (theApp.sharedfiles->GetFileByID(file->GetFileHash()) == NULL)
				continue;
			bContainsSharedKnownFile = true;
			if (i == 0)
			{
				strComment = file->GetFileComment();
				iRating = file->GetFileRating();
			}
			else
			{
				if (!m_bMergedComment && strComment.Compare(file->GetFileComment()) != 0)
				{
					strComment.Empty();
					m_bMergedComment = true;
				}
				if (iRating != -1 && (UINT)iRating != file->GetFileRating())
					iRating = -1;
			}
		}
		m_bSelf = true;
		SetDlgItemText(IDC_CMT_TEXT, strComment);
		((CEdit*)GetDlgItem(IDC_CMT_TEXT))->SetLimitText(MAXFILECOMMENTLEN);
		m_ratebox.SetCurSel(iRating);
		m_bSelf = false;
		EnableDialog(bContainsSharedKnownFile);

		m_bDataChanged = false;

		RefreshData();
	}

	return TRUE;
}
bool SpawnMoonbaseCommander (HWND hwnd, PROCESS_INFORMATION& pi, bool bSaveWaitInfo)
   {
   char szExe[1024];
   strcpy(szExe, szMoonbasePathG);
   strcat(szExe, "moonbase.exe");

   STARTUPINFO si;

   ZeroMemory( &si, sizeof(si) );
   si.cb = sizeof(si);

   if (pi.hProcess)
      CloseHandle(pi.hProcess);
   if (pi.hThread)
      CloseHandle(pi.hThread);
   ZeroMemory( &pi, sizeof(pi) );

   bool bRet;
   bRet = CreateProcess(szExe, NULL, NULL, NULL, FALSE, 0, NULL, szMoonbasePathG, &si, &pi) ? true : false;
   // GetLastError

   if (bSaveWaitInfo)
      {
      nReplayNumberHighestG = FindHighestReplayNumber();

      EnableDialog(hwnd, false);
      }
   else
      {
      CloseHandle(piG.hProcess);
      CloseHandle(piG.hThread);
      ZeroMemory(&piG, sizeof(piG));
      }

   return bRet;
   }
BOOL CALLBACK DlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) 
   { 
   switch (message) 
      { 
      case WM_INITDIALOG:
         {
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(4, 10));
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(1, 2));
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6));
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6));
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6));
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(1, 6));

         int nValue;

         nValue = GetPrivateProfileInt("MoonbaseConsole", "SizeValue", 4, szMoonbaseIniFileG);
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_SETPOS, TRUE, nValue);  
         nValue = GetPrivateProfileInt("MoonbaseConsole", "SizeRandom", FALSE, szMoonbaseIniFileG);
         CheckDlgButton(hwndDlg, IDC_CHECK1, nValue);
         
         nValue = GetPrivateProfileInt("MoonbaseConsole", "GeneratorValue", 1, szMoonbaseIniFileG);
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_SETPOS, TRUE, nValue);  
         nValue = GetPrivateProfileInt("MoonbaseConsole", "GeneratorRandom", TRUE, szMoonbaseIniFileG);
         CheckDlgButton(hwndDlg, IDC_CHECK2, nValue);

         nValue = GetPrivateProfileInt("MoonbaseConsole", "EnergyValue", 3, szMoonbaseIniFileG);
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_SETPOS, TRUE, nValue);  
         nValue = GetPrivateProfileInt("MoonbaseConsole", "EnergyRandom", TRUE, szMoonbaseIniFileG);
         CheckDlgButton(hwndDlg, IDC_CHECK3, nValue);

         nValue = GetPrivateProfileInt("MoonbaseConsole", "TerrainValue", 3, szMoonbaseIniFileG);
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_SETPOS, TRUE, nValue);  
         nValue = GetPrivateProfileInt("MoonbaseConsole", "TerrainRandom", TRUE, szMoonbaseIniFileG);
         CheckDlgButton(hwndDlg, IDC_CHECK4, nValue);

         nValue = GetPrivateProfileInt("MoonbaseConsole", "WaterValue", 3, szMoonbaseIniFileG);
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_SETPOS, TRUE, nValue);  
         nValue = GetPrivateProfileInt("MoonbaseConsole", "WaterRandom", TRUE, szMoonbaseIniFileG);
         CheckDlgButton(hwndDlg, IDC_CHECK5, nValue);

         nValue = GetPrivateProfileInt("MoonbaseConsole", "TilesetValue", 5, szMoonbaseIniFileG);
         SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_SETPOS, TRUE, nValue);  
         nValue = GetPrivateProfileInt("MoonbaseConsole", "TilesetRandom", TRUE, szMoonbaseIniFileG);
         CheckDlgButton(hwndDlg, IDC_CHECK6, nValue);

         SendMessage(hwndDlg, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIconG);

         EnableDialog(hwndDlg, true);

         return TRUE; 
         }

      case WM_VSCROLL:
         {
         if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER1))
            CheckDlgButton(hwndDlg, IDC_CHECK1, BST_UNCHECKED);
         else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER2))
            CheckDlgButton(hwndDlg, IDC_CHECK2, BST_UNCHECKED);
         else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER3))
            CheckDlgButton(hwndDlg, IDC_CHECK3, BST_UNCHECKED);
         else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER4))
            CheckDlgButton(hwndDlg, IDC_CHECK4, BST_UNCHECKED);
         else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER5))
            CheckDlgButton(hwndDlg, IDC_CHECK5, BST_UNCHECKED);
         else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER6))
            CheckDlgButton(hwndDlg, IDC_CHECK6, BST_UNCHECKED);
         return TRUE;
         }

      case WM_COMMAND: 
         switch (LOWORD(wParam)) 
            {
            case IDC_BUTTON1: // Help
               {
               HRSRC hrsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_TXT1), "TXT");
               HGLOBAL hgbl = LoadResource(NULL, hrsrc);
               BYTE *pReadme = (BYTE *)LockResource(hgbl);

               char sz[MAX_PATH];
               strcpy(sz, szMoonbasePathG);
               strcat(sz, "\\MC_README.TXT");
               FILE *pf;
               pf = fopen(sz, "wb");
               fwrite(pReadme, 1, SizeofResource(NULL, hrsrc), pf);
               fclose(pf);

               ShellExecute(hwndDlg, "open", "MC_README.TXT", NULL, szMoonbasePathG, SW_SHOWNORMAL);

               return TRUE;
               }

            case IDC_BUTTON3: // Credits
               MessageBox(hwndDlg, "A lot of people helped in one way or the other. Here are the main contributors (in alphabetical order).\n"
                                   "\n"
                                   "Katton designed and coded the Katton map generation algorithm. He decoded a lot of the tiles and published what he learned. He also coded the algorithm that puts the \"craters\" on the map and wrote the code that generates the map preview showing the options.\n"
                                   "\n"
                                   "MYCROFT wrote the tools to rip apart the MAP files so they could be deciphered, decoded the rest of the tiles, defined the format that allows the generators to describe the map without caring about tiles, wrote the code to translate the generator output to a useable map, and did the Windows coding.\n"
                                   "\n"
                                   "SpacemanSpiff designed and coded the Spiff map generation algorithm. He also contributed to deciphering the map file format.\n"
                                   "\n"
                                   "Special thanks to Bwappo for his contest-winning thumbnail image.\n"
                                   "\n"
                                   "A number of other people on the Moonbase Commander forums also contributed to map decoding or beta testing including Bwappo, Covak, florent28, Kamolas, llangford, and YorkdinK.\n",
                                   "Moonbase Console Credits",
                                   MB_OK);
               return TRUE;
            
            case IDC_BTN_HOST_GAME:
               if (!DialogBoxParam(hInstanceG, MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, HostDlgProc, 0))
                  return TRUE; // bail if they cancel
               // fall through

            case IDC_SINGLE_GENERATE:
               {
               CGameInfo gi;

               gi.nVersion = GAMENUM_VERSION;

               if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK1))
                  gi.nMapSize = ((rand() % 5) + 4) * 8; // Don't randomly pick nonstandard map sizes.
               else
                  gi.nMapSize = SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_GETPOS, 0, 0) * 8;

               if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK2))
                  gi.nGenerator = (rand() % 2) + 1;
               else
                  gi.nGenerator = SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_GETPOS, 0, 0);

               if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK6))
                  gi.nTileset = (rand() % 6) + 1;
               else
                  gi.nTileset = 7 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_GETPOS, 0, 0);;

               gi.nIP1 = (unsigned char) FIRST_IPADDRESS(dwIPAddressG);
               gi.nIP2 = (unsigned char) SECOND_IPADDRESS(dwIPAddressG);
               gi.nIP3 = (unsigned char) THIRD_IPADDRESS(dwIPAddressG);
               gi.nIP4 = (unsigned char) FOURTH_IPADDRESS(dwIPAddressG);

               MBCMIF mif;

               if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK3))
                  gi.nEnergy = (rand() % 3) + 2;   // Only use [2, 3, 4] of the legal [0, 1, 2, 3, 4, 5, 6]
               else
                  gi.nEnergy = 6 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_GETPOS, 0, 0);

               if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK4))
                  gi.nTerrain = (rand() % 3) + 2;  // Only use [2, 3, 4] of the legal [0, 1, 2, 3, 4, 5, 6]
               else
                  gi.nTerrain = 6 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_GETPOS, 0, 0);

               if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK5))
                  gi.nWater = (rand() % 3) + 2;    // Only use [2, 3, 4] of the legal [0, 1, 2, 3, 4, 5, 6]
               else
                  gi.nWater = 6 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_GETPOS, 0, 0);

               gi.nSeed = rand(); // It is critical that the seed get set right before the generate.
               srand(gi.nSeed);

               switch (gi.nGenerator)
                  {
                  case SPIFF_GEN:
                     SpiffGenerate(gi, mif);
                     break;

                  case KATTON_GEN:
                     KattonGenerate(gi, mif);
                     break;
                  }

               try
                  {
                  BackupSystemMapFile();// TODO: Do single player differently.
                  makewiz(gi.nEnergy, gi.nTerrain, gi.nWater);
                  MakeMap(mif, gi);

                  if (LOWORD(wParam) == IDC_SINGLE_GENERATE)
                     {
                     gi.nIP1 = 192;
                     gi.nIP2 = 168;
                     gi.nIP3 = 1;
                     gi.nIP4 = 1;
                     }
                  else
                     {
                     PublishGameNumber(gi, hwndDlg);

                     // Prompt the user, tell them about the game number, and give them a chance to bail.
                     if (IDCANCEL == MessageBox(hwndDlg, "Your random map has been generated.\n\nThe game number for this map needs to be given to the people that you will be playing with.\nThis number is already on the clipboard, paste it into a message to them.\n\nOnce you have done this, press Ok to start Moonbase Commander or Cancel to abort.", "Moonbase Console Message", MB_OKCANCEL))
                        {
                        RestoreSystemMapFile();

                        return TRUE;
                        }
                     }

                  HostGame(hwndDlg, gi);
                  }
               catch (CMapError e)
                  {
                  RestoreSystemMapFile();

                  char szErrorHeader[80];
                  char szError[512];
                  sprintf(szErrorHeader, "Map Generation Error: Please Report This Information");
                  sprintf(szError, "%s\n\n"
                              "Generator:\t%s\n"
                              "Seed:\t\t%04X\n"
                              "Size:\t\t%d\n"
                              "nEnergy:\t\t%d\n"
                              "nTerrain:\t\t%d\n"
                              "nWater:\t\t%d\n"
                              "\n(%d, %d)\n"
                              "%d %d %d %d\n"
                              " %c %c %c\n"
                              "%d %d %d %d\n"
                              " %c %c %c\n"
                              "%d %d %d %d\n"
                              " %c %c %c\n"
                              "%d %d %d %d\n",
                              e.m_szErrorDescription,
                              (gi.nGenerator == SPIFF_GEN) ? "SpacemanSpiff" : "Katton",
                              (int)gi.nSeed,
                              (int)gi.nMapSize,
                              gi.nEnergy,
                              gi.nTerrain,
                              gi.nWater,
                              e.m_nX, e.m_nY,
                              mif.TTLLCorner(e.m_nX,e.m_nY),  mif.TTLCorner(e.m_nX,e.m_nY),  mif.TTRCorner(e.m_nX,e.m_nY), mif.TTRRCorner(e.m_nX,e.m_nY),
                                        mif.TLCenter(e.m_nX,e.m_nY),   mif.TCenter(e.m_nX,e.m_nY),    mif.TRCenter(e.m_nX,e.m_nY), 
                               mif.TLLCorner(e.m_nX,e.m_nY),   mif.TLCorner(e.m_nX,e.m_nY),   mif.TRCorner(e.m_nX,e.m_nY),  mif.TRRCorner(e.m_nX,e.m_nY),
                                         mif.LCenter(e.m_nX,e.m_nY),  mif.aaCenterMap[e.m_nX][e.m_nY], mif.RCenter(e.m_nX,e.m_nY),
                               mif.BLLCorner(e.m_nX,e.m_nY),   mif.BLCorner(e.m_nX,e.m_nY),   mif.BRCorner(e.m_nX,e.m_nY),  mif.BRRCorner(e.m_nX,e.m_nY),
                                        mif.BLCenter(e.m_nX,e.m_nY),   mif.BCenter(e.m_nX,e.m_nY),    mif.BRCenter(e.m_nX,e.m_nY),
                              mif.BBLLCorner(e.m_nX,e.m_nY),  mif.BBLCorner(e.m_nX,e.m_nY),  mif.BBRCorner(e.m_nX,e.m_nY), mif.BBRRCorner(e.m_nX,e.m_nY));

                  MessageBox(NULL, szError, szErrorHeader, MB_OK);
                  }
               catch (CGenericError e)
                  {
                  MessageBox(NULL, e.m_szErrorDescription, "Moonbase Console Error", MB_OK);
                  }

               return TRUE;
               }

            case IDC_BUTTON2:
               {
               if (!DialogBoxParam(hInstanceG, MAKEINTRESOURCE(IDD_DIALOG2), hwndDlg, JoinDlgProc, 0))
                  return TRUE; // bail if they cancel

               MBCMIF mif;

               // seed the generator
               srand(giG.nSeed);

               switch(giG.nGenerator)
                  {
                  case SPIFF_GEN:
                     SpiffGenerate(giG, mif);
                     break;

                  case KATTON_GEN:
                     KattonGenerate(giG, mif);
                     break;
                  }

               try
                  {
                  BackupSystemMapFile();
                  makewiz(giG.nEnergy, giG.nTerrain, giG.nWater);
                  MakeMap(mif, giG);
                  }
               catch (CGenericError e)
                  {
                  RestoreSystemMapFile();
                  MessageBox(NULL, e.m_szErrorDescription, "Moonbase Console Error", MB_OK);
                  }
               catch (...)
                  {
                  // Shouldn't get map generation errors here, only valid keys should be coming in.
                  }

               JoinGame(hwndDlg, giG);

               return TRUE;
               }
               
            default:
               return FALSE;
            }

      case WM_CLOSE:
         {
         char sz[80];

         wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_GETPOS, 0, 0));
         WritePrivateProfileString("MoonbaseConsole", "SizeValue", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK1));
         WritePrivateProfileString("MoonbaseConsole", "SizeRandom", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_GETPOS, 0, 0));
         WritePrivateProfileString("MoonbaseConsole", "GeneratorValue", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK2));
         WritePrivateProfileString("MoonbaseConsole", "GeneratorRandom", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_GETPOS, 0, 0));
         WritePrivateProfileString("MoonbaseConsole", "EnergyValue", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK3));
         WritePrivateProfileString("MoonbaseConsole", "EnergyRandom", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_GETPOS, 0, 0));
         WritePrivateProfileString("MoonbaseConsole", "TerrainValue", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK4));
         WritePrivateProfileString("MoonbaseConsole", "TerrainRandom", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_GETPOS, 0, 0));
         WritePrivateProfileString("MoonbaseConsole", "WaterValue", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK5));
         WritePrivateProfileString("MoonbaseConsole", "WaterRandom", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_GETPOS, 0, 0));
         WritePrivateProfileString("MoonbaseConsole", "TilesetValue", sz, szMoonbaseIniFileG);

         wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK6));
         WritePrivateProfileString("MoonbaseConsole", "TilesetRandom", sz, szMoonbaseIniFileG);

         DestroyWindow(hwndDlg);
         return TRUE;
         }

      case WM_DESTROY:
         CleanUpMoonbaseINI();
         PostQuitMessage(0);
         return TRUE;
      } 
   return FALSE; 
   } 
BOOL CALLBACK HostDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) 
   { 
   switch (message) 
      { 
      case WM_INITDIALOG:
         {
         HWND hwndCtl = GetDlgItem(hwndDlg, IDC_COMBO1);
         SendMessage(hwndCtl, CB_ADDSTRING, 0, (LPARAM)"http://simple.showmyip.com");
         SendMessage(hwndCtl, CB_ADDSTRING, 0, (LPARAM)"http://www.whatismyip.com");
         SendMessage(hwndCtl, CB_ADDSTRING, 0, (LPARAM)"http://checkip.dyndns.org");

         char sz[1024];
         GetPrivateProfileString("MoonbaseConsole", "IPService", "http://simple.showmyip.com", sz, sizeof(sz), szMoonbaseIniFileG);
         SendMessage(hwndCtl, WM_SETTEXT, NULL, (LPARAM)sz);

         int nValue;

         nValue = GetPrivateProfileInt("MoonbaseConsole", "IPAddress", 0, szMoonbaseIniFileG);
         if (nValue)
            SendMessage(GetDlgItem(hwndDlg, IDC_IPADDRESS1), IPM_SETADDRESS, 0, (LPARAM)nValue);

         EnableDialog(hwndDlg, true);

         return TRUE; 
         }
  
      case WM_NOTIFY:
         switch (wParam)
            {
            case IDC_IPADDRESS1:
               LPNMIPADDRESS lpnmipa;
               lpnmipa = (LPNMIPADDRESS) lParam;

               // TODO:This has to be changed to be the right button
               EnableDisableHostButton(hwndDlg);

               return TRUE;

            default:
               return FALSE;
            }

      case WM_COMMAND: 
         switch (LOWORD(wParam)) 
            {
            case IDC_BUTTON1:
               {
               char sz[1024];

               GetDlgItemText(hwndDlg, IDC_COMBO1, sz, 1024);

               // TODO: Some kind of timeout here?
               EnableDialog(hwndDlg, false);
               SendMessage(GetDlgItem(hwndDlg, IDC_IPADDRESS1), IPM_SETADDRESS, 0, (LPARAM)DetectIPAddress(sz));
               EnableDialog(hwndDlg, true);

               return TRUE;
               }

            case IDC_BUTTON3:
               {
               // TODO: Some kind of timeout here?
               EnableDialog(hwndDlg, false);
               SendMessage(GetDlgItem(hwndDlg, IDC_IPADDRESS1), IPM_SETADDRESS, 0, (LPARAM)DetectLANIPAddress());
               EnableDialog(hwndDlg, true);

               return TRUE;
               }


            case IDOK:
               {
               char sz[80];
               SendMessage(GetDlgItem(hwndDlg, IDC_IPADDRESS1), IPM_GETADDRESS, 0, (LPARAM)&dwIPAddressG);
               wsprintf(sz, "%d", dwIPAddressG);
               WritePrivateProfileString("MoonbaseConsole", "IPAddress", sz, szMoonbaseIniFileG);

               GetDlgItemText(hwndDlg, IDC_COMBO1, sz, 80);
               WritePrivateProfileString("MoonbaseConsole", "IPService", sz, szMoonbaseIniFileG);

               EndDialog(hwndDlg, TRUE);

               return TRUE;
               }

            case IDCANCEL:
               {
               dwIPAddressG = NULL;

               EndDialog(hwndDlg, FALSE);

               return TRUE;
               }
               
            default:
               return FALSE;
            }
      } 
   return FALSE; 
   } 
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
   {   
   hInstanceG = hInstance;

   srand((unsigned)time(NULL));

   if (!InitializeWindowsStuff())
      return -1;

   if (!InitializeMBCStuff(lpCmdLine))
      return -1;

   hIconG = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
   hwndDlgModelessG = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), GetDesktopWindow(), (DLGPROC) DlgProc); 
   ShowWindow(hwndDlgModelessG, SW_SHOW); 

   while (TRUE)
      {
      DWORD result;
      MSG msg;
      DWORD cObjects = 0;
      
      while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
         { 
         if (msg.message == WM_QUIT)  
            return 0; 
         
         if (!IsDialogMessage(hwndDlgModelessG, &msg)) 
            { 
            TranslateMessage(&msg); 
            DispatchMessage(&msg); 
            }
         }

      if (piG.hProcess)
         cObjects = 1;
      else
         cObjects = 0;

      result = MsgWaitForMultipleObjectsEx(cObjects, &piG.hProcess, INFINITE, QS_ALLINPUT | QS_ALLPOSTMESSAGE, 0); 
      
      if (result == (WAIT_OBJECT_0 + cObjects))
         continue; // New messages have arrived, continue to the top of the loop to dispatch them and resume waiting.
      else 
         { 
         // MBC has exited
         EnableDialog(hwndDlgModelessG, true);

         int nReplayNumberHighest = FindHighestReplayNumber();

         if (nReplayNumberHighest > nReplayNumberHighestG)
            {
            char szReplay[MAX_PATH];
            sprintf(szReplay, "%suser\\Rep%03d.rep", szMoonbasePathG, nReplayNumberHighest);
            int nReplayMap = GetPrivateProfileInt("SETUP", "5-10", 1, szReplay);
            if (nReplayMap == 1)    // Only copy random map if they used it.
               {
               char szSource[MAX_PATH];
               char szDest[MAX_PATH];

               strcpy(szSource, szMoonbasePathG);
               strcat(szSource, "map\\moon001.map");

               sprintf(szDest, "%suser\\Rep%03d.map", szMoonbasePathG, nReplayNumberHighest);

               CopyFile(szSource, szDest, TRUE);

               WritePrivateProfileString("SETUP", "5-10", "66", szReplay); // Update the replay to reflect the custom map.
               }
            }

         RestoreSystemMapFile();

         CloseHandle(piG.hProcess);
         CloseHandle(piG.hThread);
         ZeroMemory(&piG, sizeof(piG));
         } 
      }
   }