Creating a file

Hello,

I want to write a visual C++ program to create a script file for Autocad. A script file has the extension .scr

The goal is, to create the file, write information in it and close the file and save it at a specific location. How can I create the file? I have tried the CreateFile function but I can not make it work. I use the Visual C++ express version as a IDE.

The question that I have is: how does the function look like?
Which header files should I use and where should I put the include statement?

Could someone help me? I have tried many examples on the internet.






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// PDFScripper.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"
#include <Windows.h>
#include <stdio.h>
#include <tchar.h>
#include <WinBase.h>

using namespace PDFScripper;

[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;
}
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#pragma once

namespace PDFScripper {

	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 std;


	/// <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^  browse_btn;
	protected: 
	private: System::Windows::Forms::OpenFileDialog^  openFileDialog1;
	private: System::Windows::Forms::ListBox^  filenames_lb;
	private: System::Windows::Forms::GroupBox^  uitleg_groupbox;
	private: System::Windows::Forms::Label^  uitleg_label4;




	private: System::Windows::Forms::Label^  uitleg_label2;


	private: System::Windows::Forms::Label^  uitleg_label;
	private: System::Windows::Forms::Label^  uitleg_label5;
	private: System::Windows::Forms::Button^  clearalles_btn;
	private: System::Windows::Forms::Button^  locatie_btn;
	private: System::Windows::Forms::Label^  uitleg_label3;
	private: System::Windows::Forms::Label^  uitleg_label6;
	private: System::Windows::Forms::TextBox^  lisp_txtb;
	private: System::Windows::Forms::Button^  locatiescript_btn;
	private: System::Windows::Forms::FolderBrowserDialog^  folderBrowserDialog1;
	private: System::Windows::Forms::Label^  uitleg_label7;
	private: System::Windows::Forms::TextBox^  locatiescript_txtb;
	private: System::Windows::Forms::Button^  script_btn;
	private: System::Windows::Forms::Label^  uitleg_label8;



	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->browse_btn = (gcnew System::Windows::Forms::Button());
			this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
			this->filenames_lb = (gcnew System::Windows::Forms::ListBox());
			this->uitleg_groupbox = (gcnew System::Windows::Forms::GroupBox());
			this->script_btn = (gcnew System::Windows::Forms::Button());
			this->uitleg_label8 = (gcnew System::Windows::Forms::Label());
			this->locatiescript_btn = (gcnew System::Windows::Forms::Button());
			this->uitleg_label3 = (gcnew System::Windows::Forms::Label());
			this->locatie_btn = (gcnew System::Windows::Forms::Button());
			this->clearalles_btn = (gcnew System::Windows::Forms::Button());
			this->uitleg_label4 = (gcnew System::Windows::Forms::Label());
			this->uitleg_label2 = (gcnew System::Windows::Forms::Label());
			this->uitleg_label = (gcnew System::Windows::Forms::Label());
			this->uitleg_label5 = (gcnew System::Windows::Forms::Label());
			this->uitleg_label6 = (gcnew System::Windows::Forms::Label());
			this->lisp_txtb = (gcnew System::Windows::Forms::TextBox());
			this->folderBrowserDialog1 = (gcnew System::Windows::Forms::FolderBrowserDialog());
			this->uitleg_label7 = (gcnew System::Windows::Forms::Label());
			this->locatiescript_txtb = (gcnew System::Windows::Forms::TextBox());
			this->uitleg_groupbox->SuspendLayout();
			this->SuspendLayout();
			// 
			// browse_btn
			// 
			this->browse_btn->Location = System::Drawing::Point(6, 44);
			this->browse_btn->Name = L"browse_btn";
			this->browse_btn->Size = System::Drawing::Size(125, 23);
			this->browse_btn->TabIndex = 0;
			this->browse_btn->Text = L"Zoek bestanden";
			this->browse_btn->UseVisualStyleBackColor = true;
			this->browse_btn->Click += gcnew System::EventHandler(this, &Form1::browse_btn_Click);
			// 
			// openFileDialog1
			// 
			this->openFileDialog1->FileName = L"openFileDialog1";
			// 
			// filenames_lb
			// 
			this->filenames_lb->FormattingEnabled = true;
			this->filenames_lb->Location = System::Drawing::Point(12, 26);
			this->filenames_lb->Name = L"filenames_lb";
			this->filenames_lb->Size = System::Drawing::Size(444, 537);
			this->filenames_lb->TabIndex = 1;
			// 
			// uitleg_groupbox
			// 
			this->uitleg_groupbox->Controls->Add(this->script_btn);
			this->uitleg_groupbox->Controls->Add(this->uitleg_label8);
			this->uitleg_groupbox->Controls->Add(this->locatiescript_btn);
			this->uitleg_groupbox->Controls->Add(this->uitleg_label3);
			this->uitleg_groupbox->Controls->Add(this->locatie_btn);
			this->uitleg_groupbox->Controls->Add(this->clearalles_btn);
			this->uitleg_groupbox->Controls->Add(this->uitleg_label4);
			this->uitleg_groupbox->Controls->Add(this->uitleg_label2);
			this->uitleg_groupbox->Controls->Add(this->uitleg_label);
			this->uitleg_groupbox->Controls->Add(this->browse_btn);
			this->uitleg_groupbox->Location = System::Drawing::Point(980, 12);
			this->uitleg_groupbox->Name = L"uitleg_groupbox";
			this->uitleg_groupbox->Size = System::Drawing::Size(200, 565);
			this->uitleg_groupbox->TabIndex = 2;
			this->uitleg_groupbox->TabStop = false;
			this->uitleg_groupbox->Text = L"Controls";
			// 
			// script_btn
			// 
			this->script_btn->Location = System::Drawing::Point(6, 170);
			this->script_btn->Name = L"script_btn";
			this->script_btn->Size = System::Drawing::Size(125, 23);
			this->script_btn->TabIndex = 9;
			this->script_btn->Text = L"Maak script file";
			this->script_btn->UseVisualStyleBackColor = true;
			this->script_btn->Click += gcnew System::EventHandler(this, &Form1::script_btn_Click);
			// 
			// uitleg_label8
			// 
			this->uitleg_label8->AutoSize = true;
			this->uitleg_label8->Location = System::Drawing::Point(15, 154);
			this->uitleg_label8->Name = L"uitleg_label8";
			this->uitleg_label8->Size = System::Drawing::Size(41, 13);
			this->uitleg_label8->TabIndex = 8;
			this->uitleg_label8->Text = L"Stap 4:";
			// 
			// locatiescript_btn
			// 
			this->locatiescript_btn->Location = System::Drawing::Point(6, 128);
			this->locatiescript_btn->Name = L"locatiescript_btn";
			this->locatiescript_btn->Size = System::Drawing::Size(125, 23);
			this->locatiescript_btn->TabIndex = 7;
			this->locatiescript_btn->Text = L"Selecteer locatie script";
			this->locatiescript_btn->UseVisualStyleBackColor = true;
			this->locatiescript_btn->Click += gcnew System::EventHandler(this, &Form1::locatiescript_btn_Click);
Last edited on
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// 
			// uitleg_label3
			// 
			this->uitleg_label3->AutoSize = true;
			this->uitleg_label3->Location = System::Drawing::Point(15, 112);
			this->uitleg_label3->Name = L"uitleg_label3";
			this->uitleg_label3->Size = System::Drawing::Size(35, 13);
			this->uitleg_label3->TabIndex = 6;
			this->uitleg_label3->Text = L"Stap3";
			// 
			// locatie_btn
			// 
			this->locatie_btn->Location = System::Drawing::Point(6, 86);
			this->locatie_btn->Name = L"locatie_btn";
			this->locatie_btn->Size = System::Drawing::Size(125, 23);
			this->locatie_btn->TabIndex = 5;
			this->locatie_btn->Text = L"Selecteer locatie lisp";
			this->locatie_btn->UseVisualStyleBackColor = true;
			this->locatie_btn->Click += gcnew System::EventHandler(this, &Form1::convert_btn_Click);
			// 
			// clearalles_btn
			// 
			this->clearalles_btn->Location = System::Drawing::Point(6, 214);
			this->clearalles_btn->Name = L"clearalles_btn";
			this->clearalles_btn->Size = System::Drawing::Size(125, 23);
			this->clearalles_btn->TabIndex = 4;
			this->clearalles_btn->Text = L"Deselecteer alle items";
			this->clearalles_btn->UseVisualStyleBackColor = true;
			this->clearalles_btn->Click += gcnew System::EventHandler(this, &Form1::clearalles_btn_Click);
			// 
			// uitleg_label4
			// 
			this->uitleg_label4->AutoSize = true;
			this->uitleg_label4->Location = System::Drawing::Point(9, 198);
			this->uitleg_label4->Name = L"uitleg_label4";
			this->uitleg_label4->Size = System::Drawing::Size(41, 13);
			this->uitleg_label4->TabIndex = 3;
			this->uitleg_label4->Text = L"Overig:";
			this->uitleg_label4->Click += gcnew System::EventHandler(this, &Form1::label2_Click);
			// 
			// uitleg_label2
			// 
			this->uitleg_label2->AutoSize = true;
			this->uitleg_label2->Location = System::Drawing::Point(12, 70);
			this->uitleg_label2->Name = L"uitleg_label2";
			this->uitleg_label2->Size = System::Drawing::Size(38, 13);
			this->uitleg_label2->TabIndex = 2;
			this->uitleg_label2->Text = L"Stap2:";
			// 
			// uitleg_label
			// 
			this->uitleg_label->AutoSize = true;
			this->uitleg_label->Location = System::Drawing::Point(15, 24);
			this->uitleg_label->Name = L"uitleg_label";
			this->uitleg_label->Size = System::Drawing::Size(41, 13);
			this->uitleg_label->TabIndex = 1;
			this->uitleg_label->Text = L"Stap1: ";
			// 
			// uitleg_label5
			// 
			this->uitleg_label5->AutoSize = true;
			this->uitleg_label5->Location = System::Drawing::Point(12, 9);
			this->uitleg_label5->Name = L"uitleg_label5";
			this->uitleg_label5->Size = System::Drawing::Size(132, 13);
			this->uitleg_label5->TabIndex = 3;
			this->uitleg_label5->Text = L"Geselecteerde bestanden:";
			// 
			// uitleg_label6
			// 
			this->uitleg_label6->AutoSize = true;
			this->uitleg_label6->Location = System::Drawing::Point(462, 82);
			this->uitleg_label6->Name = L"uitleg_label6";
			this->uitleg_label6->Size = System::Drawing::Size(130, 13);
			this->uitleg_label6->TabIndex = 4;
			this->uitleg_label6->Text = L"Het gekozen lisp bestand:";
			// 
			// lisp_txtb
			// 
			this->lisp_txtb->Location = System::Drawing::Point(465, 103);
			this->lisp_txtb->Name = L"lisp_txtb";
			this->lisp_txtb->ReadOnly = true;
			this->lisp_txtb->Size = System::Drawing::Size(471, 20);
			this->lisp_txtb->TabIndex = 5;
			// 
			// uitleg_label7
			// 
			this->uitleg_label7->AutoSize = true;
			this->uitleg_label7->Location = System::Drawing::Point(462, 126);
			this->uitleg_label7->Name = L"uitleg_label7";
			this->uitleg_label7->Size = System::Drawing::Size(213, 13);
			this->uitleg_label7->TabIndex = 6;
			this->uitleg_label7->Text = L"De gekozen locatie voor het script bestand:";
			// 
			// locatiescript_txtb
			// 
			this->locatiescript_txtb->Location = System::Drawing::Point(465, 140);
			this->locatiescript_txtb->Name = L"locatiescript_txtb";
			this->locatiescript_txtb->ReadOnly = true;
			this->locatiescript_txtb->Size = System::Drawing::Size(471, 20);
			this->locatiescript_txtb->TabIndex = 7;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(1192, 589);
			this->Controls->Add(this->locatiescript_txtb);
			this->Controls->Add(this->uitleg_label7);
			this->Controls->Add(this->lisp_txtb);
			this->Controls->Add(this->uitleg_label6);
			this->Controls->Add(this->uitleg_label5);
			this->Controls->Add(this->uitleg_groupbox);
			this->Controls->Add(this->filenames_lb);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->uitleg_groupbox->ResumeLayout(false);
			this->uitleg_groupbox->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void browse_btn_Click(System::Object^  sender, System::EventArgs^  e) {
				 OpenFileDialog CommonDialog;
				 CommonDialog.Title="Selecteer de bestanden voor het plotten.";
				 CommonDialog.Multiselect= true;
				 CommonDialog.CheckFileExists = true;
				 CommonDialog.Filter = "Autocad tekeningen (*.DWG*) | *.DWG*";
				 CommonDialog.FilterIndex = 2;

				 if(CommonDialog.ShowDialog() == System::Windows::Forms::DialogResult::OK)
				 {
					
					array<String^>^ gekozenbestanden = (CommonDialog.FileNames);
					filenames_lb->Items->AddRange(gekozenbestanden);
				 }

			 }
	private: System::Void label2_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
private: System::Void clearalles_btn_Click(System::Object^  sender, System::EventArgs^  e) {
			 filenames_lb->Items->Clear();
		 }
private: System::Void convert_btn_Click(System::Object^  sender, System::EventArgs^  e) {
			 OpenFileDialog CommonDialog2;
			 CommonDialog2.Title="Selecteer het Lisp bestand.";
			 CommonDialog2.Multiselect = false;
			 CommonDialog2.CheckFileExists = true;
			 CommonDialog2.Filter = "Lisp bestanden (*.lsp*)| *.lsp*";
			 CommonDialog2.FilterIndex =2;
			 if(CommonDialog2.ShowDialog() == System::Windows::Forms::DialogResult::OK)
			 {
				 String^ gekozenlisp = (CommonDialog2.FileName);
				 lisp_txtb->Text = gekozenlisp;
			 }
		 }
private: System::Void locatiescript_btn_Click(System::Object^  sender, System::EventArgs^  e) {
			 FolderBrowserDialog folderDialog;

			 if(folderDialog.ShowDialog() == System::Windows::Forms::DialogResult::OK){
			 String^ scriptlocatie = folderDialog.SelectedPath;
			 scriptlocatie = scriptlocatie + "\\PDFscript.scr";
			 locatiescript_txtb->Text = scriptlocatie;
			 }

		 }
private: System::Void script_btn_Click(System::Object^  sender, System::EventArgs^  e) {
			 
			 

		 }
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
		 }
};
}
Topic archived. No new replies allowed.