|
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
|
|
|
|
|
Thanks Mike
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|
|
|
|
|
Hi,
I wanted to know how do you attach your MFC program to a program and how to modify datas at specific offsets in this program, once your MFC app as been attached to it.
Also, how do you convert a CString to a DWORD (or anything you need for offsets) because let's say I have a simple text file, in which you can find.. let's say 00x412345 89, well I want to set the hex data 89 to the 00x412345 offset.. I hope you understand
Thanks for the help
|
|
|
|
|
#1: look at the OpenProcess and WriteProcessMemory functions.
#2: look up sscanf .
--
Mike Dimmick
|
|
|
|
|
Anonymous wrote:
I want to set the hex data 89 to the 00x412345 offset..
And why would you want to do that? Why aren't you logged in as a member?
// Afterall, I realized that even my comment lines have bugs
When one cannot invent, one must at least improve (in bed).-My latest fortune cookie
|
|
|
|
|
Hello all I am trying to make a game...
I have it dialog based and I have the Logon screen up but I don't know how to close that screen and open up the Game...
Anyone familier with Aol Instant Messenger (AIM)??
I guess that's what it's supposed to do.
[It is possible to represent everything in this universe by using 0 and 1]
I was born intelligent
Education ruined me!.
An idea is useless until it has been implemented.
|
|
|
|
|
snyp wrote:
but I don't know how to close that screen and open up the Game...
That being the case, you have no idea how to write a game, so take a step back, and learn some basics first.
I'd be inclined if I was using a dialog based app to just resize the same window, and hide the login stuff, and show the game stuff instead, all on the same dialog.
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
|
|
|
|
|