6 Replies - 16116 Views - Last Post: 25 March 2011 - 05:41 PM

#1 andyrocks9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-March 11

Count the number of open windows forms in visual c++

Posted 22 March 2011 - 06:27 PM

Hi,

I am new to windows system programming and currently experimenting with forms. Could someone help me in writing a windows form application which will launch new forms and then give the count of currently open forms. The count then decrements as we close the forms. I know we need to use interlockedexcahnge and memory mapped files for the program, but don't know how to proceed. Please help me. Any help is highly appreciated.
Is This A Good Question/Topic? 0
  • +

Replies To: Count the number of open windows forms in visual c++

#2 salindor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 46
  • View blog
  • Posts: 301
  • Joined: 10-November 06

Re: Count the number of open windows forms in visual c++

Posted 22 March 2011 - 06:39 PM

I know of 3 different windows technologies that could solve your problem (without necessarily using interlockedexchange and memory mapped files).

Why do you think you need them?
Have you looked into .NET forms?
Visual Studio has a wizard for create a new forms project have you tried that?
Was This Post Helpful? 0
  • +
  • -

#3 andyrocks9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-March 11

Re: Count the number of open windows forms in visual c++

Posted 22 March 2011 - 07:03 PM

View Postsalindor, on 22 March 2011 - 06:39 PM, said:

I know of 3 different windows technologies that could solve your problem (without necessarily using interlockedexchange and memory mapped files).

Why do you think you need them?
Have you looked into .NET forms?
Visual Studio has a wizard for create a new forms project have you tried that?


Hi Salindor,

Thanks for responding, Frankly speaking this has been provided as an assignment for one of my course to understand the working of memory mapped files. But I am not able to figure out where to start with. Even if you point me in the right direction, I can try to pick it up from there. Thank you very much for your help.
Was This Post Helpful? 0
  • +
  • -

#4 salindor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 46
  • View blog
  • Posts: 301
  • Joined: 10-November 06

Re: Count the number of open windows forms in visual c++

Posted 22 March 2011 - 07:38 PM

Well I guess I would start with a design. The reason my response is cryptic is because you picked two functions that are seemed unrelated to your stated problem.

I would start by reading MSDN and try and formulate specific questions as to what is getting you stuck.

I am guessing maybe you are trying to count the number of windows across multiple processes. In that case the forms really isn't the important part you just need to have a windows form application, and you can get away with a simple .NET application windows form. The wizard should be good enough to satisfy that requirement. Then that just leaves you focusing on the two technologies you want to research.

Once you get stuck post your code and we will be happy to help.

Salindor
Was This Post Helpful? 1
  • +
  • -

#5 andyrocks9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-March 11

Re: Count the number of open windows forms in visual c++

Posted 24 March 2011 - 03:09 PM

View Postsalindor, on 22 March 2011 - 07:38 PM, said:

Well I guess I would start with a design. The reason my response is cryptic is because you picked two functions that are seemed unrelated to your stated problem.

I would start by reading MSDN and try and formulate specific questions as to what is getting you stuck.

I am guessing maybe you are trying to count the number of windows across multiple processes. In that case the forms really isn't the important part you just need to have a windows form application, and you can get away with a simple .NET application windows form. The wizard should be good enough to satisfy that requirement. Then that just leaves you focusing on the two technologies you want to research.

Once you get stuck post your code and we will be happy to help.

Salindor


I just started building this piece of code and am already stuck!!! Am sorry....learning my way

I am launching a windows form when I build and run the solution and currently clicking on the button on the form launches a new form. But what I want here is to launch a form on building and running the solution and then allow me to again run the solution to launch a new form and so on, instead of using the button in the form.
Here is my code:
#pragma once
#include "Form1.h"

namespace Formsnow {

	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
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </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;
	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->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(36, 146);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(190, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"button1";
			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(292, 270);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 Form1 ^ form = gcnew Form1;
                 form->Show();
			 }
	};
}




Thank you for your help
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,515
  • Joined: 23-August 08

Re: Count the number of open windows forms in visual c++

Posted 24 March 2011 - 03:27 PM

Moved to CLI C++.

Application class's OpenForms property
Was This Post Helpful? 0
  • +
  • -

#7 andyrocks9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-March 11

Re: Count the number of open windows forms in visual c++

Posted 25 March 2011 - 05:41 PM

View PostJackOfAllTrades, on 24 March 2011 - 03:27 PM, said:



I am a newbie to Windows Forms Application and am stuck with the program. I came up with an algorithm for the program:

1. The Visual C++ application should launch a form and when second instance of the form is launched, it must show the count of forms in both the first and second forms as 2, similarly when third instance of the form is launched, all the three forms should display count as 3 and so on.

2. The count information should be passed between the instances using memory mapped file

I know we have a windows api createfilemapping and also I am aware that we need to use some kind of mutex to synchronize the different instances of the forms, but I am extremely novice to Windows Form Application and don't know how to build this. Any help will be highly appreciated.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1