Header files not compiling right?

Im using visual C++ to make a form application to shut off the computer at a specific time. i used the datetimepicker tool but im not able to compare and convert the value because form1.h will not read the ctime and cstring header files. i do not know where to put them exactly.

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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#pragma once

namespace AutoShutDownController {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <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::MenuStrip^  menuStrip1;
	protected: 
	private: System::Windows::Forms::ToolStripMenuItem^  aboutToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  helpToolStripMenuItem;
	private: System::Windows::Forms::CheckBox^  Java;

	private: System::Windows::Forms::DateTimePicker^  Time;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Label^  Set;
	private: System::Windows::Forms::CheckBox^  Tray;
	private: System::Windows::Forms::NotifyIcon^  SIcon;


	private: System::ComponentModel::IContainer^  components;



	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#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->components = (gcnew System::ComponentModel::Container());
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
			this->aboutToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->helpToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->Java = (gcnew System::Windows::Forms::CheckBox());
			this->Time = (gcnew System::Windows::Forms::DateTimePicker());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->Set = (gcnew System::Windows::Forms::Label());
			this->Tray = (gcnew System::Windows::Forms::CheckBox());
			this->SIcon = (gcnew System::Windows::Forms::NotifyIcon(this->components));
			this->menuStrip1->SuspendLayout();
			this->SuspendLayout();
			// 
			// menuStrip1
			// 
			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->aboutToolStripMenuItem, 
				this->helpToolStripMenuItem});
			this->menuStrip1->Location = System::Drawing::Point(0, 0);
			this->menuStrip1->Name = L"menuStrip1";
			this->menuStrip1->Size = System::Drawing::Size(284, 24);
			this->menuStrip1->TabIndex = 0;
			this->menuStrip1->Text = L"menuStrip1";
			// 
			// aboutToolStripMenuItem
			// 
			this->aboutToolStripMenuItem->Name = L"aboutToolStripMenuItem";
			this->aboutToolStripMenuItem->Size = System::Drawing::Size(52, 20);
			this->aboutToolStripMenuItem->Text = L"About";
			// 
			// helpToolStripMenuItem
			// 
			this->helpToolStripMenuItem->Name = L"helpToolStripMenuItem";
			this->helpToolStripMenuItem->Size = System::Drawing::Size(44, 20);
			this->helpToolStripMenuItem->Text = L"Help";
			// 
			// Java
			// 
			this->Java->AutoSize = true;
			this->Java->Location = System::Drawing::Point(12, 45);
			this->Java->Name = L"Java";
			this->Java->Size = System::Drawing::Size(154, 17);
			this->Java->TabIndex = 1;
			this->Java->Text = L"Only Shut Down javaw.exe";
			this->Java->UseVisualStyleBackColor = true;
			this->Java->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox1_CheckedChanged);
			// 
			// Time
			// 
			this->Time->CustomFormat = L"MM\'/\'dd ddd hh\':\'mm\':\'ss tt";
			this->Time->Format = System::Windows::Forms::DateTimePickerFormat::Custom;
			this->Time->Location = System::Drawing::Point(19, 142);
			this->Time->Name = L"Time";
			this->Time->ShowUpDown = true;
			this->Time->Size = System::Drawing::Size(147, 20);
			this->Time->TabIndex = 2;
			this->Time->ValueChanged += gcnew System::EventHandler(this, &Form1::Time_ValueChanged);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(12, 122);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(97, 13);
			this->label1->TabIndex = 3;
			this->label1->Text = L"Time for shutdown:";
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(39, 168);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(92, 24);
			this->button1->TabIndex = 4;
			this->button1->Text = L"Set Time";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// Set
			// 
			this->Set->AutoSize = true;
			this->Set->Location = System::Drawing::Point(166, 174);
			this->Set->Name = L"Set";
			this->Set->Size = System::Drawing::Size(0, 13);
			this->Set->TabIndex = 5;
			this->Set->Click += gcnew System::EventHandler(this, &Form1::Set_Click);
			// 
			// Tray
			// 
			this->Tray->AutoSize = true;
			this->Tray->Location = System::Drawing::Point(12, 68);
			this->Tray->Name = L"Tray";
			this->Tray->Size = System::Drawing::Size(102, 17);
			this->Tray->TabIndex = 6;
			this->Tray->Text = L"Minimize to Tray";
			this->Tray->UseVisualStyleBackColor = true;
			this->Tray->Click += gcnew System::EventHandler(this, &Form1::checkBox1_CheckedChanged);
			// 
			// SIcon
			// 
			this->SIcon->BalloonTipText = L"Test";
			this->SIcon->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"SIcon.Icon")));
			this->SIcon->Text = L"Icon";
			this->SIcon->MouseDoubleClick += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_Show);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 264);
			this->Controls->Add(this->Tray);
			this->Controls->Add(this->Set);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->Time);
			this->Controls->Add(this->Java);
			this->Controls->Add(this->menuStrip1);
			this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
			this->MainMenuStrip = this->menuStrip1;
			this->MaximizeBox = false;
			this->Name = L"Form1";
			this->Text = L"Auto Shutdown Controller";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->Resize += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->menuStrip1->ResumeLayout(false);
			this->menuStrip1->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion

		bool STray;

		
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void checkBox1_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
				 STray = true;
			 }
	private: System::Void Time_ValueChanged(System::Object^  sender, System::EventArgs^  e) {
			 }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

			 CString sCurTime = curTime->Format("HH:mm:ss"); //here is where i have the problem//
			 CString sDTValue = m_MyDTValue->Format("HH:mm:ss");
			 Set->Text = ;
			 Time->Enabled = false;
			 if (STray == true) 
			 {
				  SIcon->Visible = true;
				  SIcon->ShowBalloonTip(500);
				  this->Hide();
			 }
		 }
