コード例 #1
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	HRESULT hResult;

	hResult = CoInitialize(NULL);

	if (SUCCEEDED(hResult))
	{
		IShellDispatch * pISD;

		hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pISD);

		if (SUCCEEDED(hResult) && NULL != pISD)
		{
			FILE * File = fopen(ParameterFilename, "rb");

			if (NULL == File)
			{
				// Perform the Taskbar operation
				pISD->TileVertically();

				// Create file
				File = fopen(ParameterFilename, "wb");
				if (NULL != File) fclose(File);
			}
			else
			{
				// Undo the last Taskbar operation
				pISD->UndoMinimizeALL();

				// Make sure the file is empty before removing it (as to not accidentally delete a user's valuable file)
				fseek(File, 0, SEEK_END); long FileSize = ftell(File); if (0 != FileSize) MessageBox(NULL, "Warning: The file 'OrganizeWindows_ShouldUndoNextTime' was not empty. When this program creates it, it should be empty.\n\nIt will not be deleted in case you have valuable information there. Please delete it yourself, or move this program into another folder that doesn't have a file with such name.", "OrganizeWindows", MB_ICONWARNING);
				fclose(File);
				if (0 == FileSize) remove(ParameterFilename);
			}

			pISD->Release();
		}

		CoUninitialize();
	}

	return EXIT_SUCCESS;
}