BOOL CmyWord::Open(CString fileName) { if(FALSE == PathFileExists(fileName) || -1 == fileName.Find(_T(".doc"))) { AfxMessageBox(_T("请确定路径是否正确!"),MB_OK|MB_ICONSTOP); return FALSE; } CComVariant Read(FALSE); CComVariant AddToR(FALSE); CComVariant Name(fileName); COleVariant vTrue((short)TRUE); COleVariant vFalse((short)FALSE); COleVariant varstrNull(_T("")); COleVariant varZero((short)0); COleVariant varTrue(short(1),VT_BOOL); COleVariant varFalse(short(0),VT_BOOL); COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR); if(!m_wdApp.m_lpDispatch) { if(CreateApp()==FALSE) { return FALSE; } } if(!m_wdDoc.m_lpDispatch) { m_wdDocs=m_wdApp.GetDocuments(); if(!m_wdDocs.m_lpDispatch) { AfxMessageBox(_T("DocuMent 对象创建失败")); CloseApp(); return FALSE; } } CComVariant format(0);//打开方式 0 为doc的打开方式 //doc=docs.Open(&Name,varFalse,&Read,&AddToR,vOpt,vOpt,vFalse,vOpt,vOpt,&format,vOpt,vTrue,vOpt,vOpt,vOpt,vOpt); m_wdDoc = m_wdDocs.Add(&Name, vOpt, vOpt, vOpt); if(!m_wdDoc.m_lpDispatch) { AfxMessageBox(_T("文件打开失败")); CloseApp(); return FALSE; } else { m_wdSel=m_wdApp.GetSelection(); if(!m_wdSel.m_lpDispatch) { AfxMessageBox(_T("打开失败")); CloseApp(); return FALSE; } return TRUE; } }
BOOL CmyWord::CreateDocuments() { if (FALSE == CreateApp()) { return FALSE; } m_wdDocs.AttachDispatch(m_wdApp.GetDocuments()); if (!m_wdDocs.m_lpDispatch) { AfxMessageBox(_T("Documents创建失败!"), MB_OK|MB_ICONWARNING); return FALSE; } return TRUE; }
int main(int argc, char* argv[]) { memset(kKeyPool, false, sizeof(kKeyPool)); //! Create App if(!(g_pApp = CreateApp())) return 1; glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(width, height); char title[32]; sprintf(title, "TestBed2D"); mainWindow = glutCreateWindow(title); //! Init App if(!g_pApp->Init(argc, argv)) { DestroyApp(); return 1; } glutDisplayFunc(LogicLoop); GLUI_Master.set_glutReshapeFunc(Resize); GLUI_Master.set_glutKeyboardFunc(Keyboard); GLUI_Master.set_glutKeyboardUpFunc(KeyboardUp); GLUI_Master.set_glutSpecialFunc(KeyboardSpecial); GLUI_Master.set_glutSpecialUpFunc(KeyboardSpecialUp); GLUI_Master.set_glutMouseFunc(Mouse); #ifdef FREEGLUT glutMouseWheelFunc(MouseWheel); #endif glutMotionFunc(MouseMotion); //! ÃüÁîÐÐstart glui = GLUI_Master.create_glui_subwindow( mainWindow, GLUI_SUBWINDOW_BOTTOM ); pkCmd = new GLUI_CommandLine(glui, "Cmd", NULL, 1, CmdLineCallBack); pkCmd->set_w(300); //! ÃüÁîÐÐend // Use a timer to control the frame rate. glutTimerFunc(timerPeriod, Timer, 0); lastTime = GetTickCount(); glutMainLoop(); return 0; }
void CALLBACK RVExtension(char *output, int outputSize, const char* function) { if (!gApp) { gApp = CreateApp(); if (!gApp) //error during creation ExitProcess(1); } try { gApp->callExtension(function, output, outputSize); } catch(const HiveExtApp::ServerShutdownException&) { ExtStartup::ProcessShutdown(); } }
int main() { const int width = 256; const int height = 256; const TCHAR* wndClassName = _T("DemoEffectWindowClass"); WNDCLASS wndClass = { 0 }; wndClass.style = 0; wndClass.lpfnWndProc = WindowProc; wndClass.hInstance = GetModuleHandle(NULL); wndClass.lpszClassName = wndClassName; RegisterClass(&wndClass); const auto hwnd = CreateWindow(wndClassName, _T("Demo Effect Challenge"), WS_OVERLAPPED, CW_USEDEFAULT, 0, 2 * width, 2 * height, GetDesktopWindow(), NULL, GetModuleHandle(NULL), NULL); ShowWindow(hwnd, SW_SHOWNORMAL); auto app = CreateApp(hwnd, width, height); MSG msg = { 0 }; do { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { RECT windowRect; GetWindowRect(hwnd, &windowRect); POINT cursorPos; GetCursorPos(&cursorPos); int mouseX = cursorPos.x - windowRect.left; int mouseY = cursorPos.y - windowRect.top; app->Update(mouseButtonDown, mouseX, mouseY); } } while (msg.message != WM_QUIT); return 0; }
ExampleUI::ExampleUI() { app = CreateApp(); CWindowPtr window = CreateWindow(); app->AddWindow(window); CViewPtr view = CreateView("canvas"); CViewPtr grayView = CreateView(CAttributes() .Set("name", "grayView") .Set("x1", 0) .Set("y1", 0) .Set("width", "100%") .Set("height", "100%") .Set("backgroundColour", COLOUR_GREY)); view->AddChild(grayView); // buttons CButtonPtr button1 = CreateButton(CAttributes() .Set("name", "Button1") .Set("caption", "Query Shop") .Set("x1", "5%") .Set("y1", "5%") .Set("alignW", "left") .Set("visible", true) ); button1->SetEventHandler("click", (void*)this, &OnButton1Click); CButtonPtr button2 = CreateButton(CAttributes() .Set("name", "Button2") .Set("caption", "Restore Purchases") .Set("x1", "5%") .Set("y1", "15%") .Set("alignW", "left") .Set("visible", true) ); button2->SetEventHandler("click", (void*)this, &OnButton2Click); CButtonPtr button3 = CreateButton(CAttributes() .Set("name", "Button3") .Set("caption", "Purchase fluidtest.100coins") .Set("x1", "50%") .Set("y1", "5%") .Set("alignW", "left") .Set("visible", true) ); button3->SetEventHandler("click", (void*)this, &OnButton3Click); CButtonPtr button4 = CreateButton(CAttributes() .Set("name", "Button4") .Set("caption", "Consume fluidtest.100coins") .Set("x1", "50%") .Set("y1", "15%") .Set("alignW", "left") .Set("visible", true) ); button4->SetEventHandler("click", (void*)this, &OnButton4Click); // text fields statusText = CreateLabel(CAttributes() .Set("caption","") .Set("x1", "5%") .Set("x2", "95%") .Set("y1", "60%") .Set("height","10%") .Set("alignW","left") ); animatingText = CreateLabel(CAttributes() .Set("caption","... Some Animating Text ...") .Set("x1", "5%") .Set("x2", "95%") .Set("y1", "70%") .Set("height","10%") .Set("alignW","left") ); consumableText = CreateLabel(CAttributes() .Set("caption","") .Set("x1", "5%") .Set("x2", "95%") .Set("y1", "50%") .Set("height","10%") .Set("alignW","left") ); // log list box logText = CreateListBox(CAttributes() .Set("x1", "5%") .Set("x2", "95%") .Set("y1", "80%") .Set("alignW","left") ); logText->SetEventHandler("selectitem",(void*)this,&ListBoxSelect); listBoxItems.AddString(CString("View Log")); logText->SetAttribute("listBoxItems",listBoxItems); view->AddChild(button1); buttons.push_back(button1); view->AddChild(button2); buttons.push_back(button2); view->AddChild(button3); buttons.push_back(button3); view->AddChild(button4); buttons.push_back(button4); view->AddChild(statusText); view->AddChild(animatingText); view->AddChild(consumableText); view->AddChild(logText); //view->AddChild(userNameText); SetStatusText(""); window->SetChild(view); app->ShowWindow(window); }
STATIC APIRET ReadINI(PXINI pXIni) // in: profile opened with xprfOpenProfile { APIRET arc; FILESTATUS3 fs3; if (!(arc = DosQueryFileInfo(pXIni->hFile, FIL_STANDARD, &fs3, sizeof(fs3)))) { PBYTE pbFileData; if (!(pbFileData = (PBYTE)malloc(fs3.cbFile))) arc = ERROR_NOT_ENOUGH_MEMORY; else { ULONG ulSet = 0; if (!(arc = DosSetFilePtr(pXIni->hFile, 0, FILE_BEGIN, &ulSet))) { ULONG cbRead = 0; if (!(arc = DosRead(pXIni->hFile, pbFileData, fs3.cbFile, &cbRead))) { if (cbRead != fs3.cbFile) arc = ERROR_NO_DATA; else { PINIFILE_HEADER pHeader = (PINIFILE_HEADER)pbFileData; if (pHeader->magic == 0xFFFFFFFF) { ULONG ulAppOfs = pHeader->offFirstApp; // create-applications loop while ((ulAppOfs) && (!arc)) { // application struct PINIFILE_APP pApp = (PINIFILE_APP)(pbFileData + ulAppOfs); ULONG ulKeysOfs = pApp->offFirstKeyInApp; PXINIAPPDATA pIniApp; if (arc = CreateApp(pXIni, (PCHAR)(pbFileData + pApp->offAppName), &pIniApp)) break; // create-keys loop while ((ulKeysOfs) && (!arc)) { PINIFILE_KEY pKey = (PINIFILE_KEY)(pbFileData + ulKeysOfs); PXINIKEYDATA pIniKey; if (arc = CreateKey(pIniApp, (PSZ)(pbFileData + pKey->offKeyName), (PBYTE)(pbFileData + pKey->offKeyData), pKey->lenKeyData, &pIniKey)) break; // next key; can be null ulKeysOfs = pKey->offNextKeyInApp; } // next application; can be null ulAppOfs = pApp->offNextApp; } } } } } free(pbFileData); } } return arc; }
APIRET xprfWriteProfileData(PXINI pXIni, // in: profile opened with xprfOpenProfile const char *pcszApp, // in: application name const char *pcszKey, // in: key name or NULL PVOID pData, // in: data to write or NULL ULONG ulDataLen) // in: sizeof(*pData) or null { APIRET arc = NO_ERROR; if ( (!pXIni) || (memcmp(pXIni->acMagic, XINI_MAGIC_BYTES, sizeof(XINI_MAGIC_BYTES))) ) arc = ERROR_INVALID_PARAMETER; else { // check if application exists PXINIAPPDATA pAppData; if (FindApp(pXIni, pcszApp, &pAppData)) // not found: pAppData = NULL; // now check: does caller want entire application deleted? if (!pcszKey) { // yes, delete application: did we find it? if (pAppData) { // yes: kill that FreeApp(pAppData); // and remove from list lstRemoveItem(&pXIni->llApps, pAppData); // rewrite profile on close pXIni->fDirty = TRUE; } // else application doesn't exist: // nothing to do return NO_ERROR } else { // caller has specified key: // does caller want a key to be deleted? if (!ulDataLen) { // yes: delete key: if (pAppData) { // app exists: FreeKeyIfExists(pXIni, pAppData, (PCHAR)pcszKey); } // else app doesn't even exist: // nothing to do, return NO_ERROR } else { // key and data specified: let's add something... if (!pAppData) // app doesn't exist yet: // create arc = CreateApp(pXIni, pcszApp, &pAppData); if (!arc) { // found or created app: // delete existing key if it exists PXINIKEYDATA pKeyData; FreeKeyIfExists(pXIni, pAppData, (PCHAR)pcszKey); // now create new key if (!(arc = CreateKey(pAppData, pcszKey, (PBYTE)pData, ulDataLen, &pKeyData))) // mark as dirty pXIni->fDirty = TRUE; } } } } return arc; }