Char clientpath [121];
Getcurrentdirectory (120, clientpath); // obtain the current path
Cstring
M_tempclientpath =
_ T ("");
M_tempclientpath.format ("% S/MAP/gps_status.tab", clientpath); // place the tab file in the directory where the map is located
Cstring
Temppathgst = _ T ("");
Temppathgst. Format ("% S/MAP/untitled. GST", clientpath); // obtain the path of the gallery's GST File
Cmapxfields
FLDS;
If (! FLDS. createdispatch (FLDS. getclsid ()))
// Return
False;
MessageBox ("create field error! ");
Variant
Fieldname; // field name
Fieldname. Vt = vt_bstr;
Cstring
Cstmp; // Chinese field name
Cstmp = _ T ("statusfield ");
Lpctstr lcstmp =
(Lpctstr) cstmp;
Variant
Fieldlength; // Field Length
Fieldlength. Vt = vt_i2;
Fieldlength. ival
= 200;
Long iwidth =
200;
FLDS. addstringfield (lcstmp, iwidth, false );
// Create a variant that
Points to the fields collection just created
Variant vflds;
Vflds. Vt =
Vt_dispatch;
Vflds. pdispval = FLDS. m_lpdispatch;
// Create a new layerinfo
Object
Cmapxlayerinfo
Linfo;
Linfo. createdispatch (linfo. getclsid ());
// Set the layer info type
To type: New table
Linfo. settype (milayerinfotypenewtable );
// Add
Parameters for the new table
Linfo. addparameter ("filespec ",
Colevariant (m_tempclientpath); // tab File
Linfo. addparameter ("name ",
Colevariant ("gps_status"); // layer name
Linfo. addparameter ("fields", vflds );
// Fields
Linfo. addparameter ("overwritefile", colevariant ("1 "));
// Add
New layer to the map
Cmapxlayer
Lyr = m_ctrlmapx.getlayers (). Add (linfo. m_lpdispatch );
MessageBox ("create Layer
Correctly, statuslayer! ");
// The following code checks whether a new layer is added to display the names of all layers.
Cmapxlayers
Layers = m_ctrlmapx.getlayers ();
Int IIi = layers. getcount ();
If
(Iii> 0)
{
For (int iss = 1; ISS <= III; ISS
++)
{
Cmapxlayer
Templayer = layers. Item (ISS );
Cstring
SSS = templayer. getname ();
Afxmessagebox (SSS );
}
}
// Save
The GST
File
// If the GST is not stored, this layer is not added to the GST file the next time it is opened.
// M_ctrlmapx.savemapasgeoset ("", temppathgst );
Method 2: If a layer file already exists, you only need to add the file to the gallery.
For other code, refer to the first example.
To obtain the path of the tab file, go to m_tempclientpath and add a layer.
Cmapxlayer
Lyr = m_ctrlmapx.getlayers (). Add (m_tempclientpath );
Remember to save the GST file at the end; otherwise, you need to add the file next time you open the file.