Click here to Skip to main content
15,922,325 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Hardware Acceleration.......... Pin
David Crow25-Aug-05 4:11
David Crow25-Aug-05 4:11 
GeneralRe: Hardware Acceleration.......... Pin
ashwath200528-Aug-05 22:42
ashwath200528-Aug-05 22:42 
GeneralRe: Hardware Acceleration.......... Pin
ashwath200528-Aug-05 22:45
ashwath200528-Aug-05 22:45 
GeneralRe: Hardware Acceleration.......... Pin
ashwath200528-Aug-05 22:54
ashwath200528-Aug-05 22:54 
GeneralRe: Hardware Acceleration.......... Pin
David Crow2-Sep-05 8:45
David Crow2-Sep-05 8:45 
GeneralWindow's Border Pin
Nishad S24-Aug-05 21:43
Nishad S24-Aug-05 21:43 
GeneralSHInvokePrinterCommand Pin
ashwath200524-Aug-05 21:41
ashwath200524-Aug-05 21:41 
General..NEW Help... pls Pin
cue_ball24-Aug-05 21:27
cue_ball24-Aug-05 21:27 
Guys.
i suppose to write a program using vc++ to get the status from a PLC.. using tcp/ip.. i got a sample program of a chat channel.. this is the following code for the dialog... THE THING I NEED HELP IS... i add a button2 and i want it to sent a hello immendiatly upon pressing.. but i dont know how.. help pls..
#include "stdafx.h"
#include "ChatClient.h"
#include "ChatClientDlg.h"
#include "utility.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChatClientDlg dialog

CChatClientDlg::CChatClientDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChatClientDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChatClientDlg)
m_ChangeOfIp = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CChatClientDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChatClientDlg)
DDX_Control(pDX, IDC_LSTUSERS, m_CurrentUsers);
DDX_Control(pDX, IDC_EDTINPUT, m_edtInput);
DDX_Control(pDX, IDC_EDTSHOWUP, m_edtShowUp);
DDX_Control(pDX, IDC_EDTLOGIN, m_edtLogin);
DDX_Text(pDX, IDC_ChangeIp, m_ChangeOfIp);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CChatClientDlg, CDialog)
//{{AFX_MSG_MAP(CChatClientDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_LOGIN, OnLogin)
ON_BN_CLICKED(IDC_SEND, OnSend)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_ERRORMSG,OnErrorMsg)
ON_MESSAGE(WM_LISTMSG,OnListMsg)
ON_MESSAGE(WM_SHOWMSG,OnShowMsg)
ON_MESSAGE(WM_DELEMSG,OnDeleMsg)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChatClientDlg message handlers

BOOL CChatClientDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
((CButton*)GetDlgItem(IDC_LOGIN))->EnableWindow(FALSE);
m_edtLogin.EnableWindow(FALSE);
m_edtInput.EnableWindow(FALSE);

m_edtShowUp.SetReadOnly();
bLogined = FALSE;
ConnectServer();
return TRUE; // return TRUE unless you set the focus to a control
}

void CChatClientDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CChatClientDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CChatClientDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CChatClientDlg::OnLogin()
{
// TODO: Add your control notification handler code here
//clear all the message in the status bar
((CStatic*)GetDlgItem(IDC_MESSAGEBAR))->SetWindowText("");

CString str;
m_edtLogin.GetWindowText(str);
//if the login name is empty,do nothing
if(str.IsEmpty()){
//output remiander message in the status bar
((CStatic*)GetDlgItem(IDC_MESSAGEBAR))->SetWindowText("You must login with some name!");
return;
}
//connected,begin to launch the worker thread
if(g_bConnected){
if(g_cRequest!=NULL){
delete[] g_cRequest;
}
g_cRequest = new char[MAXLINELENGTH];
FormRequest(&g_cRequest,"NAME",str.GetBuffer(str.GetLength()));
((CButton*)GetDlgItem(IDC_LOGIN))->EnableWindow(FALSE);
m_edtLogin.EnableWindow(FALSE);
m_edtInput.EnableWindow(TRUE);
g_sClient.Write(g_cRequest,strlen(g_cRequest),10);
AfxBeginThread(ClientThreadProc,GetSafeHwnd());
bLogined = TRUE;
}
}

void CChatClientDlg::OnSend()
{
// TODO: Add your control notification handler code here
if(g_bConnected){

if(g_cRequest!=NULL){
delete[] g_cRequest;
}
g_cRequest = new char[MAXLINELENGTH];
CString str;
m_edtInput.GetWindowText(str);
if(str.IsEmpty())
return;
FormRequest(&g_cRequest,"MESG",str.GetBuffer(str.GetLength()));
g_sClient.Write(g_cRequest,strlen(g_cRequest),10);
m_edtInput.SetWindowText("");

}
}

void CChatClientDlg::OnErrorMsg(WPARAM wParam,LPARAM lParam)
{
if(lParam!=0){ //receiving the ERROR message
if(strcmp((char*)lParam,"ERRO")==0){
m_edtInput.EnableWindow(FALSE);
m_edtLogin.EnableWindow(TRUE);
m_edtLogin.SetWindowText("");
((CButton*)GetDlgItem(IDC_LOGIN))->EnableWindow(TRUE);
bLogined = FALSE;
}
}
((CStatic*)GetDlgItem(IDC_MESSAGEBAR))->SetWindowText("");
LPCTSTR str = (LPCTSTR)(LPSTR)wParam;
((CStatic*)GetDlgItem(IDC_MESSAGEBAR))->SetWindowText(str);
}

