Click here to Skip to main content
15,921,577 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: can anyone help me.... please Pin
moodsey21122-Aug-05 14:59
moodsey21122-Aug-05 14:59 
GeneralRe: can anyone help me.... please Pin
Anonymous22-Aug-05 0:12
Anonymous22-Aug-05 0:12 
GeneralRe: can anyone help me.... please Pin
moodsey21122-Aug-05 15:09
moodsey21122-Aug-05 15:09 
GeneralRe: can anyone help me.... please Pin
Rage22-Aug-05 1:42
professionalRage22-Aug-05 1:42 
GeneralRe: can anyone help me.... please Pin
moodsey21122-Aug-05 15:19
moodsey21122-Aug-05 15:19 
AnswerRe: can anyone help me.... please Pin
Trollslayer22-Aug-05 3:16
mentorTrollslayer22-Aug-05 3:16 
GeneralRe: can anyone help me.... please Pin
moodsey21122-Aug-05 17:45
moodsey21122-Aug-05 17:45 
AnswerRe: can anyone help me.... please Pin
MailtoGops23-Aug-05 5:38
MailtoGops23-Aug-05 5:38 
Here the code and step..

1. Create a MFC dialog based application.

2. Create a new thread class (named CConThread) deriving from CWinThread (Use Application wizard)

3. In the Dialog App InitInstance () function add this code

int nResponse;
CString str = this->m_lpCmdLine;


if (str.Find ("Console") > -1)
{

CWinThread *t = AfxBeginThread(RUNTIME_CLASS(CConThread),THREAD_PRIORITY_NORMAL,0,0,NULL);
WaitForSingleObject(t->m_hThread,INFINITE);

}
else
{
CWinConDlg dlg;
m_pMainWnd = &dlg;

nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}

}


4. USing class wizard add Run() method to your CConThread class...

5. Add this code to your Run () method

int CConThread::Run()
{
AllocConsole();
HWND hWnd = NULL;

ifstream istr;
ofstream ostr;

//typedef HANDLE (__stdcall *FOO)(LPCTSTR);


istr.open ("CONIN$");
cin = istr;

ostr.open ("CONOUT$",ios::out);

cout = ostr;

typedef HWND (__stdcall *CW) ();
CW fp;
HMODULE hM = LoadLibrary("Kernel32.dll");
fp = (CW) GetProcAddress(hM,"GetConsoleWindow");
hWnd = (*fp)();

SetStdHandle(STD_INPUT_HANDLE,hWnd);
SetStdHandle(STD_OUTPUT_HANDLE,hWnd);
SetStdHandle(STD_ERROR_HANDLE,hWnd);


cout << "Welcome to my app .. Enter a value ";
cout.flush();
int i;
//istr >> i;

cin >>i;

cout << endl << "You have entered " << i;
cout.flush ();

istr.close();
ostr.close();

//return CWinThread::Run ();
return 0;
}


6. Compile and build the code

Execution
----------

1. If you execute the app without any command line agrument, it will display a dialog (As usual)

2. To work on command prompt d:\> AppName Console

where console is the paramter that I have checked inside the code..




" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "

- Words from Nelson Mandela

Thanks & Regards,

Gopalakrishnan
GeneralRe: can anyone help me.... please Pin
moodse21124-Aug-05 0:19
sussmoodse21124-Aug-05 0:19 
GeneralRe: can anyone help me.... please Pin
moodsey211124-Aug-05 15:11
sussmoodsey211124-Aug-05 15:11 
GeneralRe: can anyone help me.... please Pin
moodsey21125-Aug-05 23:54
moodsey21125-Aug-05 23:54 
GeneralNeed to generate inner polygon vertices for the given outer polygon vertices Pin
uma_kanth_k21-Aug-05 22:54
uma_kanth_k21-Aug-05 22:54 
GeneralRe: Need to generate inner polygon vertices for the given outer polygon vertices Pin
dharani22-Aug-05 0:14
dharani22-Aug-05 0:14 
GeneralRe: Need to generate inner polygon vertices for the given outer polygon vertices Pin
uma_kanth_k22-Aug-05 0:38
uma_kanth_k22-Aug-05 0:38 
GeneralRe: Need to generate inner polygon vertices for the given outer polygon vertices Pin
uma_kanth_k22-Aug-05 2:00
uma_kanth_k22-Aug-05 2:00 
Generalscrollbar &amp; big dialog's &amp;where are my buttons Pin
Member 176444821-Aug-05 21:44
Member 176444821-Aug-05 21:44 
GeneralPlease Help Pin
Aditya Rao21-Aug-05 21:43
Aditya Rao21-Aug-05 21:43 
GeneralTransmiting video captured from a webcam to another system through LAN Pin
VCSharp00721-Aug-05 21:33
VCSharp00721-Aug-05 21:33 
Generalfile reading in a specific format Pin
a_david12321-Aug-05 21:04
a_david12321-Aug-05 21:04 
GeneralRe: file reading in a specific format Pin
toxcct21-Aug-05 21:19
toxcct21-Aug-05 21:19 
GeneralRe: file reading in a specific format Pin
Anonymous21-Aug-05 23:34
Anonymous21-Aug-05 23:34 
QuestionIMPLEMENT_DYNAMIC,IMPLEMENT_SERIAL &amp; IMPLEMENT_DYNCREATE macros internals? Pin
ledallam21-Aug-05 20:42
ledallam21-Aug-05 20:42 
GeneralDrag and Drop Button Control Pin
Hachaso21-Aug-05 20:24
Hachaso21-Aug-05 20:24 
GeneralRe: Drag and Drop Button Control Pin
toxcct21-Aug-05 20:45
toxcct21-Aug-05 20:45 
GeneralCTabCtrl issue Pin
Nishad S21-Aug-05 18:52
Nishad S21-Aug-05 18:52 

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.