|
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!
|
|
|
|
|
When I use;
Pen* myPen1 = new Pen(Color(255, 255, 0, 0));
I got compiler error --> error C2660: 'new' : function does not take 3 parameters
But when use;
Pen myPenRed(Color(100, 255, 0, 0), 30);
and
func(&myPenRed, ... )
I have not error!
Why!?
|
|
|
|
|
Have you defined a function named "new"? Why does the new Pen constructor have one param and the other ctor 2 params?
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Ah, yes. That error again.
That error occurs in debug builds when you have the code
#ifdef _DEBUG
#define new DEBUG_NEW <<-- here's the problem, GDI+ does not like this
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
A fix is to use the global new when allocating GDI+ objects.
Pen *myPen1 = ::new Pen(Color(255, 255, 0, 0));
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!
|
|
|
|
|
I'm having a difficult time understanding the code below (specifically how push_back and push_front work), I was hoping someone might please explain it. See addition code below if you'd like to view more. Thank you.
<br />
for(int a = 0; a <= 10; a++)<br />
{<br />
mylist.push_back(a * 2);
if(a) mylist.push_front(a * -2);
}<br />
-------------------------------------------
<br />
#include <list> <br />
#include <iostream> <br />
<br />
using namespace std;<br />
<br />
void OutputList(list<int> output)<br />
{<br />
list<int>::iterator pos;<br />
<br />
for(pos = output.begin(); pos != output.end(); ++pos)<br />
cout << *pos << " ";<br />
cout << endl << endl;<br />
}<br />
<br />
int main()<br />
{<br />
list<int> mylist;<br />
list<int>::iterator pos;<br />
<br />
for(int a = 0; a <= 10; a++)<br />
{<br />
mylist.push_back(a * 2);<br />
if(a) mylist.push_front(a * -2);<br />
} <br />
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|
|
|
|
|
push_back adds elements to the end of an STL container; push_front adds elements to the start.
The code should output (assuming main calls OutputList ):
-20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20
In production code you would probably want to pass the output parameter as a const list& rather than as a list . This saves an unnecessary copy operation.
--
Mike Dimmick
|
|
|
|
|
I'm particularly interested in the process of how push_front, push_back, pop_front and pop_back insert and delete data. I know what they do, I just don't understand how they do it. I was hoping someone could explain (or direct me to some good reading on the subject).
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|
|
|
|
|
std::list almost has to be doubly-linked, to meet its standard guarantees. There are good treatments in many places, but I'll carry on anyway
Typically, you have an internal structure - let's call it _Node - which looks like:
struct _Node
{
T m_T;
_Node* m_pPrev;
_Node* m_pNext;
}; Then, the data members of std::list look something like:
template <typename T >
class list
{
<font color="green">
private:
_Node* m_pHead;
_Node* m_pTail;
}; push_front basically performs the following operations:
- Allocate a new
_Node - Set the new
_Node 's m_pNext pointer to the current value of m_pHead - Set the
m_pHead pointer to point to the new _Node - Set the
_Node 's m_pPrev pointer to NULL
push_back works basically the same, except you should replace m_pHead with m_pTail , and swap m_pNext and m_pPrev over.
Removing an item (pop_front , pop_back ) is as follows (example for pop_front ):- Set a temporary
_Node pointer pNode to the value of m_pHead - Set the head pointer to point to the next node, i.e.
m_pHead = m_pHead->m_pNext - Set the
m_pPrev pointer of the new head _Node to NULL - Delete the old head node through the
pNode pointer Again, pop_back is very similar.
Different containers implement this in different ways: for example, a deque is basically a linked list of arrays of T, which allow items to be efficiently added at either end, but it's costly to insert or delete in the middle; a vector is basically an array, so push_front requires a loop to copy each element to the next position before copying the pushed item into position 0. push_front is typically very slow for vector s as it's proportional to the number of elements (i.e. O(n)).
--
Mike Dimmick
|
|
|
|
|