op2_sdk:textdialogbox

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
op2_sdk:textdialogbox [2016/03/28 02:28] vagabondop2_sdk:textdialogbox [2016/03/28 13:35] vagabond
Line 14: Line 14:
 Rich Text Format documents include metadata such as font and text color which are not available in text (.txt) format. Depending on the program used to open an RTF, the metadata may be hidden. Microsoft Word and Wordpad will default to showing just the text and the effect of the metadata on the text. Notepad or Notepad++ will show all of the metadata. Rich Text Format documents include metadata such as font and text color which are not available in text (.txt) format. Depending on the program used to open an RTF, the metadata may be hidden. Microsoft Word and Wordpad will default to showing just the text and the effect of the metadata on the text. Notepad or Notepad++ will show all of the metadata.
  
-Outpost 2 uses Arial font size 10 for Campaign Mission Briefing Screens.+For campaign mission briefing screens, Outpost 2 uses Arial font size 10 with an RGB of red0\green255\blue0.
  
-**Note:** //Although Microsoft Word can create and save RTF documents, it is not recommended. Microsoft Word adds large amounts of metadata to the document that is not necessary for Outpost 2, typically increasing a small amount of text from about 3 kb to about 50 kb.//+Typically, the RTF file is saved as briefing.rtf and added to the root directory of the scenario's project. 
 + 
 +**Note:** //Although Microsoft Word can create and save RTF documents, it is not recommended. Microsoft Word adds large amounts of metadata to the document that is not necessary for Outpost 2, typically increasing a small amount of text from about 3 kb to about 50 kb. This file size increase will carry into the compiled DLL.//
  
 **Example RTF file** **Example RTF file**
Line 43: Line 45:
 ===== Adding a Resource Script (.rc) File ===== ===== Adding a Resource Script (.rc) File =====
  
-Microsoft Visual Studio will autogenerate resource script files. Some of the auto-generated content are unnecessary comments.+Resource script files are text documents describing resources associated with an executable or DLL. These include among other things Version Information, Icons, Cursors, Dialog box descriptions, and Menu Toolbars. Microsoft Visual Studio will auto-generate resource script files. 
 + 
 +To add a resource script file and associated resource header: 
 + 
 +right click on your project in the solution explorer. -> Add -> New Item... -> Visual C++ -> Resource -> Resource File (.rc) -> Add. 
 + 
 +Resource Scripts by default is placed in the Resource Files filter in the Solution Explorer. Use the Solution Explorer (or your favorite text editor) to open the file file in text view. You can also access the Resource Script from the Visual Studio Resource View, which defaults to opening on the left side of Visual Studio. The Resource View allows graphical depiction of Dialog Boxes defined in the resource script file. Alternative programs like Resource Hacker can also load Resource Scripts.
  
-#ifdef //identifier// is the if defined directiveExecute the code if the identifier is defined.+Below is a sample resource script file that provides a dialog box before a scenario is initialized. The dialog box will include the contents of briefing.rtf in a rich text box.
  
 For more information on TEXTINCLUDE, see: https://msdn.microsoft.com/en-us/library/6t3612sk.aspx. For more information on TEXTINCLUDE, see: https://msdn.microsoft.com/en-us/library/6t3612sk.aspx.
 +
 +#ifdef //identifier// - If defined directive. Execute the code if the identifier is defined.
 +
 +#ifndef //identifier// - If not defined directive. Execute the code if the identifier is not defined.
 +
 +#undef //identifier// - Undefined directive. Removes the definition of an identifier.
  
 <code cpp> <code cpp>
Line 59: Line 73:
 // Generated from the TEXTINCLUDE 2 resource. // Generated from the TEXTINCLUDE 2 resource.
 // //
-#include "afxres.h"+#include "winres.h"
  
 ///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
Line 120: Line 134:
 2 TEXTINCLUDE  2 TEXTINCLUDE 
 BEGIN BEGIN
-    "#include ""afxres.h""\r\n"+    "#include ""winres.h""\r\n"
     "\0"     "\0"
 END END
Line 243: Line 257:
 #endif #endif
  
 +</code>
 +
 +===== Creating the Dialog Box in Code =====
 +
 +Once the resource script and resource header have been well formed, the briefing screen should be called from the beginning of ''InitProc''. You will have to include the Sierra library odasl.h in your project.
 +
 +First, you will require a handle to the DLL instance from DllMain.
 +
 +**DllMain.cpp**
 +<code cpp>
 +#define WIN32_LEAN_AND_MEAN
 +#include <windows.h>
 +
 +// Used by the scenario briefing screen.
 +HINSTANCE hInst;
 +
 +BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 +{
 + if (fdwReason == DLL_PROCESS_ATTACH)
 + {
 + DisableThreadLibraryCalls(hinstDLL);
 + hInst = hinstDLL;
 + }
 +
 + return TRUE;
 +}
 +</code>
 +
 +**briefigin.h**
 +<code cpp>
 +#pragma once
 +
 +#define WIN32_LEAN_AND_MEAN
 +#include <windows.h>
 +
 +#include <richedit.h>
 +#include "resource.h"
 +#include "odasl\odasl.h"
 +
 +void ShowBriefing();
 +LRESULT CALLBACK DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
 +</code>
 +
 +**briefing.cpp**
 +<code cpp>
 +#include "Briefing.h"
 +
 +extern HINSTANCE hInst;
 +
 +// Briefing source code is pulled from Plymouth Cold War Scenario and was written by BlackBox.
 +void ShowBriefing()
 +{
 + // OP2 turns off the skinning before the game loads.
 + // We have to re-enable it (otherwise the briefing box will look ugly).
 + wplEnable();
 + // Show the dialog box, using the shell window as the parent
 + HWND shellWnd = FindWindow("Outpost2Shell", NULL);
 + DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_MISSIONINFO), shellWnd, (DLGPROC)DialogProc, NULL);
 + // Turn off the skinning again (probably not needed but a good idea to do it anyway)
 + wplDisable();
 +}
 +
 +LRESULT CALLBACK DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 +{
 + HRSRC txtRes = NULL;
 + HWND richEdit = NULL;
 + switch (msg)
 + {
 + case WM_INITDIALOG:
 + // Make the BG black in the rich edit box
 + richEdit = GetDlgItem(hWnd, IDC_TEXTAREA);
 + SendMessage(richEdit, EM_SETBKGNDCOLOR, 0, 0);
 +
 + // Find the text resource
 + txtRes = FindResource(hInst, MAKEINTRESOURCE(IDR_MISSIONTEXT), "TEXT");
 + if (txtRes)
 + {
 + // Load it
 + HGLOBAL resHdl = LoadResource(hInst, txtRes);
 + if (resHdl)
 + {
 + // Lock it and set the text
 + char *briefing = (char*)LockResource(resHdl);
 + if (briefing)
 + {
 + SetDlgItemText(hWnd, IDC_TEXTAREA, briefing);
 + return TRUE;
 + }
 + }
 + }
 + SetDlgItemText(hWnd, IDC_TEXTAREA, "Error: Mission text could not be loaded.");
 + return TRUE;
 + case WM_COMMAND:
 + if (wParam == IDOK)
 + {
 + EndDialog(hWnd, IDOK);
 + return TRUE;
 + }
 + return FALSE;
 + }
 + return FALSE;
 +}
 </code> </code>
  
  • op2_sdk/textdialogbox.txt
  • Last modified: 2016/12/28 19:03
  • by vagabond