main.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:6k
- /*
- * main.cxx
- *
- * PWLib application source file for $$PRODUCT_NAME$$
- *
- * Main program entry point.
- *
- * Copyright $$YEAR$$ $$MANUFACTURER$$
- *
- * $Log$
- */
- #include <$$HEADER_FILE$$>
- #include "main.h"
- $$IF(IS_GUI)
- #include "resources.h"
- $$ENDIF
- $$IF(HAS_HTTP)
- #include "custom.h"
- $$ENDIF
- PCREATE_PROCESS($$APP_CLASS_NAME$$);
- $$IF(HAS_HTTP)
- const WORD DefaultHTTPPort = 6666;
- $$ENDIF
- $$APP_CLASS_NAME$$::$$APP_CLASS_NAME$$()
- $$IF(HAS_HTTP)
- : $$PARENT_APP_CLASS$$(ProductInfo)
- $$ELSE
- : $$PARENT_APP_CLASS$$("$$MANUFACTURER$$", "$$PRODUCT_NAME$$", 1, 0, AlphaCode, 1)
- $$ENDIF
- {
- }
- $$IF(IS_SERVICE)
- #ifdef _WIN32
- const char * $$APP_CLASS_NAME$$::GetServiceDependencies() const
- {
- return "EventLog Tcpip ";
- }
- #endif
- BOOL $$APP_CLASS_NAME$$::OnStart()
- {
- GetFile().GetDirectory().Change();
- $$IF(HAS_HTTP)
- httpNameSpace.AddResource(new PHTTPDirectory("data", "data"));
- httpNameSpace.AddResource(new PServiceHTTPDirectory("html", "html"));
- $$ENDIF
- return Initialise("Started");
- }
- void $$APP_CLASS_NAME$$::OnStop()
- {
- PSYSTEMLOG(Warning, GetName() << " stopped.");
- PServiceProcess::OnStop();
- }
- BOOL $$APP_CLASS_NAME$$::OnPause()
- {
- $$IF(HAS_HTTP)
- OnConfigChanged();
- $$ENDIF
- return TRUE;
- }
- void $$APP_CLASS_NAME$$::OnContinue()
- {
- if (Initialise("Restarted"))
- return;
- OnStop();
- Terminate();
- }
- void $$APP_CLASS_NAME$$::OnControl()
- {
- // This function get called when the Control menu item is selected in the
- // tray icon mode of the service.
- $$IF(HAS_HTTP)
- PStringStream url;
- url << "http://";
- PString host = PIPSocket::GetHostName();
- PIPSocket::Address addr;
- if (PIPSocket::GetHostAddress(host, addr))
- url << host;
- else
- url << "localhost";
- url << ':' << httpListeningSocket->GetPort();
- PURL::OpenBrowser(url);
- $$ENDIF
- }
- $$IF(HAS_HTTP)
- void $$APP_CLASS_NAME$$::OnConfigChanged()
- {
- }
- PString $$APP_CLASS_NAME$$::GetPageGraphic()
- {
- PFile header;
- if (header.Open("header.html", PFile::ReadOnly))
- return header.ReadString(header.GetLength());
- return PHTTPServiceProcess::GetPageGraphic();
- }
- void $$APP_CLASS_NAME$$::AddUnregisteredText(PHTML &)
- {
- }
- $$ENDIF
- BOOL $$APP_CLASS_NAME$$::Initialise(const char * initMsg)
- {
- $$IF(HAS_HTTP)
- // create the home page
- static const char welcomeHtml[] = "welcome.html";
- if (PFile::Exists(welcomeHtml))
- httpNameSpace.AddResource(new PServiceHTTPFile(welcomeHtml, TRUE), PHTTPSpace::Overwrite);
- else {
- PHTML html;
- html << PHTML::Title("Welcome to "+GetName())
- << PHTML::Body()
- << "<CENTER>rn"
- << PHTML::Heading(1) << "Welcome to "
- << gifHTML
- << PHTML::Heading(1)
- << PProcess::GetOSClass() << ' ' << PProcess::GetOSName()
- << " Version " << GetVersion(TRUE) << PHTML::BreakLine()
- << ' ' << compilationDate.AsString("d MMMM yy")
- << PHTML::BreakLine()
- << "by"
- << PHTML::BreakLine()
- << PHTML::Heading(3)
- << PHTML::HotLink(GetHomePage()) << GetManufacturer() << PHTML::HotLink()
- << PHTML::Heading(3)
- << PHTML::HotLink(PString("mailto:")+GetEMailAddress()) << GetEMailAddress() << PHTML::HotLink()
- << PHTML::Paragraph()
- << PHTML::HRule()
- << PHTML::Paragraph()
- << PHTML::HotLink("http://www.equival.com.au/$$PRODUCT_NAME$$/relnotes/" + GetVersion(TRUE) + ".html")
- << "Release notes" << PHTML::HotLink()
- << " on this version of " << GetProductName() << " are available."
- << PHTML::Paragraph()
- << PHTML::HRule()
- << GetCopyrightText()
- << PHTML::Body();
- httpNameSpace.AddResource(new PServiceHTTPString("welcome.html", html), PHTTPSpace::Overwrite);
- }
- // set up the HTTP port for listening & start the first HTTP thread
- if (ListenForHTTP(DefaultHTTPPort))
- PSYSTEMLOG(Info, "Opened master socket for HTTP: " << httpListeningSocket->GetPort());
- else {
- PSYSTEMLOG(Fatal, "Cannot run without HTTP port: " << httpListeningSocket->GetErrorText());
- return FALSE;
- }
- $$ENDIF
- PSYSTEMLOG(Info, "Service " << GetName() << ' ' << initMsg);
- return TRUE;
- }
- $$ENDIF
- void $$APP_CLASS_NAME$$::Main()
- {
- $$IF(HAS_HTTP)
- Suspend();
- $$ENDIF
- $$IF(IS_GUI)
- SetAboutDialogID(IDD_ABOUT);
- PNEW MainWindow(GetArguments());
- PApplication::Main();
- $$ENDIF
- }
- $$IF(IS_GUI)
- MainWindow::MainWindow(PArgList & /*args*/)
- {
- SetTitle(PResourceString(IDS_TITLE));
- SetIcon(PIcon(IDI_MAIN_WINDOW));
- SetMenu(new MainMenu(this));
- UpdateCommandSources();
- ShowAll();
- }
- void MainWindow::NewCmd(PMenuItem &, INT)
- {
- // New document
- }
- void MainWindow::OpenCmd(PMenuItem &, INT)
- {
- POpenFileDialog dlg(this);
- if (dlg.RunModal()) {
- // Open existing document
- }
- }
- void MainWindow::CloseCmd(PMenuItem &, INT)
- {
- // Close document
- }
- void MainWindow::SaveCmd(PMenuItem &, INT)
- {
- // Save current document
- }
- void MainWindow::SaveAsCmd(PMenuItem &, INT)
- {
- PSaveFileDialog dlg(this);
- if (dlg.RunModal()) {
- // Save document to new name
- }
- }
- void MainWindow::PrintCmd(PMenuItem &, INT)
- {
- PPrintJobDialog dlg(this, printInfo);
- if (dlg.RunModal()) {
- printInfo = dlg.GetPrintInfo();
- PPrintCanvas canvas("$$PRODUCT_NAME$$", printInfo);
- // Add printing code here
- }
- }
- void MainWindow::PrinterSetupCmd(PMenuItem &, INT)
- {
- PPrinterSetupDialog dlg(this, printInfo);
- if (dlg.RunModal())
- printInfo = dlg.GetPrintInfo();
- }
- void MainWindow::ExitCmd(PMenuItem &, INT)
- // The Exit menu ... well ... exits.
- {
- owner->Terminate();
- }
- void MainWindow::CopyCmd()
- {
- PClipboard clip(this);
- // Do something with the clipboard
- }
- BOOL MainWindow::CanCopy()
- {
- // If want copy menu enabled
- return TRUE;
- }
- void MainWindow::PasteCmd()
- {
- PClipboard clip(this);
- // Do something with the clipboard
- }
- BOOL MainWindow::CanPaste()
- {
- // If want paste menu enabled, ie clipboard has right format
- return TRUE;
- }
- $$ENDIF
- // End of File ///////////////////////////////////////////////////////////////