1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
BOOL CALLBACK CEmuleLinkInjectApp::SearchEmuleLinkInjectWindow( HWND hWnd, LPARAM lParam )
{
DWORD dwMsgResult;
LRESULT lResult = ::SendMessageTimeout( hWnd, UWM_ARE_YOU_EMULELINKINJECT, 0, 0, SMTO_BLOCK | SMTO_ABORTIFHUNG, 10000, &dwMsgResult);
if( lResult == NULL )
return TRUE;
if( dwMsgResult == UWM_ARE_YOU_EMULELINKINJECT )
{
HWND* target = (HWND*)lParam;
*target = hWnd;
return FALSE;
}
return TRUE;
}
void CCustumCommandLineInfo::ParseParam(const TCHAR* pszParam,BOOL bFlag,BOOL bLast)
{
for (int i = 1; i < __argc; i++)
{
LPCTSTR pszParam = __targv[i];
if (pszParam[0] == _T('-') || pszParam[0] == _T('/'))
{
pszParam++;
if ( strcmp(pszParam, "WinStart") == 0 )
EmuleLinkInjectOptions->bHideAppOnStartup = true;
else
EmuleLinkInjectOptions->bHideAppOnStartup = false;
if ( strcmp(pszParam, "AddFile") == 0)
AfxMessageBox( "Do you want Add file ?", MB_ICONQUESTION | MB_YESNO);
}
}
}
BOOL CEmuleLinkInjectApp::GetEmuleLinkInjectRunning( void )
{
// Parse command line for standard shell commands, DDE, file open
CCustumCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
HWND maininst = NULL;
bool bAlreadyRunning ;
m_hMutexOneInstance = ::CreateMutex( NULL, FALSE, _T(EMULELINKINJECT_GUID) );
bAlreadyRunning = ( ::GetLastError() == ERROR_ALREADY_EXISTS ||::GetLastError() == ERROR_ACCESS_DENIED);
if ( bAlreadyRunning )
EnumWindows(SearchEmuleLinkInjectWindow, (LPARAM)&maininst);
CString command( AfxGetApp()->m_lpCmdLine );
if ( !command.IsEmpty() )
{
sendstruct.cbData = ( command.GetLength() + 1) * sizeof( TCHAR );
sendstruct.lpData = command.GetBuffer();
sendstruct.dwData = ( Function->VerifyLink(command, false) ) ? OP_ED2KLINK : OP_ECOMMAND;
if ( maininst )
{
SendMessage( maininst, WM_COPYDATA, (WPARAM)0, (LPARAM) (PCOPYDATASTRUCT) &sendstruct);
returntrue;
}
else
{
ProcessShellCommand(cmdInfo);
AfxGetMainWnd()->SendMessage( WM_COPYDATA, (WPARAM)0, (LPARAM) (PCOPYDATASTRUCT) &sendstruct);
returnfalse;
}
}
// Dispatch commands specified on the command line. Will return FALSE if
// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
ProcessShellCommand(cmdInfo);
return ( maininst || bAlreadyRunning);
}
// CEmuleLinkInjectApp initialization
BOOL CEmuleLinkInjectApp::InitInstance()
{
// InitCommonControls() 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.
InitCommonControls();
CWinApp::InitInstance();
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
// 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(""));
LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CEmuleLinkInjectDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CEmuleLinkInjectView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
pendinglink = 0;
if ( GetEmuleLinkInjectRunning() )
{
return FALSE;
}
m_pMainWnd->SetIcon( ::LoadIcon( m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME)), TRUE );
Function->LoadOptions();
Function->HideUnHideApplication( m_pMainWnd, (EmuleLinkInjectOptions->bAppWindowsStart || EmuleLinkInjectOptions->bHideAppOnStartup) );
COpenInternet OpenInternet;
if ( OpenInternet.GetSession() == NULL )
{
EmuleLinkInjectVariableApp->bConnectToEmuleState = false;
}
/*
// The one and only window has been initialized, so show and update it
if ( (EmuleLinkInjectOptions->bAppWindowsStart || EmuleLinkInjectOptions->bHideAppOnStartup) )
m_pMainWnd->ShowWindow(SW_HIDE);
else
m_pMainWnd->ShowWindow(SW_SHOW);
*/
m_pMainWnd->UpdateWindow();
// call DragAcceptFiles only if there's a suffix
// In an SDI app, this should occur after ProcessShellCommand
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
return TRUE;
}
|