|
|
Choice 'C' but not using C# which the link in choice 'B' is based upon.
Jer 29:11
|
|
|
|
|
Google the GetPrivateProfileString API to help read from an INI file. Once you have the values you can create the menu using regular STDOUT and STDIN routines such as printf , scanf , getchar , gets et al.
|
|
|
|
|
I want to put a Login form at the beginning of my project with using VC++ MFC along with validations.I have created a table using MS-ACCESS giving Username and Password as column headers.Now I want to connect the MS-ACCESS table contents with this VC++ MFC form.So if I enter the name and password in the edit boxes which are in the Login form,it should check that particular data whatever is typed in the edit boxes with the records in the MS-ACCESS say in login.mdb and pop a messagebox if it is incorrect,else the user must be allowed to enter the next form.S how to do that.The same thing I have done in Visual Basic as follows,but now I want the equivalent code in VC++ MFC,can anyone pls tell me...?
Private Sub cmdOk_Click()
Dim cnt As Integer
adLogin.Recordset.MoveFirst
cnt = 1
If txtLogin = "" Or txtPassword = "" Then
MsgBox "Invalid UserName or Password"
Exit Sub
End If
While Not adLogin.Recordset.EOF
If adLogin.Recordset(0) = txtLogin.Text And adLogin.Recordset(1) = txtPassword.Text Then
Unload Me
'mainForm.Show
frmOption.Show
Exit Sub
Else
adLogin.Recordset.MoveNext
cnt = cnt + 1
End If
Wend
If cnt >= adLogin.Recordset.RecordCount Then
txtLogin.Text = ""
txtPassword.Text = ""
MsgBox "Wrong User Name or Password"
txtLogin.SetFocus
End If
End Sub
|
|
|
|
|
hello,
i want to start and stop other process (win32 vc++ application without gui) in a mfc dialog application. please tell me how to do that ?
for stopping, i read that TerminateProcess() can be used but it should be used in extreme circumstances. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used. so is it safe to use it ??
|
|
|
|
|
Hello,
rahuljin wrote: want to start and stop other process (win32 vc++ application without gui)
What kind of an application are you developing?
You can use ShellExecute[^] to create a process. Or if you want more options and possibly control over the spawned process, there is CreateProcess[^]
No, you shouldn't be using TerminateProcess(), but again if you say what kind of application are you writing (and if you have written the spawned process as well), a better alternative might be suggested to you.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
mfc application creates some text files which are used by other win32 c++ program. if i try to access the files through mfc application while win32 c++ program running, it causes the crash of the mfc application (beacuse i dont used any 'if' for file open and i cant).
i used the createprocess() and it is working great.
|
|
|
|
|
rahuljin wrote: mfc application creates some text files which are used by other win32 c++ program. if i try to access the files through mfc application while win32 c++ program running, it causes the crash of the mfc application (beacuse i dont used any 'if' for file open and i cant).
I don't understand this. If you could explain me better, and tell me what exactly are you trying to achieve, I may be able to help you.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
i created the win32 c++ application long back when i dont have any idea of mfc. it is working fine.
with mfc, i create a gui which accept the some content and save them in text files. these text files are then used by the win32 application. win32 application runs at startup of windows and it takes the information from the files and starts using it (it is socket application so it will not read the file again until it receives some information for the ip which is saved in the text file).
so i want to restart the win32 application when closing mfc application so that win32 application can use the updated text files.
actually i want to use TerminateProcess() and then start it with CreateProcess() function. but i read that TerminateProcess() can create problem with DLL structure.
|
|
|
|
|
please tell me how to use TerminateProcess() function. if there is an alternative for this function, please suggest.
|
|
|
|
|
might want to look at ExitProcess() also
|
|
|
|
|
I have Tabctrl in a dialog.I want to set its background colour for each tab .I tried ON_WM_DRAWITEM but the control never comes in OnDrawItem().Can you help?
#define RED RGB(255,0,0)
#define YELLOW RGB(255,255,0)
#define MAGENTA RGB(255,0,255)
#define WHITE RGB(255,255,255)
#define BLUE RGB(0,0,255)
void CVMListDialog::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpdis)
{
CDialog::OnDrawItem(nIDCtl, lpdis);
char szTabText[100];
RECT rect;
UINT bkColor;
CBrush *cbr;
TC_ITEM tci;
CTabCtrl *pTabCtrl = (CTabCtrl *)GetDlgItem(IDC_TAB_VM);
if (pTabCtrl->m_hWnd == lpdis->hwndItem)
{
// which tab?
switch (lpdis->itemID)
{
case 0:
cbr = &m_brRed;
bkColor = RED;
break;
case 1:
cbr = &m_brYellow;
bkColor = YELLOW;
break;
case 2:
cbr = &m_brMagenta;
bkColor = MAGENTA;
break;
case 3:
cbr = &m_brWhite;
bkColor = WHITE;
break;
case 4:
cbr = &m_brBlue;
bkColor = BLUE;
break;
}
memset(szTabText, '\0', sizeof(szTabText));
tci.mask = TCIF_TEXT;
tci.pszText = szTabText;
tci.cchTextMax = sizeof(szTabText)-1;
pTabCtrl->GetItem(lpdis->itemID, &tci);
CDC *dc = CDC::FromHandle(lpdis->hDC);
dc->FillRect(&lpdis->rcItem, cbr);
dc->SetBkColor(bkColor);
TextOut(lpdis->hDC,
lpdis->rcItem.left,
lpdis->rcItem.top,
tci.pszText,
lstrlen(tci.pszText));
}
}
|
|
|
|
|
You must have set the "owner draw propery " dialouge proprty in your application either by dialouge wizard or by code.
notjing
|
|
|
|
|
Hello All;
i make a user control on c# using ultragrid control the problem is when i take the dll in order to use it in other projects the data doesnt appear, the grid reads the data from the data base
the code of the user control:
the grid name here is ulGrid
<br />
<br />
public partial class GridUserControl : UserControl<br />
{<br />
Infragistics.Win.UltraWinGrid.UltraGrid ulGrid = new UltraGrid();<br />
Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ulExcel = new UltraGridExcelExporter();<br />
Infragistics.Win.UltraWinGrid.UltraGridPrintDocument ulPrint = new Infragistics.Win.UltraWinGrid.UltraGridPrintDocument();<br />
<br />
<br />
bool GridRightLeft;<br />
string HeaderTitle;<br />
string HeaderRightDetails;<br />
string HeaderLeftDetails;<br />
<br />
public GridUserControl()<br />
{<br />
InitializeComponent();<br />
ulItasGrid.ContextMenuStrip = contextMenuStrip1;<br />
}<br />
<br />
public delegate void GridEventKeyDown(object sender,KeyEventArgs e);<br />
public delegate void GridEventKeyUp(object sender, KeyEventArgs e);<br />
public delegate void GridEventMouseDown(object sender, KeyEventArgs e);<br />
public delegate void GridEventMouseClick(object sender, KeyEventArgs e);<br />
<br />
<br />
<br />
<br />
public bool GridRightToLeft<br />
{<br />
set<br />
{<br />
GridRightLeft = value;<br />
}<br />
get<br />
{<br />
return GridRightLeft;<br />
}<br />
}<br />
<br />
<br />
public string LeftDetails<br />
{ <br />
set<br />
{<br />
HeaderLeftDetails = value;<br />
}<br />
get<br />
{<br />
return HeaderLeftDetails;<br />
}<br />
}<br />
public string RightDetails<br />
{<br />
set<br />
{<br />
HeaderRightDetails = value;<br />
}<br />
get<br />
{<br />
return HeaderRightDetails;<br />
}<br />
}<br />
DataTable dt = new DataTable();<br />
public DataTable DataTableSource<br />
{ set<br />
{<br />
ulGrid.DataSource = dt;<br />
}<br />
<br />
<br />
get<br />
{<br />
return dt;<br />
}<br />
<br />
}<br />
<br />
<br />
public object DataSource<br />
{<br />
get<br />
{<br />
return ulGrid.DataSource;<br />
}<br />
set<br />
{<br />
ulGrid.DataSource = value;<br />
<br />
try<br />
{<br />
ulGrid.DataBind();<br />
}<br />
catch (Exception ex)<br />
{<br />
throw new Exception(String.Format("Could not bind data to grid"));<br />
}<br />
}<br />
}<br />
<br />
public string DataMember<br />
{<br />
set { ulGrid.DataMember = value; }<br />
get { return ulGrid.DataMember; }<br />
<br />
}<br />
<br />
<br />
<br />
public string HeaderReport<br />
{<br />
set<br />
{<br />
HeaderTitle = value;<br />
}<br />
get<br />
{<br />
return HeaderTitle;<br />
}<br />
}<br />
<br />
public AutoFitStyle AutoFit<br />
{<br />
set<br />
{<br />
this.ulItasGrid.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.ResizeAllColumns;<br />
}<br />
get<br />
{<br />
return this.ulItasGrid.DisplayLayout.AutoFitStyle;<br />
}<br />
}<br />
<br />
public Color Appearance<br />
{<br />
set<br />
{ <br />
this.ulItasGrid.DisplayLayout.Appearance.BackColor = Color.White;<br />
}<br />
get { <br />
return this.ulItasGrid.DisplayLayout.Appearance.BackColor;<br />
}<br />
}
and the code of the connection class for testing the grid:
<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Data.SqlClient;<br />
using System.Configuration;<br />
using System.Data;<br />
<br />
<br />
namespace testthegrid<br />
{<br />
class Connection<br />
{<br />
SqlConnection ConnectionStr = new SqlConnection();<br />
<br />
public Connection()<br />
{<br />
ConnectionStr.ConnectionString = "Data Source=.; Initial Catalog=GridExample;Integrated Security=SSPI";<br />
}<br />
<br />
public SqlConnection conn<br />
{<br />
get<br />
{<br />
return this.ConnectionStr;<br />
}<br />
set<br />
{<br />
this.ConnectionStr = value;<br />
}<br />
}<br />
<br />
<br />
public void OpenConnection()<br />
{<br />
if (ConnectionStr.State != ConnectionState.Open)<br />
ConnectionStr.Open();<br />
}<br />
<br />
<br />
public void CloseConnection()<br />
{<br />
try<br />
{<br />
if (ConnectionStr.State != ConnectionState.Closed)<br />
ConnectionStr.Close();<br />
}<br />
catch { }<br />
}<br />
}<br />
}<br />
and the code for testing the grid is:
<br />
<br />
namespace testthegrid<br />
{<br />
public partial class Form1 : Form<br />
{<br />
private Connection connection = new Connection();<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
FillGrid();<br />
}<br />
private void FillGrid()<br />
{<br />
connection.OpenConnection();<br />
DataTable dt = new DataTable();<br />
SqlDataAdapter da = new SqlDataAdapter("select * from AccountInfoA", connection.conn);<br />
da.Fill(dt);<br />
gridUserControl1.DataTableSource = dt;<br />
connection.CloseConnection();<br />
<br />
}<br />
there is no data appears in the grid
thanx a lot
|
|
|
|
|
beesan wrote: i make a user control on c#
If your question is related to C#, then please use the C# forum, not the C++ forum. Thanks.
|
|
|
|
|
hello,
i want to set the value of the ip address control from a string, say ip[100] which is read from a text file.
how this can be done ?
the text file contains ip like --- 127.0.0.1 or 111.111.11.1
|
|
|
|
|
ULONG ulP = inet_addr(szIPAddress );
|
|
|
|
|
i dont get, please explain.
i am using this code but it makes the mfc application crash.
len = strlen(fff);
if(strlen(fff) > 0 && strcmp(fff, "\n") != 0)
{
while(fff[i] != '.')
{
c[j] = fff[i];
j++;
i++;
}
m1 = atoi(c);
j = 0;
i++;
ZeroMemory(c, 3);
while(fff[i] != '.')
{
c[j] = fff[i];
j++;
i++;
}
m2 = atoi(c);
j = 0;
i++;
ZeroMemory(c, 3);
while(fff[i] != '.')
{
c[j] = fff[i];
j++;
i++;
}
m3 = atoi(c);
j = 0;
i++;
ZeroMemory(c, 3);
while(len > i)
{
c[j] = fff[i];
j++;
i++;
}
m4 = atoi(c);
j = 0;
i++;
ZeroMemory(c, 3);
ipAdd.SetAddress(m1, m2, m3, m4);
}
|
|
|
|
|
You may be over complicating the conversion of the 4 number parts of the IP address.
Try this instead:
int m1,m2,m3,m4;
sscanf(fff,"%d.%d.%d.%d",&m1,&m2,&m3,&m4);
ipAdd.SetAddress(m1,m2,m3,m4);
Of course, you'll need to validate the IP address is in the proper format.
|
|
|
|
|
this method shows wrong ip in the ip address control.
|
|
|
|
|
The variable fff must be a string only containing a valid IP address.
try this:
LPSTR lpIPAddress = _T("127.0.0.1");
int m1, m2, m3, m4;
sscanf(lpIPAddress,"%d.%d.%d.%d",&m1,&m2,&m3,&m4);
ipAdd.SetAddress(m1,m2,m3,m4);
Make sure you're passing in just the IP address in the sscanf function.
|
|
|
|
|
it is working now. since i am using
fileh.ReadString((LPTSTR)fff , 100);
therefore i have to use the following code for the correct result ---
swscanf((LPCTSTR)fff,_T("%d.%d.%d.%d"),&m1,&m2,&m3,&m4);
thanks for the help.
|
|
|
|
|
You're welcome! Glad you got it working.
|
|
|
|
|
I assume you are talking about CIPAddressCtrl .
The method CIPAddressCtrl::SetAddress take 4 BYTE parameters (see : doc on MSDN[^])
So, you will need to extract each "part" from the string and convert each substring to a BYTE. (manually or int_addr[^])
This signature was proudly tested on animals.
|
|
|
|
|
Hello,
I have a program that has a dialog box - call this 'box1' on top of another dialog.
I want to create a 'box2' that will have some of the same buttons as 'box1' and perform the same actions - don't ask why i need to do this!
What i think is that making box2 a 'child' / derived class of box1 will be the best idea.
What i want to do is tell the program, when button 'my buttonbox2' is clicked in box2 it just goes to the 'mybuttonbox1' in box1 and carries out that process.
I understand all the class and derived class things in C++, and I understand all the OnBtnClicked stuff etc... i'm just having a hard time with my limited knowledge to connect standard C++ with MFC!
If anyone can help I would be very grateful. Thankyou.
|
|
|
|