res = nsRepository::CreateInstance(kDeviceContextCID, nsnull, kDeviceContextIID, (void **)&scribbleData.mContext);  if (NS_OK == res) scribbleData.mContext->Init(nsnull);
nsresult CreateApplication(int * argc, char ** argv){    scribbleData.isDrawing = PR_FALSE;    // register graphics classes    static NS_DEFINE_IID(kCRenderingContextIID, NS_RENDERING_CONTEXT_CID);    static NS_DEFINE_IID(kCDeviceContextIID, NS_DEVICE_CONTEXT_CID);    static NS_DEFINE_IID(kCFontMetricsIID, NS_FONT_METRICS_CID);    static NS_DEFINE_IID(kCImageIID, NS_IMAGE_CID);    nsRepository::RegisterFactory(kCRenderingContextIID, GFX_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCDeviceContextIID, GFX_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCFontMetricsIID, GFX_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCImageIID, GFX_DLL, PR_FALSE, PR_FALSE);    // register widget classes    static NS_DEFINE_IID(kCWindowCID, NS_WINDOW_CID);    static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);    static NS_DEFINE_IID(kCButtonCID, NS_BUTTON_CID);    static NS_DEFINE_IID(kCCheckButtonCID, NS_CHECKBUTTON_CID);    static NS_DEFINE_IID(kCComboBoxCID, NS_COMBOBOX_CID);    static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);    static NS_DEFINE_IID(kCListBoxCID, NS_LISTBOX_CID);    static NS_DEFINE_IID(kCRadioButtonCID, NS_RADIOBUTTON_CID);    static NS_DEFINE_IID(kCHorzScrollbarCID, NS_HORZSCROLLBAR_CID);    static NS_DEFINE_IID(kCVertScrollbarCID, NS_VERTSCROLLBAR_CID);    static NS_DEFINE_IID(kCTextAreaCID, NS_TEXTAREA_CID);    static NS_DEFINE_IID(kCTextFieldCID, NS_TEXTFIELD_CID);    static NS_DEFINE_IID(kCLookAndFeelCID, NS_LOOKANDFEEL_CID);    nsRepository::RegisterFactory(kCAppShellCID, WIDGET_DLL, PR_FALSE, PR_FALSE); 		nsRepository::RegisterFactory(kCToolkitCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCWindowCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCChildCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCCheckButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCComboBoxCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCFileWidgetCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCListBoxCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCRadioButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCHorzScrollbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCVertScrollbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCTextAreaCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCTextFieldCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    nsRepository::RegisterFactory(kCLookAndFeelCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    //NS_InitToolkit(PR_GetCurrentThread());    nsresult  res;    static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);    static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);    res = nsRepository::CreateInstance(kDeviceContextCID, nsnull, kDeviceContextIID, (void **)&scribbleData.mContext);    if (NS_OK == res)      scribbleData.mContext->Init(nsnull);     // Create an application shell    nsIAppShell *appShell = nsnull;    nsRepository::CreateInstance(kCAppShellCID, nsnull, kIAppShellIID,                                 (void**)&appShell);    appShell->Create(argc, argv);       //nsILookAndFeel *laf;    //nsRepository::CreateInstance(kCLookAndFeelCID, nsnull, kILookAndFeelIID,(void**)&laf);        //    // create the main window    //    nsRepository::CreateInstance(kCWindowCID, nsnull, kIWindowIID,                                 (void **)&(scribbleData.mainWindow));    nsRect rect(100, 100, 600, 700);    scribbleData.mainWindow->Create((nsIWidget*)NULL,                                     rect,                                     HandleEventMain,                                     NULL,                                    appShell);    //scribbleData.mainWindow->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));    scribbleData.mainWindow->SetBackgroundColor(NS_RGB(255,255,255));    scribbleData.mainWindow->SetTitle("Scribble");    //    // create the control pane    //    nsIWidget *controlPane;    rect.SetRect(0, 0, 200, 700);      nsRepository::CreateInstance(kCChildCID, nsnull, kIWidgetIID, (void **)&controlPane);    controlPane->Create(scribbleData.mainWindow, rect, HandleEventControlPane, NULL);    //controlPane->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));    controlPane->SetBackgroundColor(NS_RGB(100,128,128));    controlPane->Show(PR_TRUE);    //    // Add the scribble/lines section    //    // create the "Scribble" radio button    rect.SetRect(50, 50, 100, 25);      nsRepository::CreateInstance(kCRadioButtonCID, nsnull, kIRadioButtonIID, (void **)&(scribbleData.scribble));    NS_CreateRadioButton(controlPane,scribbleData.scribble,rect,HandleEventRadioButton);    scribbleData.scribble->SetLabel("Scribble");    scribbleData.scribble->SetState(PR_FALSE);    //scribbleData.scribble->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));    // create the "Lines" radio button    rect.SetRect(50, 75, 100, 25);      nsRepository::CreateInstance(kCRadioButtonCID, nsnull, kIRadioButtonIID, (void **)&(scribbleData.lines));    NS_CreateRadioButton(controlPane,scribbleData.lines,rect,HandleEventRadioButton);    scribbleData.lines->SetLabel("Lines");    scribbleData.lines->SetState(PR_TRUE);    //scribbleData.lines->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));    // Add the circle/rectangle section    // create the "Circles" check button    nsICheckButton * checkButton;    rect.SetRect(50, 200, 100, 25);      nsIWidget* widget = nsnull;    nsRepository::CreateInstance(kCCheckButtonCID, nsnull, kICheckButtonIID, (void **)&checkButton);    if (NS_OK == checkButton->QueryInterface(kIWidgetIID,(void **)&widget))    {      widget->Create(controlPane, rect, HandleEventCheck, NULL);      nsString cbLabel2("Circles");      checkButton->SetLabel(cbLabel2);      //checkButton->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));      widget->Show(PR_TRUE);      NS_RELEASE(widget);    }    NS_RELEASE(checkButton);    // create the "Rectangles" check button    rect.SetRect(50, 225, 100, 25);      nsRepository::CreateInstance(kCCheckButtonCID, nsnull, kICheckButtonIID, (void **)&checkButton);    NS_CreateCheckButton(controlPane,checkButton,rect,HandleEventCheck);    if (NS_OK == checkButton->QueryInterface(kIWidgetIID,(void**)&widget))    {      // widget->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));      checkButton->SetLabel("Rectangles");      NS_RELEASE(widget);    }    NS_RELEASE(checkButton);    // create the "Images" check button    rect.SetRect(50, 250, 100, 25);      nsRepository::CreateInstance(kCCheckButtonCID, nsnull, kICheckButtonIID, (void **)&checkButton);    if (NS_OK == checkButton->QueryInterface(kIWidgetIID,(void **)&widget))    {      widget->Create(controlPane, rect, HandleEventCheck, NULL);      nsString cbLabel4("Image");      checkButton->SetLabel(cbLabel4);      //checkButton->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));      widget->Show(PR_TRUE);      NS_RELEASE(widget);    }    NS_RELEASE(checkButton);    //    // Add the color section    //    int y = COLOR_FIELDS_Y;    // create the "red" text widget    rect.SetRect(100, y, 50, TEXT_HEIGHT);      PRUint32 size;    nsString initText("0");    nsRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void **)&(scribbleData.red));    if (NS_OK == scribbleData.red->QueryInterface(kIWidgetIID,(void **)&widget))    {      widget->Create(controlPane, rect, HandleEventText, NULL);      scribbleData.red->SetText(initText,size);      widget->SetBackgroundColor(NS_RGB(0, 0, 255));      widget->Show(PR_TRUE);    }    y += rect.height +2;    // create the "green" text widget    rect.SetRect(100, y, 50, TEXT_HEIGHT);      nsRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void **)&(scribbleData.green));    if (NS_OK == scribbleData.green->QueryInterface(kIWidgetIID,(void **)&widget))    {      widget->Create(controlPane, rect, HandleEventText, NULL);      scribbleData.green->SetText(initText,size);      widget->SetBackgroundColor(NS_RGB(255, 0, 0));      widget->Show(PR_TRUE);    }    y += rect.height +2;    // create the "blue" text widget    rect.SetRect(100, y, 50, TEXT_HEIGHT);      nsRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void **)&(scribbleData.blue));    if (NS_OK == scribbleData.blue->QueryInterface(kIWidgetIID,(void **)&widget))    {      widget->Create(controlPane, rect, HandleEventText, NULL);      scribbleData.blue->SetText(initText,size);      widget->SetBackgroundColor(NS_RGB(0, 255, 0));      widget->Show(PR_TRUE);    }    y += rect.height +2;    //    // create a button      //    nsIButton *button;    rect.SetRect(50, 500, 100, 25);      nsRepository::CreateInstance(kCButtonCID, nsnull, kIButtonIID, (void **)&button);    NS_CreateButton(controlPane,button,rect,HandleEventButton);    button->SetLabel("Clear");    NS_RELEASE(button);    NS_RELEASE(controlPane); // the parent keeps a reference on this child    //    // create the draw pane    //    rect.SetRect(200, 0, 400, 700);      nsRepository::CreateInstance(kCChildCID, nsnull, kIWidgetIID, (void **)&scribbleData.drawPane);    scribbleData.drawPane->Create(scribbleData.mainWindow, rect, HandleEventGraphicPane, NULL);    //scribbleData.drawPane->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));    scribbleData.drawPane->SetBackgroundColor(NS_RGB(255,250,250));    scribbleData.drawPane->Show(PR_TRUE);    // show. We are in business...    scribbleData.mainWindow->Show(PR_TRUE);    //laf->Release();    polllistener *plistener = new polllistener;    appShell->SetDispatchListener(plistener);    return(appShell->Run());}