Click to See Complete Forum and Search --> : c++/cli problem,create a button


fantasy2004
January 2nd, 2006, 11:06 PM
Hi,all!
I create a application to create a button and i combox, but i cant see it.
who can tell me why? and when i run the application ,the cmd window appear first,why?

I attach my project below.

darwen
January 2nd, 2006, 11:48 PM
When you created your project did you select "windows forms application" rather than "console application" ?

Also, are you using VS2003 ? If you're using VS2002 then you can only create console applications.

Darwen.

fantasy2004
January 3rd, 2006, 12:00 AM
thanks darwen!
do you see my Attached Files?
I use VS2005 and choose "CLR empty project" option.
here is a release exe file.

cilu
January 3rd, 2006, 09:13 AM
Next time post the code, not the executable. Create a new project and select, as darwen said, Windows Forms Application instead.

fantasy2004
January 3rd, 2006, 09:31 AM
hi,cilu!
I have post the entire project in first attachment,and an executable file in second attachment.
I want to make a SDI like application and dont want to make Windows Forms Application instead.
so i choose "CLR empty project" option.
you can download the attachment to see the whole project.
and I post some code fragment here.
//MainWindow.h
pragma once

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Collections;
using namespace System::IO;
using namespace System::Drawing;


ref class MainWindow: public Form
{
public:
static MainWindow^ parentWindow;
MainWindow();
virtual ~MainWindow();
private:
System::Windows::Forms::Button^ mybutton;
private: System::Windows::Forms::ComboBox^ comboBox1;
private:
void MenuItemHandler( Object^ sender, EventArgs^ e );
System::ComponentModel::Container^ components;
Windows::Forms::MenuItem^ newMenuItem;
Windows::Forms::MenuItem^ fileMenuItem;
Windows::Forms::MainMenu^ mainMenu;
};
//MainWindow.cpp
#include "MainWindow.h"
using namespace System::Reflection;
using namespace System::Resources;

MainWindow::MainWindow()
{
parentWindow = this;
//InitializeComponent();
//documentCount = 0;
//CreateDocument();
//File
components = gcnew System::ComponentModel::Container;
this->AutoScaleBaseSize = System::Drawing::Size( 5, 13 );
this->Text = "Scribble";
//this->IsMdiContainer = true;
this->Menu = mainMenu;
this->ClientSize = System::Drawing::Size( 600, 400 );
newMenuItem = gcnew Windows::Forms::MenuItem( "&New",gcnew EventHandler( this, &MainWindow::MenuItemHandler ) );
array<Windows::Forms::MenuItem^>^rFileItems = gcnew array<Windows::Forms::MenuItem^>(1);
rFileItems[ 0 ] = newMenuItem;
fileMenuItem = gcnew Windows::Forms::MenuItem( "&File",rFileItems );
//MainMenu
array<Windows::Forms::MenuItem^>^rMainItems = gcnew array<Windows::Forms::MenuItem^>(1);
rMainItems[ 0 ] = fileMenuItem;
mainMenu = gcnew MainMenu( rMainItems );
this->Menu = mainMenu;

this->mybutton = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
this->mybutton->Location = System::Drawing::Point(0, 0);
this->mybutton->Name = L"button1";
this->mybutton->Size = System::Drawing::Size(75, 23);
this->mybutton->TabIndex = 0;
this->mybutton->Text = L"test";
//this->mybutton->UseVisualStyleBackColor = true;

this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
this->comboBox1->FormattingEnabled = true;
this->comboBox1->Location = System::Drawing::Point(61, 139);
this->comboBox1->Name = L"comboBox1";
this->comboBox1->Size = System::Drawing::Size(121, 20);
this->comboBox1->TabIndex = 1;
}

MainWindow::~MainWindow(){}

void MainWindow::MenuItemHandler( Object^ sender, EventArgs^ /* e */)
{
}

and
//main.cpp
//#include "stdafx.h"
#include "MainWindow.h"
//using namespace System;
//using namespace System::ComponentModel;
//using namespace System::Collections;
//using namespace System::Windows::Forms;
//using namespace System::Data;
//using namespace System::Drawing;

[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());
Application::Run(gcnew MainWindow());
return 0;
}
in my project,only 3 files.
you can compile and run it.

