Click here to Skip to main content
15,918,404 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: oops! Adding a window to console program Pin
adamUK13-Jul-03 6:54
adamUK13-Jul-03 6:54 
GeneralRe: oops! Adding a window to console program Pin
Ryan Binns13-Jul-03 15:20
Ryan Binns13-Jul-03 15:20 
GeneralRe: oops! Adding a window to console program Pin
adamUK14-Jul-03 5:54
adamUK14-Jul-03 5:54 
GeneralRe: oops! Adding a window to console program Pin
DaveE9th13-Jul-03 8:57
DaveE9th13-Jul-03 8:57 
GeneralRe: oops! Adding a window to console program Pin
PJ Arends13-Jul-03 14:22
professionalPJ Arends13-Jul-03 14:22 
GeneralRe: oops! Adding a window to console program Pin
DaveE9th13-Jul-03 19:28
DaveE9th13-Jul-03 19:28 
GeneralRe: oops! Adding a window to console program Pin
jan larsen14-Jul-03 2:49
jan larsen14-Jul-03 2:49 
Generaladding a window to console program Pin
Anonymous12-Jul-03 23:50
Anonymous12-Jul-03 23:50 
I found this project in the codeproject archives but I'm getting the error messages at the bottom. I was hoping someone might give me a hand getting this going. Am I missing a header or something? Thanks, Dave

Big Grin | :-D

[code]
/********************** test.cpp **************************/

// define _MT so that _beginthread( ) is available
#ifndef _MT
#define _MT
#endif

#include "stdio.h"
#include "windows.h"
#include "process.h"
#include "resource.h"

// global flag
bool bDone = false;

// this function is called by a new thread
void InputThreadProc( void *dummy )
{
// create the dialog window
HWNDhWnd = ::CreateDialog(NULL,
MAKEINTRESOURCE(IDD_DIALOG),NULL,NULL);
if ( hWnd!=NULL )
{
// show dialog
::ShowWindow(hWnd,SW_SHOW);
}
else
{
printf("Failed to create dialog\n");
bDone = true;
return;
}
// message loop to process user input
MSG msg;
while(1)
{
if ( ::PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE) )
{
if ( msg.message==WM_KEYUP )
{
int nVirtKey = (int) msg.wParam;
// if the user pressed the ESCAPE key, then
// print the text the user entered and quit
if ( nVirtKey==VK_ESCAPE )
{
// get the edit control
HWND hEdit = ::GetDlgItem(hWnd,IDC_EDIT);
if ( hEdit )
{
// get the input text the user entered
// and print it to the console window
char pText[3201];
int nSize = ::GetWindowText( hEdit,
pText, 3200 );
pText[nSize] = 0;
printf("\nYou have entered the ");
printf("following text in a second ");
printf("thread:\n\n%s\n\n",pText);
}
else
{
printf("Failed to get edit control\n");
}
// destroy the dialog and get out of
// the message loop
::DestroyWindow(hWnd);
bDone = true;
break;
}
}
// process message
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else
{
// if there is no message to process,
// then sleep for a while to avoid burning
// too much CPU cycles
::Sleep(100);
}
}
}

void main( int argc, char** argv )
{
printf("Hello, world of console apps\n");
// create a new thread to allow user input
if( _beginthread(InputThreadProc, 0, NULL )==-1)
{
printf("Failed to create thread");
return;
}
// wait for the new thread to finish
while ( !bDone )
{
// sleep 3 seonds
::Sleep(3000);
printf("main thread running\n");
}
}

/************************** end ************************/
---------------------------------------------------------
--------------------Configuration: console_window - Win32 Debug--------------------
Compiling...
console_window.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\console_window\console_window.cpp(20) : error C2065: 'HWNDhWnd' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\console_window\console_window.cpp(21) : error C2065: 'IDD_DIALOG' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\console_window\console_window.cpp(21) : error C2440: '=' : cannot convert from 'struct HWND__ *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\console_window\console_window.cpp(22) : error C2065: 'hWnd' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\console_window\console_window.cpp(47) : error C2065: 'IDC_EDIT' : undeclared identifier
Error executing cl.exe.

console_window.exe - 5 error(s), 0 warning(s)

[/code]
QuestionIs this function in the windows98 support? Pin
Alice8012-Jul-03 17:13
Alice8012-Jul-03 17:13 
AnswerRe: Is this function in the windows98 support? Pin
Christian Graus12-Jul-03 18:00
protectorChristian Graus12-Jul-03 18:00 
AnswerRe: Is this function in the windows98 support? Pin
Ryan Binns12-Jul-03 23:36
Ryan Binns12-Jul-03 23:36 
GeneralRe: Is this function in the windows98 support? Pin
Alice8012-Jul-03 23:51
Alice8012-Jul-03 23:51 
GeneralRe: Is this function in the windows98 support? Pin
Ryan Binns13-Jul-03 0:07
Ryan Binns13-Jul-03 0:07 
Questionhow I can insert these unicode characters rightly? Pin
Alice8012-Jul-03 16:54
Alice8012-Jul-03 16:54 
AnswerRe: how I can insert these unicode characters rightly? Pin
Anthony_Yio15-Jul-03 1:16
Anthony_Yio15-Jul-03 1:16 
GeneralRe: how I can insert these unicode characters rightly? Pin
Alice8015-Jul-03 1:37
Alice8015-Jul-03 1:37 
QuestionCan anybody say why no data gets shown? Pin
WREY12-Jul-03 14:23
WREY12-Jul-03 14:23 
AnswerRe: Can anybody say why no data gets shown? Pin
Michael Dunn12-Jul-03 16:24
sitebuilderMichael Dunn12-Jul-03 16:24 
GeneralRe: Can anybody say why no data gets shown? Pin
WREY12-Jul-03 17:54
WREY12-Jul-03 17:54 
GeneralRe: Can anybody say why no data gets shown? Pin
PJ Arends12-Jul-03 18:03
professionalPJ Arends12-Jul-03 18:03 
GeneralRe: Can anybody say why no data gets shown? Pin
WREY12-Jul-03 18:20
WREY12-Jul-03 18:20 
GeneralRe: Can anybody say why no data gets shown? Pin
Michael Dunn12-Jul-03 18:37
sitebuilderMichael Dunn12-Jul-03 18:37 
GeneralRe: Can anybody say why no data gets shown? Pin
Mike Dimmick13-Jul-03 1:44
Mike Dimmick13-Jul-03 1:44 
GeneralRe: Can anybody say why no data gets shown? Pin
WREY13-Jul-03 4:28
WREY13-Jul-03 4:28 
GeneralProblem by getting new object in GDI+, Help me. Pin
Behzad Ebrahimi12-Jul-03 9:08
Behzad Ebrahimi12-Jul-03 9:08 

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.