Back to index

lightning-sunbird  0.9+nobinonly
Functions
TestHelloXPLoop.cpp File Reference
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "nsCNativeApp.h"
#include "nsIEventLoop.h"
#include <windows.h>

Go to the source code of this file.

Functions

static NS_DEFINE_CID (kNativeAppCID, NS_NATIVE_APP_CID)
LRESULT CALLBACK WndProc (HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
void ErrorBox (LPSTR text)
void InfoBox (LPSTR text)
int WINAPI WinMain (HINSTANCE inst, HINSTANCE prevInstance, LPSTR lpszCmdLine, int nShowCmd)

Function Documentation

void ErrorBox ( LPSTR  text)

Definition at line 50 of file TestHelloXPLoop.cpp.

{
       MessageBox(NULL, text, "XP Event Loop", MB_OK | MB_ICONSTOP);
}

Here is the caller graph for this function:

void InfoBox ( LPSTR  text)

Definition at line 55 of file TestHelloXPLoop.cpp.

{
       MessageBox(NULL, text, "XP Event Loop", MB_OK | MB_ICONINFORMATION);
}

Here is the caller graph for this function:

static NS_DEFINE_CID ( kNativeAppCID  ,
NS_NATIVE_APP_CID   
) [static]
int WINAPI WinMain ( HINSTANCE  inst,
HINSTANCE  prevInstance,
LPSTR  lpszCmdLine,
int  nShowCmd 
)

Definition at line 60 of file TestHelloXPLoop.cpp.

{
       char* lpszAppName = "HelloWorld";
       HWND wnd;
       WNDCLASSEX wndclass;
       int retCode;

    {  //  Needed to scope all nsCOMPtr within XPCOM Init and Shutdown
      nsresult rv;
      nsCOMPtr<nsIServiceManager> servMan;
      rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
      if(NS_FAILED(rv))
      {
        ErrorBox("Failed to initalize xpcom.");
        return -1;
      }
      
      nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
      NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
      registrar->AutoRegister(nsnull);
      
      nsCOMPtr<nsINativeApp> nativeAppService(do_GetService(kNativeAppCID, &rv));

      if(NS_FAILED(rv))
      {
        ErrorBox("Failed to get nativeAppService");
        return -1;
      }
      wndclass.cbSize        = sizeof(wndclass);
      wndclass.style         = CS_HREDRAW | CS_VREDRAW;
      wndclass.lpfnWndProc   = WndProc;
      wndclass.cbClsExtra    = 0;
      wndclass.cbWndExtra    = 0;
      wndclass.hInstance     = inst;
      wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
      wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
      wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
      wndclass.lpszMenuName  = NULL;
      wndclass.lpszClassName = lpszAppName;
      wndclass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

      RegisterClassEx(&wndclass) ;
      
      wnd = CreateWindow(lpszAppName, "The Hello World",
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, CW_USEDEFAULT,
                         CW_USEDEFAULT, CW_USEDEFAULT,
                         NULL, NULL, inst, NULL);                   
      
      ShowWindow(wnd, nShowCmd);
      UpdateWindow(wnd);
      
      nsCOMPtr<nsIEventLoop> eventLoop;
      
      if(NS_FAILED(nativeAppService->CreateEventLoop(L"_MainLoop", 
                                                     nsEventLoopTypes::MainAppLoop, getter_AddRefs(eventLoop))))
        {
          ErrorBox("Failed to create event Loop");
          return 0;
        } 
      
      eventLoop->Run(nsnull, nsnull, nsnull, &retCode);
      eventLoop = nsnull; // Clear out before Shutting down XPCOM
      
      InfoBox("Hello World app is out of loop");
    }
       NS_ShutdownXPCOM(nsnull);
       InfoBox("Hello World app is exiting");
       return retCode;
}

Here is the call graph for this function:

LRESULT CALLBACK WndProc ( HWND  wnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)