fantasy2004
January 4th, 2006, 05:01 AM
I feel very few people in this forum(cli) and like to answer the question.
I dont know if it is an difficult question or i dont make the problem clear?
I have post the code and the project.
eager to your help!

darwen
January 4th, 2006, 02:34 PM
We already have. Make a windows forms application.

Darwen.

fantasy2004
January 4th, 2006, 06:39 PM
hi,darwen!
Have you seen the codes I posted, I have two questions:
first I encounter a problem, when I run the application, it shows command window first, then shows my application.
I think maybe this will be solved by Make a windows forms application.
but i compare the windows forms application and the "CLR empty project" option, I dont know where is the difference.
and I change my code from the "scribble " sample code.

second why My button cant appear when I run the program?
I post the code and the project here, but no one download it,why dont you try it, and see what happened,then you can see what I mean.

thank you very much.

cilu
January 6th, 2006, 05:42 PM
I can't unpack your project. Post it as a zip archive.

cilu
January 6th, 2006, 05:44 PM
I want to make a SDI like application and dont want to make Windows Forms Application instead.
But you're using the windows forms, can't you see:

ref class MainWindow: public Form
{
public:
static MainWindow^ parentWindow;
MainWindow();
virtual ~MainWindow();
private:
System::Windows::Forms::Button^ mybutton;
private: System::Windows::Forms::ComboBox^ comboBox1;
private:
void MenuItemHandler( Object^ sender, EventArgs^ e );
System::ComponentModel::Container^ components;
Windows::Forms::MenuItem^ newMenuItem;
Windows::Forms::MenuItem^ fileMenuItem;
Windows::Forms::MainMenu^ mainMenu;
};

The issue is not code-related only. Compilation options are the ones that make the difference. If you are creating an empty project you must set most of them by yourself. If you create a Windows Forms Application you won't have to do that, as the wizard will set everything in place.

fantasy2004
January 7th, 2006, 12:18 AM
thank you cilu!

But you're using the windows forms, can't you see:

yes, but I have no other choice. I dont want to choose MFC, and dont want to choose windows forms,so I choose "CLR empty project" option.
and i must derive it from windows forms class, beacuse i have no other choise either.

I need a SDI like application, but I dont know how to do it.

I revise the sample codes of scripple to try to realize it.

In fact, I dont know why must appear a windows forms to edit why you choose windows applications, I dont like this arrangement.

because sometime you want to choose any possible application styles according to what you like. I often delete the code the compile auto created, so I choose "CLR empty project" option instead.

and now I post the project with zip archive. hope you will help. thanks.

cilu
January 7th, 2006, 04:41 AM
I need a SDI like application, but I dont know how to do it. I dont want to choose MFC, and dont want to choose windows forms,so I choose "CLR empty project" option.
This sounds like me like:
I want to go to Las Vegas. But I don't want to choose a car, and I don't want to choose a bus, so I choose to walk.
Why don't you want neither MFC nor WinForms?
and dont want to choose windows forms
Let me say it again: you already have chosen WinForms. ;)

fantasy2004
January 7th, 2006, 10:57 AM
thank you cilu!
Why don't you want neither MFC nor WinForms?
I dont like use MFC because I use it before, i think it is old in some scence.
though you can do any thing with it if you write enough codes by your own,but i think it is not so convience, i think some function should be provided by library. but the library change so little.

I hate to use WinForms because i think I dont know "why must appear a windows forms to edit when you choose windows applications", I dont like this arrangement.

I know I must use the class of "ref class MainWindow: public Form".
because i must use its library, i cant write the lib myself.
I think windows forms application like dialog type application in mfc.
I just delete the codes that the IDE auto created and write it by myself. because i dont need dialog application sometime.( i dont know how to prevent the ide to do this), so i choose an empty project instead.

I think the "CLR empty project" option is a choice bacause i use c++.

have you download my zip files? I see 1 view, but i'm not sure if it is you.

thank you any way!

fantasy2004
January 11th, 2006, 06:01 AM
four days have passed since my last post here.
I think it is a basic question and dont know why so few people like to answer.
and cilu, have you received my email? would you like to answer my question if you have downloaded my project?
thanks!