主题:[讨论][求助]关于图形界面编程的几个基本问题
最近刚开始学GUI编程,期间有些问题无法解决,希望高手能够帮助详细解释下。
开发环境为VS.NET,使用了托管。
一、编译错误
error LNK2019: 无法解析的外部符号 _main ,该符号在函数 _mainCRTStartup 中被引用
fatal error LNK1120: 1 个无法解析的外部命令
以上为错误内容,以下为源程序。
[color=808080]//TableDisplay.h
#pragma once
#using<system.dll>
#using<mscorlib.dll>
#using<system.data.dll>
#using<system.drawing.dll>
#using<system.windows.forms.dll>
#using<system.xml.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Data::OleDb;
using namespace System::Xml;
public __gc class TableDisplay:public Form
{
public:
TableDisplay();
private:
DataSet *dataSet1;
OleDbDataAdapter *oleDbDataAdapter1;
DataGrid *dataGrid1;
OleDbCommand *oleDbSelectCommand1;
OleDbConnection *oleDbConnection1;
void InitializeComponent();
void SetupConnection();
};[/color]
//TableDisplay.cpp
#include"TableDisplay.h"
TableDisplay::TableDisplay()
{
SetupConnection();
InitializeComponent();
oleDbDataAdapter1->Fill(dataSet1,S"Authors");
//bind data in users table in dataSet1 to dataGrid1
dataGrid1->SetDataBinding(dataSet1,S"Authors");
}
void TableDisplay::SetupConnection()
{
this->dataSet1=new DataSet(S"NewDataSet");
this->oleDbDataAdapter1=new OleDbDataAdapter();
this->oleDbSelectCommand1=new OleDbCommand();
this->oleDbConnection1=new OleDbConnection();
//specift command for adapter
this->oleDbDataAdapter1->SelectCommand=this->oleDbSelectCommand1;
//create connection string
this->oleDbConnection1->ConnectionString=S"Provider=Microsoft.Jet.OLLEDB.4.0;Password=\"\";"
S"User ID=Admin;Data Source=Books.mdb;Mode=Share"
S"Deny None;Jet OLEDB:Database Password=\"\";";
this->oleDbConnection1->Open();
//configure SELECT command
this->oleDbSelectCommand1->CommandText=S"SELECT authorID,firstName,lastName FROM Authors";
this->oleDbSelectCommand1->Connection=this->oleDbConnection1;
}
void TableDisplay::InitializeComponent()
{
this->SuspendLayout();
//dataGrid1
this->dataGrid1=new DataGrid();
this->dataGrid1->Location=Point(15,16);
this->dataGrid1->Size=Drawing::Size(264,248);
//TableDisplay
this->AutoScaleBaseSize=Drawing::Size(5,13);
this->ClientSize=Drawing::Size(292,273);
this->Controls->Add(this->dataGrid1);
this->Name=S"TableDiplay";
this->Text=S"yedaoq";
this->ResumeLayout();
}
[color=008000]//TableDisplayTest.cpp
#include "TableDisplay.h"
int __stdcall WinMain()
{
Application::Run(new TableDisplay());
return 0;
}[/color]
二、我不太清楚对SuspendLayout()、ResumeLayout()的功能,希望有人能提供这两个函数的详细资料。
三、为了熟悉编程,我的程序是手工写的,没有使用“Windows窗体应用程序(NET)”生成框架。但是我发现用“Windows窗体应用程序”生成的框架与手工写的有一些地方不相同。
首先是用“Windows窗体应用程序”生成的框架中会有一个函数:
void Dispose(Boolean disposing)
但这函数并没有在程序中被调用。请问这个函数有什么用?
然后,Windows窗体应用程序生成的框架的主程序入口为:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
但是我看的书用的主程序入口却是:int __stdcall WinMain()
这两者又有什么分别呢?也请大虾帮忙解释下哦
开发环境为VS.NET,使用了托管。
一、编译错误
error LNK2019: 无法解析的外部符号 _main ,该符号在函数 _mainCRTStartup 中被引用
fatal error LNK1120: 1 个无法解析的外部命令
以上为错误内容,以下为源程序。
[color=808080]//TableDisplay.h
#pragma once
#using<system.dll>
#using<mscorlib.dll>
#using<system.data.dll>
#using<system.drawing.dll>
#using<system.windows.forms.dll>
#using<system.xml.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Data::OleDb;
using namespace System::Xml;
public __gc class TableDisplay:public Form
{
public:
TableDisplay();
private:
DataSet *dataSet1;
OleDbDataAdapter *oleDbDataAdapter1;
DataGrid *dataGrid1;
OleDbCommand *oleDbSelectCommand1;
OleDbConnection *oleDbConnection1;
void InitializeComponent();
void SetupConnection();
};[/color]
//TableDisplay.cpp
#include"TableDisplay.h"
TableDisplay::TableDisplay()
{
SetupConnection();
InitializeComponent();
oleDbDataAdapter1->Fill(dataSet1,S"Authors");
//bind data in users table in dataSet1 to dataGrid1
dataGrid1->SetDataBinding(dataSet1,S"Authors");
}
void TableDisplay::SetupConnection()
{
this->dataSet1=new DataSet(S"NewDataSet");
this->oleDbDataAdapter1=new OleDbDataAdapter();
this->oleDbSelectCommand1=new OleDbCommand();
this->oleDbConnection1=new OleDbConnection();
//specift command for adapter
this->oleDbDataAdapter1->SelectCommand=this->oleDbSelectCommand1;
//create connection string
this->oleDbConnection1->ConnectionString=S"Provider=Microsoft.Jet.OLLEDB.4.0;Password=\"\";"
S"User ID=Admin;Data Source=Books.mdb;Mode=Share"
S"Deny None;Jet OLEDB:Database Password=\"\";";
this->oleDbConnection1->Open();
//configure SELECT command
this->oleDbSelectCommand1->CommandText=S"SELECT authorID,firstName,lastName FROM Authors";
this->oleDbSelectCommand1->Connection=this->oleDbConnection1;
}
void TableDisplay::InitializeComponent()
{
this->SuspendLayout();
//dataGrid1
this->dataGrid1=new DataGrid();
this->dataGrid1->Location=Point(15,16);
this->dataGrid1->Size=Drawing::Size(264,248);
//TableDisplay
this->AutoScaleBaseSize=Drawing::Size(5,13);
this->ClientSize=Drawing::Size(292,273);
this->Controls->Add(this->dataGrid1);
this->Name=S"TableDiplay";
this->Text=S"yedaoq";
this->ResumeLayout();
}
[color=008000]//TableDisplayTest.cpp
#include "TableDisplay.h"
int __stdcall WinMain()
{
Application::Run(new TableDisplay());
return 0;
}[/color]
二、我不太清楚对SuspendLayout()、ResumeLayout()的功能,希望有人能提供这两个函数的详细资料。
三、为了熟悉编程,我的程序是手工写的,没有使用“Windows窗体应用程序(NET)”生成框架。但是我发现用“Windows窗体应用程序”生成的框架与手工写的有一些地方不相同。
首先是用“Windows窗体应用程序”生成的框架中会有一个函数:
void Dispose(Boolean disposing)
但这函数并没有在程序中被调用。请问这个函数有什么用?
然后,Windows窗体应用程序生成的框架的主程序入口为:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
但是我看的书用的主程序入口却是:int __stdcall WinMain()
这两者又有什么分别呢?也请大虾帮忙解释下哦