RUPAK SEARCH ENGINE

Custom Search

button program in visual studio 6

//control.h
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};

class CMainWindow : public CFrameWnd
{
public:
CMainWindow ();

private:
CButton b[2];

protected:


afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void ok();
afx_msg void cancel();
DECLARE_MESSAGE_MAP ()
};


//resource.h

#define ID_BUTTON_OK 40001
#define ID_BUTTON_CANCEL 40002


//control.cpp
#include
#include "control.h"
#include "resource.h"

CMyApp myApp;
// CMyApp member functions

BOOL CMyApp::InitInstance ()
{
m_pMainWnd = new CMainWindow;


m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}

/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functions

BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(ID_BUTTON_OK,ok)
ON_COMMAND(ID_BUTTON_CANCEL,cancel)

END_MESSAGE_MAP ()

CMainWindow::CMainWindow ()
{
Create (NULL, _T ("Testing Controls"));
}

int CMainWindow::OnCreate (LPCREATESTRUCT lpCreateStruct)
{
b[0].Create("OK",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,CRect(250,100,310,150),this,ID_BUTTON_OK);
b[1].Create("Cancel",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,CRect(350,100,410,150),this,ID_BUTTON_CANCEL);

b[0].SetFocus();
return 0;
}
void CMainWindow::ok()
{
MessageBox("You clicked OK button","ok");
b[1].SetFocus ();
}


void CMainWindow::cancel()
{
MessageBox("You clicked Cancel button","cancel");
b[0].SetFocus ();
}

No comments:

Post a Comment