Ejemplo n.º 1
0
//
//	How to process WM_DROPFILES
//
void HandleDropFiles(HWND hwnd, HDROP hDrop)
{
	TCHAR buf[MAX_PATH];
	
	if(DragQueryFile(hDrop, 0, buf, MAX_PATH))
	{
		TCHAR tmp[MAX_PATH];
		
		if(ResolveShortcut(buf, tmp, MAX_PATH))
			lstrcpy(buf,tmp);

		NeatpadOpenFile(hwnd, buf);
	}
	
	DragFinish(hDrop);
}
Ejemplo n.º 2
0
//
//	Entry-point for text-editor application
//
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int iShowCmd)
{
	MSG			msg;
	HACCEL		hAccel;
	TCHAR		**argv;
	int			argc;
	//TCHAR		*pszCmdlineFile = 0;
	TCHAR		arg[MAX_PATH];

	//
	// get the first commandline argument
	//
	TCHAR *pszCmdline = GetArg(GetCommandLineW(), arg, MAX_PATH);
	argv = GetArgvCommandLine(&argc);

	// check if we have any options
	if(pszCmdline && *pszCmdline == '-')
	{
		pszCmdline = GetArg(pszCmdline, arg, MAX_PATH);

		// do the user-account-control thing
		if(lstrcmpi(arg, _T("-uac")) == 0)
		{
			//return 0;
		}
		// image-file-execute-options
		else if(lstrcmpi(arg, _T("-ifeo")) == 0)
		{
			// skip notepad.exe
			pszCmdline = GetArg(pszCmdline, arg, MAX_PATH);
		}
		// unrecognised option
		else
		{
		}
	}


	// has a prior instance elevated us to admin in order to 
	// modify some system-wide settings in the registry?
	if(argv && argc == 4 && lstrcmpi(argv[1], _T("-uac")) == 0)
	{
		g_fAddToExplorer	= _ttoi(argv[2]);
		g_fReplaceNotepad	= _ttoi(argv[3]);

		if(SetExplorerContextMenu(g_fAddToExplorer) &&
			SetImageFileExecutionOptions(g_fReplaceNotepad))
		{
			SaveRegSysSettings();
			return 0;
		}
		else
		{
			return ERROR_ACCESS_DENIED;
		}
	}

	// default to the built-in resources
	g_hResourceModule = hInst;

	OleInitialize(0);

	// initialize window classes
	InitMainWnd();
	InitTextView();

	LoadRegSettings();

	// create the main window!
	g_hwndMain = CreateMainWnd();

	// open file specified on commmand line
	if(pszCmdline && *pszCmdline)
	{
		// check to see if it's a quoted filename
		if(*pszCmdline == '\"')
		{
			GetArg(pszCmdline, arg, MAX_PATH);
			pszCmdline = arg;
		}

		NeatpadOpenFile(g_hwndMain, pszCmdline);
		LoadFileData(pszCmdline, g_hwndMain);
	}
	// automatically create new document if none specified
	else
	{
		PostMessage(g_hwndMain, WM_COMMAND, IDM_FILE_NEW, 0);
	}

	ApplyRegSettings();
	ShowWindow(g_hwndMain, iShowCmd);

	//
	// load keyboard accelerator table
	//
	hAccel = LoadAccelerators(g_hResourceModule, MAKEINTRESOURCE(IDR_ACCELERATOR1));

	
	//
	// message-loop
	//
	while(GetMessage(&msg, NULL, 0, 0) > 0)
	{
		if(!TranslateAccelerator(g_hwndMain, hAccel, &msg))
		{
			if((!IsWindow(g_hwndSearchDlg) || !IsDialogMessage(g_hwndSearchDlg, &msg)))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
	}

	if(g_fSaveOnExit)
		SaveRegSettings();

	OleUninitialize();
	ExitProcess(0);
	return 0;
}