void CChatClientDlg::OnListMsg(WPARAM wParam)
{

CString str = (CString)(LPCTSTR)(LPSTR)wParam;
int n=0;
do{
n = str.Find(':');
if(n==-1){
m_CurrentUsers.AddString(str);
break;
}
CString str1 = str.Left(n);
CString str2 = str.Right(str.GetLength()-n-1);
m_CurrentUsers.AddString(str1);
str = str2;

}while(TRUE);

}

void CChatClientDlg::OnShowMsg(WPARAM wParam)
{
CString str = (LPCTSTR)(LPSTR)wParam;
int nSel = m_edtShowUp.GetWindowTextLength();
m_edtShowUp.SetSel(nSel, nSel);
str += "\r\n";
m_edtShowUp.ReplaceSel(str);
}

void CChatClientDlg::OnDeleMsg(WPARAM wParam)
{
LPCTSTR str = (LPCTSTR)(LPSTR)wParam;
int index = m_CurrentUsers.FindString(-1,str);
m_CurrentUsers.DeleteString(index);
}



BOOL CChatClientDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if((pMsg->message == WM_KEYDOWN)&&(pMsg->wParam == VK_RETURN)){
OnSend();
return TRUE;
}

return CDialog::PreTranslateMessage(pMsg);
}

void CChatClientDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
CString str;
m_edtLogin.GetWindowText(str);
if(!str.IsEmpty()&&bLogined){

if(g_cRequest!=NULL){
delete[] g_cRequest;
}
g_cRequest = new char[MAXLINELENGTH];
//sending the KILL message to the server
//so that the server can inform other clients to delete this guy
if(!g_bServerClosed){
FormRequest(&g_cRequest,"KILL",(LPSTR)(LPCTSTR)str);
g_sClient.Write(g_cRequest,strlen(g_cRequest),10);
//get out of the dead loop in the worker thread
g_eventKill.SetEvent();
}
delete[] g_cRequest;
}
CDialog::OnClose();
}

void CChatClientDlg::ConnectServer()
{
ASSERT(g_bConnected == FALSE);
CSockAddr saServer, saClient;

try {
g_sClient.Create();
if(g_strServerIP.IsEmpty()) {
saServer = CBlockingSocket::GetHostByName(g_strServerName, g_nPort);
}
else {
saServer = CSockAddr(g_strServerIP, g_nPort);
}

((CStatic*)GetDlgItem(IDC_MESSAGEBAR))->SetWindowText("Connecting...");
g_sClient.Connect(saServer);
g_bServerClosed = FALSE;

((CStatic*)GetDlgItem(IDC_MESSAGEBAR))->SetWindowText("Connection established.Pls log on with a user name.");
g_bConnected = TRUE;
((CButton*)GetDlgItem(IDC_LOGIN))->EnableWindow(TRUE);
m_edtLogin.EnableWindow(TRUE);
}
catch(CBlockingSocketException* e) {
LogBlockingSocketException((HWND)m_hWnd, "CLIENT:", e);
m_edtLogin.SetWindowText("");
m_edtLogin.SetFocus();
g_sClient.Close();
g_sClient.Cleanup();
e->Delete();
}

}

void CChatClientDlg::OnButton2()
{
// TODO: Add your control notification handler code here

}


GeneralRe: ..NEW Help... pls Pin
Cedric Moonen24-Aug-05 21:32
Cedric Moonen24-Aug-05 21:32 
Generalwerwerwe Pin
ashwath200524-Aug-05 21:12
ashwath200524-Aug-05 21:12 
GeneralRe: werwerwe Pin
MailtoGops24-Aug-05 21:23
MailtoGops24-Aug-05 21:23 
GeneralRe: werwerwe Pin
ThatsAlok24-Aug-05 21:56
ThatsAlok24-Aug-05 21:56 
GeneralRe: werwerwe Pin
ashwath200524-Aug-05 22:26
ashwath200524-Aug-05 22:26 
GeneralRe: werwerwe Pin
ThatsAlok24-Aug-05 23:31
ThatsAlok24-Aug-05 23:31 
GeneralRe: werwerwe Pin
toxcct25-Aug-05 0:08
toxcct25-Aug-05 0:08 
GeneralRe: werwerwe Pin
toxcct24-Aug-05 23:03
toxcct24-Aug-05 23:03 
QuestionManagedMFC? Pin
Uwe Keim24-Aug-05 20:11
sitebuilderUwe Keim24-Aug-05 20:11 
Generalreplies recived for&quot;problems in file reading,Suggest best method&quot;did not work Pin
a_david12324-Aug-05 20:02
a_david12324-Aug-05 20:02 
GeneralRe: replies recived for&quot;problems in file reading,Suggest best method&quot;did not work Pin
Rage24-Aug-05 20:37
professionalRage24-Aug-05 20:37 
GeneralRe: replies recived for&quot;problems in file reading,Suggest best method&quot;did not work Pin
MailtoGops24-Aug-05 21:00
MailtoGops24-Aug-05 21:00 
Generaltutorial help Pin
Neelesh K J Jain24-Aug-05 19:51
Neelesh K J Jain24-Aug-05 19:51 
GeneralRe: tutorial help Pin
dharani25-Aug-05 17:43
dharani25-Aug-05 17:43 
GeneralRegarding InstallShield Pin
Neelesh K J Jain24-Aug-05 19:50
Neelesh K J Jain24-Aug-05 19:50 
GeneralFont Size Pin
TssPrasad24-Aug-05 18:22
sussTssPrasad24-Aug-05 18:22 
GeneralRe: Font Size Pin
MailtoGops24-Aug-05 19:29
MailtoGops24-Aug-05 19:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.