|
I actually answered this a few minutes after he posted it, but my reply got posted on the last page of the forum. Wierd...
PJ Arends wrote:
why do people rate a question a 1? If the question is so dumb, and the answer so obvious, then answer the question or else totally ignore it and move on.
I did both - rated it a 1 and posted a reply, which unfortunately got lost
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
I did both - rated it a 1 and posted a reply, which unfortunately got lost
It's probably Karma dude...
My world tour
What I do now..
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
"I suppose if it was a choice between bon jovi and the interior of a car, the car would win, even it didnt have a radio and I had to sit in silence" James Simpson on Light Metal.
|
|
|
|
|
adamUK wrote:
It's probably Karma dude...
Probably. I must have been punished for voting it a 1, even though I voted after I replied...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Wow... pre-Karma or deja-karma.. now that's spooky.
My world tour
What I do now..
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
"I suppose if it was a choice between bon jovi and the interior of a car, the car would win, even it didnt have a radio and I had to sit in silence" James Simpson on Light Metal.
|
|
|
|
|
I did what you said PJ and it eliminated 3 of the errors, now I only have 2 errors left...see below. I'm not sure what a dialog is. I thought specifying the header was enough, no?
Thanks, Dave
<br />
--------------------Configuration: console_window - Win32 Debug--------------------<br />
Compiling...<br />
console_window.cpp<br />
C:\Program Files\Microsoft Visual Studio\MyProjects\console_window\console_window.cpp(21) : error C2065: 'IDD_DIALOG' : undeclared identifier<br />
C:\Program Files\Microsoft Visual Studio\MyProjects\console_window\console_window.cpp(47) : error C2065: 'IDC_EDIT' : undeclared identifier<br />
Error executing cl.exe.<br />
<br />
console_window.exe - 2 error(s), 0 warning(s)<br />
<br />
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|
|
|
|
|
DaveE9th wrote:
I'm not sure what a dialog is.
Oh boy
A dialog is a form based window that is used to get input from a user. The colour picker, font picker, and file open/save dialogs that you encounter frequently are examples of dialogs.
Check out these articles for a good beginners intro to using dialogs
http://www.codeproject.com/dialog/dialogapptute.asp[^]
http://www.codeproject.com/dialog/dialogapptute2.asp[^]
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
PJ Arends wrote:
You have created a dialog resource with those IDs have you not?
I'm not sure what you mean by "dialog resource." I know what a dialog box is, I should have been more specific.
I found this project in the archives. It builds a window in a CONSOLE program. You referred me to the MFC tutorials, that's a different ball game. I'm just trying to study the differences between the type of programs. I still can't get the above program going. It wants something in the header file. Anyone?
Thanks much, Dave
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|
|
|
|
|
VC++ needs the dialog resource file which it should have got from resource.h.
If you used the wizard to create a simple application and then pasted the code, then it may have created the resource.h for you, but it is empty, and you should create a dialog with the id that is missing...
Sorry that I can't be more specific, but it is ages since I last used resources.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
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
[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]
|
|
|
|
|
I an use the function Drawtextw output some words,
Is this function in the windows98 support?
if it not support, Should I how do?
|
|
|
|
|
I'd suggest you start with msdn.microsoft.com. The full answer to your question is easily found there.
Christian
NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma
Anonymous wrote:
OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window.
I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
|
|
|
|
|
Yes, using the Microsoft Layer for Unicode. See MSDN for more information on using this.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
but I want to display unicode character in windows 98, what should I do?
|
|
|
|
|
Alice80 wrote:
what should I do
Search for "Microsoft Layer for Unicode" on MSDN.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I am in a Dialog use pView->ReplaceSel(szData1,true) insert a Unicode char to view,I can't insert it rightly, the some word sign shows the disorderly code after inserting.
What my engineering use is not the method of unicode.
how I can insert these unicode characters rightly?
|
|
|
|
|
Is it because your OS doesn't support the UNICODE?
I know only NT , 2000 and XP automatially support UNICODE.
Win98 and below I think it is not automatically available.
|
|
|
|
|
My os is widows 2000 server,I can output the character rightly use the following code in a dialog,
i is a interger between 0 and 65536
wchar_t cTemp=i;
::DrawTextW(HDC(*pDC), &cTemp, 1, rcText, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
but I cant't output them in a view rightly use this code pView->ReplaceSel(szData1,true);
|
|
|
|
|
Here are portions of my code. The rest of the program is working fine, but at strategic spots I'd like to see what the state of certain values are (shown together in one convenient way).
Where the structure is being initialized, data are already in the variables from which it gets initialized.
======================================
struct IData
{
char* str;
char* pO;
char* pGH;
char* pIntrm;
int wrdlen;
int lvlcnt;
int ltrcnt;
} idata, *pIData;
// other program code
ostream& operator<< (ostream& outp, const IData IDat)
{
char Bufr[40] = " ";
char* Ptr_fmt[] = { pIData->str, pIData->pO, pIData->pGH, pIData->pIntrm };
int i, Dec_fm[] = { pIData->wrdlen, pIData->lvlcnt, pIData->ltrcnt };
i = sprintf(Bufr, "\tstr: 0x%x\n", *Ptr_fmt);
i += sprintf(Bufr+i, "\tOutput: 0x%x\n", *(Ptr_fmt+1));
i += sprintf(Bufr+i, "\tGrp Hold: 0x%x\n", *(Ptr_fmt+2));
i += sprintf(Bufr+i, "\tInterim: 0x%x\n", *(Ptr_fmt+3));
i += sprintf(Bufr+i, "\tWord len: %d\n", *Dec_fm);
i += sprintf(Bufr+i, "\tLevel cnt: %d\n", *(Dec_fm+1));
i += sprintf(Bufr+i, "\tLetter cnt: %d\n", *(Dec_fm+2));
outp<< IDat;
return outp;
}
// other program code
for(int lvl_cnt=0; lvl_cnt<<wordlen; ++lvl_cnt)
{
ltr_cnt = ++lvl_cnt;
pIData->str = str;
pIData->pO = pOut;
pIData->pGH = pGH;
pIData->pIntrm = pIntrm_str;
pIData->wrdlen = wordlen;
pIData->lvlcnt = lvl_cnt;
pIData->ltrcnt = ltr_cnt;
cout<< "\n *** " << idata <<endl;
lvl_cnt--;
}
======================================
In the "for" statement, I had to use two "<" signs, because without it the CodeProject editor would not show the rest of the statement.
After a while, things begin to get blurred. So, I thank you for whatever you may see as the reason why nothing gets shown.
William
Fortes in fide et opere!
|
|
|
|
|
Your operator<< is not sound. First, you're overrunning Bufr , you'll need much more than 40 characters for all that output. Second, you're not doing anything with Bufr . Third, it has a parameter IDat that you don't use; instead you refer to pIData .
--Mike--
"Big handwavy generalizations made from a position of deep ignorance is one of the biggest wastes of time on the net today.
-- Joel Spolsky
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
Thank you for your insightful reply. However, while I'm happy to report that with the changes made (directly due to the points you made), data has now begun displaying. That's the good news!
The bad news is that they're garbage!
Here is the new code:
ostream& operator<< (ostream& output, const IData& idata)
{
char Bufr[200] = " ";
char* Ptr_fm[] = { idata.str, idata.pO, idata.pGH, idata.pIntrm };
int i, Dec_fm[] = { idata.wrdlen, idata.lvlcnt, idata.ltrcnt };
i = sprintf(Bufr, "\tstr: 0x%x\n", *Ptr_fm);
i += sprintf(Bufr+i, "\tOutput: 0x%x\n", *(Ptr_fm+1));
i += sprintf(Bufr+i, "\tGrp Hold: 0x%x\n", *(Ptr_fm+2));
i += sprintf(Bufr+i, "\tInterim: 0x%x\n", *(Ptr_fm+3));
i += sprintf(Bufr+i, "\tWord len: %d\n", *(Dec_fm);
i += sprintf(Bufr+i, "\tLevel cnt: %d\n", *(Dec_fm+1));
i += sprintf(Bufr+i, "\tLetter cnt: %d\n", *(Dec_fm+2));
printf(" *******\n %s\n", Bufr);
output<< idata;
return output;
}
=========================================
Perhaps, helpful to mention is that just before the "for" loop is entered, the structure is instantiated to:
IData idata;
and upon entering the loop, the structure is initialized with data that are already present in the variables to which it is being initialized.
Right after those initializations take place, this is the statement that follows:
cout<< "\n\n ^^^ " << idata <
|
|
|
|
|
Hi William,
I may be wrong, but I think your call to output<< idata; would cause an infinite loop. (you are calling your operator<< from within your operator<< )
perhaps it should be output << Bufr; ?
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks! Your suggestion worked (no more wild antics by "printf"), but garbage still got printed out.
Holy moly! I KNOW those variables used to initialized the structure, ARE themselves, already initialized. Might returning Bufr instead of idata have anything to do with garbage being displayed? (I don't know. It's been a long day for me.)
In case anybody start wondering, the answer is, "Yes," I moved Bufr outside the overloaded function and made it a global variable (just for this time), otherwise it was going to get destroyed whenever the function exited.
Thanks again!
(Sometimes I hate computers!!)
William
Fortes in fide et opere!
|
|
|
|
|
Use the debugger. View the memory that the pointers point at. Double-check that you've got the right addresses. Step into sprintf() . Etc. That's what the debugger's there for
--Mike--
"Big handwavy generalizations made from a position of deep ignorance is one of the biggest wastes of time on the net today.
-- Joel Spolsky
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
I have to ask: why the heck are you messing around with sprintf and a buffer inside an operator << function??
Try the following:
ostream& operator<<( ostream& output, const IData& idata )
{
output << "\tstr: 0x" << (void*)idata.str <<
"\n\tOutput: 0x" << (void*)idata.p0 <<
"\n\tGrp Hold: 0x" << (void*)idata.pGH <<
"\n\tInterim: 0x" << (void*)idata.pIntrm <<
"\n\tWord len: " << idata.wrdlen <<
"\n\tLevel cnt: " << idata.lvlcnt <<
"\n\tLetter cnt: " << idata.ltrcnt << "\n";
return output;
}
|
|
|
|
|
Thanks for your reply!
What started out as a quick and dirty way to see data, turned out to be not so quick, and was getting rather dirty.
Your point is well taken, and thanks for bringing back some reality to the situation.
William
Fortes in fide et opere!
|
|
|
|
|