|
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
|
|
|
|
|
how is that possible to draw to text in view window using MFC .A Cstrng object containg the MEssage is in the ondraw function of view clas
|
|
|
|
|
Construct a CFont object and use the CFont::CreateFont( ) function to give you the attributes you need.
E.g.
CFont font, *pOldFont; //you will need pOldFont to store a pointer to the old font so you can reinstate it later.
font.CreateFont(....)
Load the font into the device context using pOldFont=pDC->SelectObject(&font)
Draw the text using pDC->DrawText(...);
When done reload the old font into the device context (pDC->SelectObject(pOldFont))
If you want spiral text then you will have to do some maths with sin and cos, adjusting nOrientation in the CFont object as you go.
Check out the CDC and CFont classes in MSDN.
Hope this helps
Adam.
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.
|
|
|
|
|
Hello all
I'm writing an application which uses serial port using vc++. I would like to code this app in such a way that if any other application is using serial port my application should stop it before proceeding and again should start the stopped application when my application is done. Pls suggest me the way to do it with an example.
thanks for your time,
Hari.
|
|
|
|
|
Please help me with this stupid problem.
I tried to load a dll dynamicly. I used LoadLibrary in my function. In this function I first diplay a CFileDialog to open some datafiles. After that i load my dll. But LoadLibrary return NULL. When I place my LoadLibraray before CFileDialog it seems to be OK.
Can you help me with this problem?
I the future i plan to load the library in a working thread. I tried this although but the result of LoadLibrary was NULL!
|
|
|
|
|
Is your DLL in your application directory? When your app is run, the current directory is set to your app directory (usually). Since LoadLibrary() looks in your app directory first, it find the DLL no problems. However, if the user changes the directory in the file dialog, the current directory is no longer set to your app directory, therefore LoadLibrary() can not find the DLL.
The best way to solve this is to specify the complete path in the call to LoadLibrary() .
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"
|
|
|
|
|
thank you for your help. I tried to specify the complete path in loadlibrary but the problem is still there...
When I try to load a different dll in the same codepassage all worked fine. The problem still excists in the first dll (but only in this passage!).
Do you have an idea?
|
|
|
|
|
Post the relevant parts of your code and I'll see if I can find anything.
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"
|
|
|
|
|
Hi,
I want to nest splitter windows, but I can't find any documentation on how to do that.
Before I'll try to write a derived class that supports nested splitting, is there anyone who can tell me where I can find information about nested splitter windows?
many thanks.
When elaphants fight it is the grass that suffers.
|
|
|
|
|
Bob Stanneveld wrote:
I want to nest splitter windows,
I presume you are talking about MFC? If so, AFAIK this isn't the way Microsoft wants you to do it (meaning, it's close to impossible).
Splitters are IIRC only handled by frame windows. Read that sentence again and you see the problem.
If you need nested splitters (which seems quite awkward to me, but perhaps you indeed have found a legit use for it) I think you need to do some programming for yourself to work around MFC deficiencies.
Disclaimer: I might be wrong, why you shouldn't read the text above as some absolute truth.
|
|
|
|
|
Thanks, I guess that I'll be busy this holiday
|
|
|
|
|
|
I'm using the class library provided with visual C++ 6.0.
Maybe I should study some WTL.
thanks a lot.
|
|
|
|
|
|
thanks
|
|
|
|