Jump to content

Windows form application: drive opener and time/date display

- - - - -

  • Please log in to reply
9 replies to this topic

#1
RuneNova91

RuneNova91

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
The current project I'm working on is a Windows form app and I would like it to have a display of the time and date on the upper middle of the form, a text progress that will display messages (drive is being opened, closed, etc), then at the bottom I would like three buttons...an "Open Drive", "Close Drive", and "Exit Program" buttons. Obviously I would like each button to do what it says, then a message that displays what the program is doing (Now opening CD-Rom Drive, Now closing CD-Rom Drive, Now Exiting Program, etc) after a button is pressed while the program is carrying out its task.

I am thinking of more things to add to the program like maybe a data log or something that the user can check within the program that keeps itself updated or whatever. any suggestions would be awesome, what do you think?

And Im sure with time I can figure out and code everything on my own but I may need some help being pointed in the right direction...however, I will try my best!

Thanks :)
How many programmers does it take to fix a light bulb? ...None, its a hardware problem.

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
I would suggest getting that to work first, then adding fun stuff. It doesn't seem trivial.
sudo rm -rf /

#3
RuneNova91

RuneNova91

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
Ok so when I post code for a windows app button that is supposed to open the cd drive under "button1" and then the code that closes the drive under "button2" it makes all the buttons on the form disappear...I would guess Im posting the code in the wrong spot...so my question is where exactly do I post the code for the buttons?
How many programmers does it take to fix a light bulb? ...None, its a hardware problem.

#4
RuneNova91

RuneNova91

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
It might be very simple but it's not clicking for me :( can someone help me out? I need to add code to make my buttons actually work...where do I post the code for it?
How many programmers does it take to fix a light bulb? ...None, its a hardware problem.

#5
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
You can post code in one of two ways

1) use code tags [noparse]
 /* your code goes here */ 
[/noparse]

2) zip up the project files (delete all files that are compiler generated) then attach it to your post. You have to use the Advanced Editor to do that.


>>I need to add code to make my buttons actually work...where do I post the code for it?
In the Design Editor double clikck on the button, the IDE will create a function (called an event handler) for you where you can add code to make that button work.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#6
RuneNova91

RuneNova91

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
#pragma once

namespace Driveopener {

	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::FlowLayoutPanel^  flowLayoutPanel1;
	protected: 
	private: System::Windows::Forms::Button^  button1;





	protected: 

	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->flowLayoutPanel1 = (gcnew System::Windows::Forms::FlowLayoutPanel());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->flowLayoutPanel1->SuspendLayout();
			this->SuspendLayout();
			// 
			// flowLayoutPanel1
			// 
			this->flowLayoutPanel1->Controls->Add(this->button1);
			this->flowLayoutPanel1->Dock = System::Windows::Forms::DockStyle::Bottom;
			this->flowLayoutPanel1->Location = System::Drawing::Point(0, 238);
			this->flowLayoutPanel1->Name = L"flowLayoutPanel1";
			this->flowLayoutPanel1->Size = System::Drawing::Size(409, 35);
			this->flowLayoutPanel1->TabIndex = 0;
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(3, 3);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(87, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Open CD-Rom";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(409, 273);
			this->Controls->Add(this->flowLayoutPanel1);
			this->Name = L"Form1";
			this->Text = L"CD-Rom Control";
			this->flowLayoutPanel1->ResumeLayout(false);
			this->ResumeLayout(false);

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

#include <iostream>  
#include <windows.h>   // Sleep() 
#include <mmsystem.h>  // mciSendString()

using namespace std;   // std::cout, std::cin

int main()  
{  
  mciSendString("open CDAudio", NULL, 0, NULL);
  Beep(440,1000);     
  mciSendString("set CDAudio door open", NULL, 0, NULL);  
 }			 
};

	 
		 }
		 }
} 


Right now this is the windows application with only button1 on it and the button has no function yet...I want to post a code that makes the button open the cd-rom drive. then Ill make a few other buttons to close it, exit the program, etc. I just need to know where to put it...unfortunately I've only made win32 applications so the windows form is kinda foreign to me...also just fyi, im using visual c++ 2010
How many programmers does it take to fix a light bulb? ...None, its a hardware problem.

#7
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
you don't manually put it anywhere. As I said in my last post, double click the button and the IDE will start the function for you. All you have to do is add the code to open and/or close the CD drive. Don't ask me how to do that because I don't know. You will just have to google around and see if you can find some C or C++ code that does it.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#8
RuneNova91

RuneNova91

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
yea thats what I mean. Everythings set up for the actual wfa. I just need to make the button do what its supposed to do. I just dont know where to add the code
How many programmers does it take to fix a light bulb? ...None, its a hardware problem.

#9
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
Ancient Dragon is telling you where you need to add the code using the IDE. You must go to the view where you design the form graphically. There you must double click over the button of the form that you want to use to open the cd-rom or whatever. When you do this, Visual Studio will automatically create a new function and put the cursor inside that function so that you can write the code. This is the place where you must write the code to open the cd-rom.

#10
RuneNova91

RuneNova91

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
ah crap I knew it was very simple. sorry for the misunderstanding. thank you so much, ill continue working on it
How many programmers does it take to fix a light bulb? ...None, its a hardware problem.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users