private: System::Void Set_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void Form1_Show(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			 this->Show();
			 SIcon->visible = false;
		 }
};
}
*Sigh* Everyday more and more people are using C++/CLI thinking it is the same as C++. I guess these questions will proliferate in the short term.

Anyway, sorry about that. To answer your question: Since you are using .Net, use the DateTime Structure from .Net. It will be a lot easier.

And remember: This is C++/CLI so you should stick to using .Net classes and structs as much as you can.
closed account (3hM2Nwbp)
Well, the 'Windows Programming' section of the site lumps C++/CLI in with the rest, so I can see that as a reason for the confusion. I'm not entirely sure that C++/CLI falls into the scope of this board, so I can't really suggest a sub-forum for it.

site wrote:
Win32, MFC, ATL, C++/CLI, .NET ...
Last edited on
ok. so im using that structure to get the values, but i'd like to be able to check the values. I get an error saying that the value couldnt be converted to a string when i try to make a label output the value. Also, how would i get the values of the current time and then subtract those from the inputed value? (sorry if this sounds confusing)

1
2
3
4
5
6
7
8
9
10
11
12
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 System::DateTime Time = TimeI->Value;
			 int hour = Time.Hour;
			 Set->Text = hour;
			 TimeI->Enabled = false;
			 if (STray == true) 
			 {
				  SIcon->Visible = true;
				  SIcon->ShowBalloonTip(500);
				  this->Hide();
			 }
		 }
closed account (3hM2Nwbp)
Wild guess, but would

Set->Text = hour.ToString();

fix it?
haha yup that worked! Any ideas on the other part though? I saw somewhere about a timespan value with the structure. would that help?
I have used the timespan structure, however i do not think the ToLocalTime function is working correctly. The output is 00:00:00 instead of 01:00:00...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 System::DateTime Time = TimeI->Value;
			 System::DateTime Current = TimeI->Value;
			 Current.ToLocalTime(); 
			 System::TimeSpan remainder = Time - Current;
			 Set->Text = "Time Set!";
			 Remaining->Text = remainder.ToString();
			 TimeI->Enabled = false;
			 if (STray == true) 
			 {
				  SIcon->Visible = true;
				  SIcon->ShowBalloonTip(500);
				  this->Hide();
			 }
		 }
ok....i fixed what was previously questioned, but i have ran into another problem: i want to have the textbox keep updating the timespan so that it looks like a countdown, however i get a syntax error about one of my identifiers which i know the name is matched with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 System::DateTime Time = TimeI->Value;
			 do
			 System::TimeSpan remainder = Time - DateTime::Now;
			 TBox->Text = remainder.ToString();
			 while (DateTime::Now != Time);
			 TimeI->Enabled = false;
			 Set->Text = "Time Set!";
			 if (STray == true) 
			 {
				  SIcon->Visible = true;
				  SIcon->ShowBalloonTip(500);
				  this->Hide();
			 }
		 }


Any Tips?
Topic archived. No new replies allowed.