Creating a folder in %appdata%

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 13179 Views - Last Post: 19 August 2012 - 06:24 AM

#16 Lukee9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 15-August 12

Re: Creating a folder in %appdata%

Posted 19 August 2012 - 06:24 AM

View Postsnoopy11, on 18 August 2012 - 07:17 PM, said:

Ahh,

I found out how to get your current appdata path..

you have to use SHGetFolderPath

I have revised the code a little..

It should now do what you want..

On an aside there are many free install programs available

Why write your own ?

anyway...

Form1.h

#pragma once
#include <cstring>
#include <shlobj.h>
#pragma comment(lib, "shell32.lib")

namespace clrprogress {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::Security::AccessControl;
	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::TextBox^  textBox1;
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(13, 33);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(106, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Create Directory";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(11, 78);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(234, 20);
			this->textBox1->TabIndex = 1;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

              String^ text;
			  wchar_t szPath[MAX_PATH];
			  String^ Path;
                          ::SHGetFolderPath(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT,szPath);

			  text = L"\\My Games";
			  Path = gcnew String(szPath);
			  text = Path + text;
			  textBox1 -> Text = text;
			  DirectorySecurity^ Secure;
			  
			  System::IO::Directory::CreateDirectory(text,Secure);
			 }
	};
}






clrprogress.cpp




// clrprogress.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace clrprogress;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew Form1());
	return 0;
}



Thanks for taking the time to do this. Works now, program 100% working. Thanks :-)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2