// The ctor. QsciScintillaBase::QsciScintillaBase(QWidget *parent) : QAbstractScrollArea(parent), preeditPos(-1), preeditNrBytes(0) #if QT_VERSION >= 0x050000 , clickCausedFocus(false) #endif { connect(verticalScrollBar(), SIGNAL(valueChanged(int)), SLOT(handleVSb(int))); connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), SLOT(handleHSb(int))); setAcceptDrops(true); setFocusPolicy(Qt::WheelFocus); setAttribute(Qt::WA_KeyCompression); setAttribute(Qt::WA_InputMethodEnabled); #if QT_VERSION >= 0x050100 setInputMethodHints( Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText|Qt::ImhMultiLine); #elif QT_VERSION >= 0x040600 setInputMethodHints(Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText); #endif viewport()->setBackgroundRole(QPalette::Base); viewport()->setMouseTracking(true); //viewport()->setAttribute(Qt::WA_NoSystemBackground); //viewport()->setAutoFillBackground(false); //viewport()->setAttribute(Qt::WA_OpaquePaintEvent); // QPainter p( viewport() ); // p.setCompositionMode( QPainter::CompositionMode_Clear ); // p.fillRect( viewport()->rect(), Qt::transparent ); triple_click.setSingleShot(true); #if (QT_VERSION >= 0x040200 && QT_VERSION < 0x050000 && defined(Q_OS_MAC)) || (QT_VERSION >= 0x050200 && defined(Q_OS_OSX)) initialiseRectangularPasteboardMime(); #endif sci = new QsciScintillaQt(this); SendScintilla(SCI_SETCARETPERIOD, QApplication::cursorFlashTime() / 2); // Make sure the lexers are linked in. if (!lexersLinked) { Scintilla_LinkLexers(); lexersLinked = true; } QClipboard *cb = QApplication::clipboard(); if (cb->supportsSelection()) connect(cb, SIGNAL(selectionChanged()), SLOT(handleSelection())); // Add it to the pool. poolList.append(this); }
FireFly::FireFly(HINSTANCE instance, HWND parent) : instance(instance), parent(parent), lang(*this) { INITCOMMONCONTROLSEX icce; icce.dwSize = sizeof(icce); // We need tabs, tooltips, link controls icce.dwICC = ICC_STANDARD_CLASSES | ICC_WIN95_CLASSES | ICC_LINK_CLASS; InitCommonControlsEx(&icce); Scintilla_RegisterClasses(this->instance); Scintilla_LinkLexers(); }
// The ctor. QsciScintillaBase::QsciScintillaBase(QWidget *parent, const char *name, WFlags f) : QWidget(parent, name, f) { QGridLayout *layout = new QGridLayout(this, 2, 2); txtarea = new QWidget(this, 0, WRepaintNoErase|WResizeNoErase); txtarea->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); txtarea->setMouseTracking(true); txtarea->setAcceptDrops(true); txtarea->setFocusPolicy(WheelFocus); txtarea->setFocusProxy(this); layout->addWidget(txtarea, 0, 0); vsb = new QScrollBar(Vertical, this); layout->addWidget(vsb, 0, 1); connect(vsb, SIGNAL(valueChanged(int)), SLOT(handleVSb(int))); hsb = new QScrollBar(Horizontal, this); layout->addWidget(hsb, 1, 0); connect(hsb, SIGNAL(valueChanged(int)), SLOT(handleHSb(int))); txtarea->installEventFilter(this); setFocusPolicy(WheelFocus); // FIXME: QMacPasteboardMime isn't in Qt v5 yet. #if QT_VERSION >= 0x040200 && defined(Q_OS_MAC) && QT_VERSION < 0x050000 RectangularPasteboardMime::initialise(); #endif sci = new QsciScintillaQt(this); SendScintilla(SCI_SETCARETPERIOD, QApplication::cursorFlashTime() / 2); // Make sure the lexers are linked in. if (!lexersLinked) { Scintilla_LinkLexers(); lexersLinked = true; } QClipboard *cb = QApplication::clipboard(); if (cb->supportsSelection()) connect(cb, SIGNAL(selectionChanged()), SLOT(handleSelection())); // Add it to the pool. poolList.append(this); }
// The ctor. QsciScintillaBase::QsciScintillaBase(QWidget *parent) : QAbstractScrollArea(parent) { connect(verticalScrollBar(), SIGNAL(valueChanged(int)), SLOT(handleVSb(int))); connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), SLOT(handleHSb(int))); setAcceptDrops(true); setFocusPolicy(Qt::WheelFocus); setAttribute(Qt::WA_KeyCompression); viewport()->setBackgroundRole(QPalette::Base); viewport()->setMouseTracking(true); viewport()->setAttribute(Qt::WA_NoSystemBackground); triple_click.setSingleShot(true); sci = new ScintillaQt(this); curseurs = new QMap<int, Curseur*>; lockedLines = new QList<int>; SendScintilla(SCI_SETCARETPERIOD, QApplication::cursorFlashTime() / 2); // Make sure the lexers are linked in. if (!lexersLinked) { Scintilla_LinkLexers(); lexersLinked = true; } QClipboard *cb = QApplication::clipboard(); if (cb->supportsSelection()) connect(cb, SIGNAL(selectionChanged()), SLOT(handleSelection())); // Add it to the pool. poolList.append(this); }
int main() { RENDERER_SETTINGS settings; settings.bVsync = false; #ifdef _DEBUG settings.nWidth = 1280; settings.nHeight = 720; settings.windowMode = RENDERER_WINDOWMODE_WINDOWED; #else settings.nWidth = 1920; settings.nHeight = 1080; settings.windowMode = RENDERER_WINDOWMODE_FULLSCREEN; if (!Renderer::OpenSetupDialog( &settings )) return -1; #endif if (!Renderer::Open( &settings )) { printf("Renderer::Open failed\n"); return -1; } if (!FFT::Open()) { printf("FFT::Open() failed, continuing anyway...\n"); //return -1; } if (!MIDI::Open()) { printf("MIDI::Open() failed, continuing anyway...\n"); //return -1; } std::map<std::string,Renderer::Texture*> textures; std::map<int,std::string> midiRoutes; SHADEREDITOR_OPTIONS options; options.nFontSize = 16; #ifdef _WIN32 options.sFontPath = "c:\\Windows\\Fonts\\cour.ttf"; #elif __APPLE__ options.sFontPath = "/Library/Fonts/Courier New.ttf"; #else options.sFontPath = "/usr/share/fonts/corefonts/cour.ttf"; #endif options.nOpacity = 0xC0; options.bUseSpacesForTabs = true; options.nTabSize = 2; options.bVisibleWhitespace = false; int nDebugOutputHeight = 200; int nTexPreviewWidth = 64; float fFFTSmoothingFactor = 0.9f; // higher value, smoother FFT char szConfig[65535]; FILE * fConf = fopen("config.json","rb"); if (fConf) { printf("Config file found, parsing...\n"); memset( szConfig, 0, 65535 ); int n = fread( szConfig, 1, 65535, fConf ); fclose(fConf); jsonxx::Object o; o.parse( szConfig ); if (o.has<jsonxx::Object>("rendering")) { if (o.get<jsonxx::Object>("rendering").has<jsonxx::Number>("fftSmoothFactor")) fFFTSmoothingFactor = o.get<jsonxx::Object>("rendering").get<jsonxx::Number>("fftSmoothFactor"); } if (o.has<jsonxx::Object>("textures")) { printf("Loading textures...\n"); std::map<std::string, jsonxx::Value*> tex = o.get<jsonxx::Object>("textures").kv_map(); for (std::map<std::string, jsonxx::Value*>::iterator it = tex.begin(); it != tex.end(); it++) { char * fn = (char*)it->second->string_value_->c_str(); printf("* %s...\n",fn); Renderer::Texture * tex = Renderer::CreateRGBA8TextureFromFile( fn ); if (!tex) { printf("Renderer::CreateRGBA8TextureFromFile(%s) failed\n",fn); return -1; } textures.insert( std::make_pair( it->first, tex ) ); } } if (o.has<jsonxx::Object>("font")) { if (o.get<jsonxx::Object>("font").has<jsonxx::Number>("size")) options.nFontSize = o.get<jsonxx::Object>("font").get<jsonxx::Number>("size"); if (o.get<jsonxx::Object>("font").has<jsonxx::String>("file")) options.sFontPath = o.get<jsonxx::Object>("font").get<jsonxx::String>("file"); } if (o.has<jsonxx::Object>("gui")) { if (o.get<jsonxx::Object>("gui").has<jsonxx::Number>("outputHeight")) nDebugOutputHeight = o.get<jsonxx::Object>("gui").get<jsonxx::Number>("outputHeight"); if (o.get<jsonxx::Object>("gui").has<jsonxx::Number>("texturePreviewWidth")) nTexPreviewWidth = o.get<jsonxx::Object>("gui").get<jsonxx::Number>("texturePreviewWidth"); if (o.get<jsonxx::Object>("gui").has<jsonxx::Number>("opacity")) options.nOpacity = o.get<jsonxx::Object>("gui").get<jsonxx::Number>("opacity"); if (o.get<jsonxx::Object>("gui").has<jsonxx::Boolean>("spacesForTabs")) options.bUseSpacesForTabs = o.get<jsonxx::Object>("gui").get<jsonxx::Boolean>("spacesForTabs"); if (o.get<jsonxx::Object>("gui").has<jsonxx::Number>("tabSize")) options.nTabSize = o.get<jsonxx::Object>("gui").get<jsonxx::Number>("tabSize"); if (o.get<jsonxx::Object>("gui").has<jsonxx::Boolean>("visibleWhitespace")) options.bVisibleWhitespace = o.get<jsonxx::Object>("gui").get<jsonxx::Boolean>("visibleWhitespace"); } if (o.has<jsonxx::Object>("midi")) { std::map<std::string, jsonxx::Value*> tex = o.get<jsonxx::Object>("midi").kv_map(); for (std::map<std::string, jsonxx::Value*>::iterator it = tex.begin(); it != tex.end(); it++) { midiRoutes.insert( std::make_pair( it->second->number_value_, it->first ) ); } } } Renderer::Texture * texFFT = Renderer::Create1DR32Texture( FFT_SIZE ); Renderer::Texture * texFFTSmoothed = Renderer::Create1DR32Texture( FFT_SIZE ); bool shaderInitSuccessful = false; char szShader[65535]; char szError[4096]; FILE * f = fopen(Renderer::defaultShaderFilename,"rb"); if (f) { printf("Loading last shader...\n"); memset( szShader, 0, 65535 ); int n = fread( szShader, 1, 65535, f ); fclose(f); if (Renderer::ReloadShader( szShader, strlen(szShader), szError, 4096 )) { printf("Last shader works fine.\n"); shaderInitSuccessful = true; } } if (!shaderInitSuccessful) { printf("No valid last shader found, falling back to default...\n"); std::string sDefShader = Renderer::defaultShader; std::vector<std::string> tokens; for (std::map<std::string, Renderer::Texture*>::iterator it = textures.begin(); it != textures.end(); it++) tokens.push_back(it->first); ReplaceTokens(sDefShader, "{%textures:begin%}", "{%textures:name%}", "{%textures:end%}", tokens); tokens.clear(); for (std::map<int,std::string>::iterator it = midiRoutes.begin(); it != midiRoutes.end(); it++) tokens.push_back(it->second); ReplaceTokens(sDefShader, "{%midi:begin%}", "{%midi:name%}", "{%midi:end%}", tokens); strncpy( szShader, sDefShader.c_str(), 65535 ); if (!Renderer::ReloadShader( szShader, strlen(szShader), szError, 4096 )) { printf("Default shader compile failed:\n"); puts(szError); assert(0); } } Misc::InitKeymaps(); #ifdef SCI_LEXER Scintilla_LinkLexers(); #endif Scintilla::Surface * surface = Scintilla::Surface::Allocate( SC_TECHNOLOGY_DEFAULT ); surface->Init( NULL ); int nMargin = 20; bool bTexPreviewVisible = true; options.rect = Scintilla::PRectangle( nMargin, nMargin, settings.nWidth - nMargin - nTexPreviewWidth - nMargin, settings.nHeight - nMargin * 2 - nDebugOutputHeight ); ShaderEditor mShaderEditor( surface ); mShaderEditor.Initialise( options ); mShaderEditor.SetText( szShader ); options.rect = Scintilla::PRectangle( nMargin, settings.nHeight - nMargin - nDebugOutputHeight, settings.nWidth - nMargin - nTexPreviewWidth - nMargin, settings.nHeight - nMargin ); ShaderEditor mDebugOutput( surface ); mDebugOutput.Initialise( options ); mDebugOutput.SetText( "" ); mDebugOutput.SetReadOnly(true); static float fftData[FFT_SIZE]; memset(fftData, 0, sizeof(float) * FFT_SIZE); static float fftDataSmoothed[FFT_SIZE]; memset(fftDataSmoothed, 0, sizeof(float) * FFT_SIZE); // if we want to do some sort of frame capturing code // (for e.g. sending frames through the network) // we'd do it here, and then below. unsigned int * pFrameContents = NULL;// new unsigned int[ settings.nWidth * settings.nHeight ]; bool bShowGui = true; Timer::Start(); float fNextTick = 0.1; while (!Renderer::WantsToQuit()) { float time = Timer::GetTime() / 1000.0; // seconds Renderer::StartFrame(); for(int i=0; i<Renderer::mouseEventBufferCount; i++) { if (bShowGui) { switch (Renderer::mouseEventBuffer[i].eventType) { case Renderer::MOUSEEVENTTYPE_MOVE: mShaderEditor.ButtonMovePublic( Scintilla::Point( Renderer::mouseEventBuffer[i].x, Renderer::mouseEventBuffer[i].y ) ); break; case Renderer::MOUSEEVENTTYPE_DOWN: mShaderEditor.ButtonDown( Scintilla::Point( Renderer::mouseEventBuffer[i].x, Renderer::mouseEventBuffer[i].y ), time * 1000, false, false, false ); break; case Renderer::MOUSEEVENTTYPE_UP: mShaderEditor.ButtonUp( Scintilla::Point( Renderer::mouseEventBuffer[i].x, Renderer::mouseEventBuffer[i].y ), time * 1000, false ); break; } } } Renderer::mouseEventBufferCount = 0; for(int i=0; i<Renderer::keyEventBufferCount; i++) { if (Renderer::keyEventBuffer[i].scanCode == 283) // F2 { if (bTexPreviewVisible) { mShaderEditor.SetPosition( Scintilla::PRectangle( nMargin, nMargin, settings.nWidth - nMargin, settings.nHeight - nMargin * 2 - nDebugOutputHeight ) ); mDebugOutput .SetPosition( Scintilla::PRectangle( nMargin, settings.nHeight - nMargin - nDebugOutputHeight, settings.nWidth - nMargin, settings.nHeight - nMargin ) ); bTexPreviewVisible = false; } else { mShaderEditor.SetPosition( Scintilla::PRectangle( nMargin, nMargin, settings.nWidth - nMargin - nTexPreviewWidth - nMargin, settings.nHeight - nMargin * 2 - nDebugOutputHeight ) ); mDebugOutput .SetPosition( Scintilla::PRectangle( nMargin, settings.nHeight - nMargin - nDebugOutputHeight, settings.nWidth - nMargin - nTexPreviewWidth - nMargin, settings.nHeight - nMargin ) ); bTexPreviewVisible = true; } } else if (Renderer::keyEventBuffer[i].scanCode == 286 || (Renderer::keyEventBuffer[i].ctrl && Renderer::keyEventBuffer[i].scanCode == 'r')) // F5 { mShaderEditor.GetText(szShader,65535); if (Renderer::ReloadShader( szShader, strlen(szShader), szError, 4096 )) { FILE * f = fopen(Renderer::defaultShaderFilename,"wb"); fwrite( szShader, strlen(szShader), 1, f ); fclose(f); mDebugOutput.SetText( "" ); } else { mDebugOutput.SetText( szError ); } } else if (Renderer::keyEventBuffer[i].scanCode == 292) // F11 { bShowGui = !bShowGui; } else if (bShowGui) { bool consumed = false; if (Renderer::keyEventBuffer[i].scanCode) { mShaderEditor.KeyDown( iswalpha(Renderer::keyEventBuffer[i].scanCode) ? towupper(Renderer::keyEventBuffer[i].scanCode) : Renderer::keyEventBuffer[i].scanCode, Renderer::keyEventBuffer[i].shift, Renderer::keyEventBuffer[i].ctrl, Renderer::keyEventBuffer[i].alt, &consumed); } if (!consumed && Renderer::keyEventBuffer[i].character) { char utf8[5] = {0,0,0,0,0}; wchar_t utf16[2] = {Renderer::keyEventBuffer[i].character, 0}; Scintilla::UTF8FromUTF16(utf16, 1, utf8, 4 * sizeof(char)); mShaderEditor.AddCharUTF(utf8, strlen(utf8)); } } } Renderer::keyEventBufferCount = 0; Renderer::SetShaderConstant( "fGlobalTime", time ); Renderer::SetShaderConstant( "v2Resolution", settings.nWidth, settings.nHeight ); for (std::map<int,std::string>::iterator it = midiRoutes.begin(); it != midiRoutes.end(); it++) { Renderer::SetShaderConstant( (char*)it->second.c_str(), MIDI::GetCCValue( it->first ) ); } if (FFT::GetFFT(fftData)) { Renderer::UpdateR32Texture( texFFT, fftData ); for ( int i = 0; i < FFT_SIZE; i++ ) { fftDataSmoothed[i] = fftDataSmoothed[i] * fFFTSmoothingFactor + (1 - fFFTSmoothingFactor) * fftData[i]; } Renderer::UpdateR32Texture( texFFTSmoothed, fftDataSmoothed ); } Renderer::SetShaderTexture( "texFFT", texFFT ); Renderer::SetShaderTexture( "texFFTSmoothed", texFFTSmoothed ); for (std::map<std::string, Renderer::Texture*>::iterator it = textures.begin(); it != textures.end(); it++) { Renderer::SetShaderTexture( (char*)it->first.c_str(), it->second ); } Renderer::RenderFullscreenQuad(); Renderer::StartTextRendering(); if (bShowGui) { if (time > fNextTick) { mShaderEditor.Tick(); mDebugOutput.Tick(); fNextTick = time + 0.1; } mShaderEditor.Paint(); mDebugOutput.Paint(); Renderer::SetTextRenderingViewport( Scintilla::PRectangle(0,0,Renderer::nWidth,Renderer::nHeight) ); if (bTexPreviewVisible) { int y1 = nMargin; int x1 = settings.nWidth - nMargin - nTexPreviewWidth; int x2 = settings.nWidth - nMargin; for (std::map<std::string, Renderer::Texture*>::iterator it = textures.begin(); it != textures.end(); it++) { int y2 = y1 + nTexPreviewWidth * (it->second->height / (float)it->second->width); Renderer::BindTexture( it->second ); Renderer::RenderQuad( Renderer::Vertex( x1, y1, 0xccFFFFFF, 0.0, 0.0 ), Renderer::Vertex( x2, y1, 0xccFFFFFF, 1.0, 0.0 ), Renderer::Vertex( x2, y2, 0xccFFFFFF, 1.0, 1.0 ), Renderer::Vertex( x1, y2, 0xccFFFFFF, 0.0, 1.0 ) ); surface->DrawTextNoClip( Scintilla::PRectangle(x1,y1,x2,y2), *mShaderEditor.GetTextFont(), y2 - 5.0, it->first.c_str(), it->first.length(), 0xffFFFFFF, 0x00000000); y1 = y2 + nMargin; } } char szLayout[255]; Misc::GetKeymapName(szLayout); std::string sHelp = "F2 - toggle texture preview F5 or Ctrl-R - recompile shader F11 - hide GUI Current keymap: "; sHelp += szLayout; surface->DrawTextNoClip( Scintilla::PRectangle(20,Renderer::nHeight - 20,100,Renderer::nHeight), *mShaderEditor.GetTextFont(), Renderer::nHeight - 5.0, sHelp.c_str(), sHelp.length(), 0x80FFFFFF, 0x00000000); } Renderer::EndTextRendering(); Renderer::EndFrame(); if (pFrameContents) { if (Renderer::GrabFrame( pFrameContents )) { // send framebuffer through network here. } } } if (pFrameContents) delete[] pFrameContents; delete surface; MIDI::Close(); FFT::Close(); Renderer::ReleaseTexture( texFFT ); Renderer::ReleaseTexture( texFFTSmoothed ); for (std::map<std::string, Renderer::Texture*>::iterator it = textures.begin(); it != textures.end(); it++) { Renderer::ReleaseTexture( it->second ); } Renderer::Close(); return 0; }
BOOL COngTVApp::InitInstance() { // customisation des barres d'outils non autorisée CMFCToolBar::SetCustomizeMode(FALSE); #ifdef SCINTILLA_DLL // Chargement de la DLL Scintilla : on va la chercher dans le repertoire de l'exe et nul part ailleurs // recuperation du path de l'exe char lpFilename[255]; memset(lpFilename,0,255); GetModuleFileName(NULL ,lpFilename, 255); std::string strSciLexerDllName = CPathMgr::ExtractPath(lpFilename); strSciLexerDllName = strSciLexerDllName + "\\SciLexer.dll"; m_hSciDLL = LoadLibrary(strSciLexerDllName.c_str()); if (NULL == m_hSciDLL) { // DLL scintilla non disponible => on ne pourra pas editer de scrip LUA } else { CVersion versionSciDLL(strSciLexerDllName); if (versionSciDLL.GetProductVersion() < std::string(EXPECTED_SCINTILLA_VERSION)) { // version de la DLL inferieur a la version attendue => on ne pourra pas editer de scrip LUA FreeLibrary(m_hSciDLL); m_hSciDLL = NULL; std::string strMsgError = "Dll min expected version : "EXPECTED_SCINTILLA_VERSION" obtained : "; strMsgError += versionSciDLL.GetProductVersion(); MessageBox(NULL, strMsgError.c_str(), "Unable to load SciLexer.dll", MB_ICONEXCLAMATION); } } #endif #ifdef TEST_ENGLISH // Pour forcer une langue ::SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),SORT_DEFAULT)); #endif // nettoyage des clefs de registres de la version precedente // si la version qui s'execute n'est pas identique a celle enregistree dans la base de registres // MFCFP = MFC Feature Pack => pour pouvoir faire cohabiter sur un même PC des versions antérieures à la 1.6.0 et des versions postérieures // a la 1.6.0 // avant la 1.6.0 => IHM basée sur UltimateToolbox et sauvegarde des caractéristiques des fenêtres à plat dans la base de registre // à partir de 1.6.0 => IHM basée sur MFC Feature Pack et sauvegarde des caractéristiques des fenêtres dans une arborescence de clefs // dans la base de registres // le nettoyage de la base de registres plantait si on essaiyait de revenir à une version < 1.6.0 => on différencie la clef de base std::string strReg = "\\CurrentUser\\Software\\" + m_versionInfos.GetCompanyName() + "\\" + m_versionInfos.GetProductName() + "MFCFP\\"; g_Registry.SetFullRegistryItem(strReg.c_str()); CString sVersion=g_Registry.GetStringValue(REGISTRY_KEY_VERSION); CString sProductVersion(m_versionInfos.GetProductVersion().c_str()); if (sVersion != sProductVersion) { DeleteRegTree(&g_Registry); } g_Registry.Close(); // Pour utilisation de RichEditCtrl AfxEnableControlContainer(); AfxInitRichEdit(); // InitCommonControlsEx() est requis sur Windows XP si le manifeste de l'application // spécifie l'utilisation de ComCtl32.dll version 6 ou ultérieure pour activer les // styles visuels. Dans le cas contraire, la création de fenêtres échouera. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // À définir pour inclure toutes les classes de contrôles communs à utiliser // dans votre application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); InitContextMenuManager(); InitShellManager(); InitKeyboardManager(); InitTooltipManager(); CMFCToolTipInfo ttParams; ttParams.m_bVislManagerTheme = TRUE; GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL, RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams); // enregistrement Scintilla #ifndef SCINTILLA_DLL Scintilla_RegisterClasses(AfxGetInstanceHandle()); Scintilla_LinkLexers(); #endif // Supprime pour la gestion multi-lingues // CWinAppEx::InitInstance(); // Initialisation standard // Si vous n'utilisez pas ces fonctionnalités et que vous souhaitez réduire la taille // de votre exécutable final, vous devez supprimer ci-dessous // les routines d'initialisation spécifiques dont vous n'avez pas besoin. // Changez la clé de Registre sous laquelle nos paramètres sont enregistrés // TODO : modifiez cette chaîne avec des informations appropriées, // telles que le nom de votre société ou organisation SetRegistryKey(m_versionInfos.GetCompanyName().c_str()); //First free the string allocated by MFC at CWinApp startup. //The string is allocated before InitInstance is called. free((void*)m_pszProfileName); //Change the name of the .INI file. //The CWinApp destructor will free the memory. // Ce nom est utilise pour la sauvegarde des parametres strReg = m_versionInfos.GetProductName() + "MFCFP"; m_pszProfileName = _tcsdup(strReg.c_str()); LoadStdProfileSettings(4); // Charge les options de fichier INI standard (y compris les derniers fichiers utilisés) // Inscrire les modèles de document de l'application. Ces modèles // lient les documents, fenêtres frame et vues entre eux // creation du manager de doc specifique afin de gerer specifiquement les repertoires // de sauvegarde des diffents documents. // cf http://www.codeguru.com/cpp/w-d/dislog/commondialogs/article.php/c1967 m_pDocManager = new COngTVDocManager; // Creation doc template pour les scripts LUA (uniquement si DLL scintilla disponible) if (NULL != m_hSciDLL) { m_pNewLuaDocTemplate = new CMultiDocTemplate( IDR_LUATYPE , RUNTIME_CLASS(CLuaDoc) , RUNTIME_CLASS(CLuaChildFrame) , RUNTIME_CLASS(CLuaView) ); if (!m_pNewLuaDocTemplate) return FALSE; AddDocTemplate(m_pNewLuaDocTemplate); } // Installe la police DINA HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(IDR_DINA), _T("DINA")); PVOID lpFont = LockResource(LoadResource(NULL, hRes)); DWORD dwSize = SizeofResource(NULL, hRes), cFonts = 0; m_hDinaFont = AddFontMemResourceEx(lpFont, dwSize, NULL, &cFonts); ASSERT(cFonts > 0); // crée la fenêtre frame MDI principale CMainFrame* pMainFrame = new CMainFrame; // On parse la ligne de commande CCmdLine cmdLine; cmdLine.SplitLine(__argc, __argv); // On indique le fichier de configuration ("" par defaut) std::string configFileName = cmdLine.GetSafeArgument("-cnx", 0, ""); pMainFrame->SetConfigFile(configFileName); m_pMainWnd = pMainFrame; if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME)) { delete pMainFrame; return FALSE; } // La fenêtre principale a été initialisée et peut donc être affichée et mise à jour pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); return TRUE; }
BOOL CKillDBGApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); //初始化Scintilla Scintilla_LinkLexers(); Scintilla_RegisterClasses(AfxGetApp()->m_hInstance); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization SetRegistryKey(_T("KillDBG")); // To create the main window, this code creates a new frame window // object and then sets it as the application's main window object //提升自身到 Debug Privilege HANDLE hProcess=GetCurrentProcess(); HANDLE hToken; BOOL bRet=FALSE; if (OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken)) { LUID luid; if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) { TOKEN_PRIVILEGES tp; tp.PrivilegeCount=1; tp.Privileges[0].Luid=luid; tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; if (AdjustTokenPrivileges(hToken, FALSE, &tp, NULL, (PTOKEN_PRIVILEGES)NULL, (PDWORD)NULL)) { bRet=(GetLastError() == ERROR_SUCCESS); } } CloseHandle(hToken); } if (!bRet) { MessageBox(NULL,_T("提升进程权限到SE_DEBUG_NAME失败,可能会导致部分进程无法调试"),NULL,MB_OK | MB_ICONWARNING); } //创建主窗口 CMainFrame* pFrame = new CMainFrame; if (!pFrame) return FALSE; m_pMainWnd = pFrame; // create and load the frame with its resources pFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,NULL); // The one and only window has been initialized, so show and update it pFrame->ShowWindow(SW_SHOW); pFrame->UpdateWindow(); // call DragAcceptFiles only if there's a suffix // In an SDI app, this should occur after ProcessShellCommand return TRUE; }