|
Like a puzzle game, how can I swap the 'hole' with the 'target element'? I use 'switch' and 'pointer' but failed!! Pls advise!!
//Moving the hole.
void Move(int& holeidx,int move)
{
int tar_row; //The row of the target element
int tar_col; //The column of the target element
int hrow; //The row of the hole
int hcol; //The column of the hole
int temp=0; //A temporary variable for swapping
int number; //The index number of the target element
hrow = holeidx / size; //Calculate the row number of the hole
hcol = holeidx % size; //Calculate the column number of the hole
int* phole = 0; //The pointer of the hole
switch(move)
{
case 49: //(Press 1)
phole = &holeidx;
tar_row = ++hrow;
tar_col = --hcol;
break;
case 50: //(Press 2)
phole = &holeidx;
tar_row = ++hrow;
tar_col = hcol;
break;
case 51: //(Press 3)
phole = &holeidx;
tar_row = ++hrow;
tar_col = ++hcol;
break;
case 52: //(Press 4)
phole = &holeidx;
tar_row = hrow;
tar_col = --hcol;
break;
case 53: //(Press 5)
phole = &holeidx;
tar_row = hrow;
tar_col = hcol;
break;
case 54: //(Press 6)
phole = &holeidx;
tar_row = hrow;
tar_col = ++hcol;
break;
case 55: //(Press 7)
phole = &holeidx;
tar_row = --hrow;
tar_col = --hcol;
break;
case 56: //(Press 8)
phole = &holeidx;
tar_row = --hrow;
tar_col = hcol;
break;
case 57: //(Press 9)
phole = &holeidx;
tar_row = --hrow;
tar_col = ++hcol;
break;
case 113: //(Press q)
case 81: //(Press Q)
exit(1); //If Press Q to quit, exit the game directly.
break;
default:
break;
}
|
|
|
|
|
I'm not sure what you're doing with phole , but it's being assigned the same value in every case of the switch statement. This is inefficient. Most of all, though, you don't need phole at all.
In addition, you don't need tar_row and tar_col either. Your switch statement can simply increment or decrement hrow and/or hcol directly. When you're finished, just convert these values back into holeidx .
You can stop here. This will solve your problem. Also...
You can remove the switch statement altogether and use a lookup table. Translate the '1' through '9' values into an index into this table. Table entries would be simple structs holding the modification to the row and column variables. You only need special traps for the 'q' key.
This table could be simplified even further by storing the modifier to holeidx . But this table would have to be built at run-time, since the value of size isn't known until then.
Bob Ciora
-- modified at 18:04 Friday 27th January, 2006
|
|
|
|
|
I used to use a manifest file in the resources. But now with vc8, for the same app, I want it to get autogenerated (just like when you create a new project). Where's the setting that enables themes in the app and gets the right manifest to get generated? Please help...
Thanks!
swine
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
I had the same trouble migrating from vc71. The first thing you need to do is remove your old manifest file from the resources.
Secondly, you need to add a small snippet of code to your vc6 project that exists in new vc8 projects, but is missing from migrated projects.
Create a new vc8 mfc project - at the bottom of the stdafx.h file, you'll see something like this:
<br />
...<br />
#ifdef _UNICODE<br />
<br />
...<br />
<br />
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")<br />
<br />
...<br />
<br />
#endif<br />
Copy the entire #ifdef block to the stdafx.h file of your old project and it should remedy the problem.
"My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine
|
|
|
|
|
ok i did that, and did a rebuild all, but it still doesn't work... anything else?
thanks
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
Strange, it worked for me and a handful of others I've talked to. I wonder if there's a setting that doesn't get updated from VC6 to 2005 that does with 2003 to 2005.
I would just create a simple VS 2005 project, and verify that the Linker -> Manifest File and Manifest Tool settings match that of your updated project.
If they're the same, and you still can't get it to work, I'd try posting something to the MSDN forums:
http://forums.microsoft.com/MSDN/default.aspx?ForumGroupID=8&SiteID=1
"My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine
|
|
|
|
|
Try removing the #ifdef _UNICODE .... #endif block
-Prakash
|
|
|
|
|
Brilliant! That did it.... Thanks
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
We use a combination of malloc() and the new operator in our VC++ programs. How can we get a summary of either or both items total memory allocation? The heap walker stuff doesn't seem to do anything unless you use those dinosaur LocalAlloc() / GlobalAlloc() calls which are not portable to Unix.
thanks for any help
|
|
|
|
|
|
Another method would be to use "Performance Counters" on that process. I believe there may be a few other APIs that get various information as well.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
Thanks Toby! There's still too much instrumentation for our simple needs. Here is what made the boss happy:
C:\Temp>printmemorystats.exe
total used 5054, free 760
OK - end of heap
total used 10174, free 3816
OK - end of heap
total used 12222, free 1760
OK - end of heap
total used 16318, free 5848
OK - end of heap
total used 24510, free 9936
OK - end of heap
total used 40894, free 14024
OK - end of heap
total used 73662, free 22128
OK - end of heap
total used 139198, free 26216
OK - end of heap
total used 270270, free 30304
OK - end of heap
total used 532414, free 34392
OK - end of heap
<code>#include <malloc.h>
#include <stdio.h>
static void PrintMemoryStats();
int main()
{
int sizemem=1024;
int ii;
char *foo;
for (ii=0; ii<10; ii++) {
PrintMemoryStats();
foo = malloc(sizemem);
sizemem *= 2;
}
}
static void PrintMemoryStats()
{
_HEAPINFO hinfo;
int heapstatus;
long totalUsed = 0, totalFree = 0;
hinfo._pentry = NULL;
while( ( heapstatus = _heapwalk( &hinfo ) ) == _HEAPOK )
{
if (hinfo._useflag == _USEDENTRY)
totalUsed += hinfo._size;
else if (hinfo._useflag == _FREEENTRY)
totalFree += hinfo._size;
}
printf ("total used %ld, free %ld\n", totalUsed, totalFree);
switch( heapstatus )
{
case _HEAPEMPTY:
printf( "OK - empty heap\n" );
break;
case _HEAPEND:
printf( "OK - end of heap\n" );
break;
case _HEAPBADPTR:
printf( "ERROR - bad pointer to heap\n" );
break;
case _HEAPBADBEGIN:
printf( "ERROR - bad start of heap\n" );
break;
case _HEAPBADNODE:
printf( "ERROR - bad node in heap\n" );
break;
}
}
</code>
-- modified at 15:25 Friday 27th January, 2006</code>
|
|
|
|
|
See if this helps.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
I need to make a combobox by which user can choose color they want. what kind of method can I use?
thanks.
|
|
|
|
|
|
Although it's not a combobox, there's also MFC's CColorDialog class.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Help!
Does anybody know the code on the web page, mentioned below? It should make working with ListControls much easier.
I added the code to my project, and made the changements in the code as described. I am using a dialog-based application. To make it work, do I have to create a dialog, which is equal to the one, which is shown in the example? Or should it work for every dialog using a ListBox?
Thanks!
-- modified at 10:49 Friday 27th January, 2006
|
|
|
|
|
Try posting your questions on the message board for that article - you'll probably get better help there (as the article author will get your question emailed to him)
--
Help me! I'm turning into a grapefruit!
Buzzwords!
|
|
|
|
|
class A
{
public :
virtual void foo() { } ;
};
class B : public virtual A
{
public :
virtual void foo() { } ;
};
class C : public virtual A
{
public :
virtual void foo() { } ;
};
class D : public B , public C
{
public :
} ;
say somewhere in code
D *ptr ;
..
....
ptr->Foo()
whose copy of Foo() will i call ? Will it be B's copy as it is the first inherited class during declaration from left to right ?
|
|
|
|
|
act_x wrote: whose copy of Foo() will i call ?
Why not just try it and see?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
I don't know, and I always try not to do that kind of multiple inheritance; and having a common base class worsen it.
I think that the
the way ( i think ) to resolve ambiguity, is to explicitly call the method :
ptr->B::food();
ptr->C::food();
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
act_x wrote: whose copy of Foo() will i call ?
None. The code will not even compile.
And adding virtual keyword to B and C classes does not have a sense in this case as the existance of class A.
Try compiling next code, it will not compile also :
#include "stdafx.h"
#include <iostream>
using namespace std;
class B
{
public :
virtual void foo() { } ;
};
class C
{
public :
virtual void foo() { } ;
};
class D : public B , public C
{
public :
} ;
int _tmain(int argc, _TCHAR* argv[])
{
D *ptr = new D ;
ptr->foo();
delete ptr;
return 0;
}
Adding virtual keyword assures that D will inherit just one copy of members of A.
Consider we have next code :
#include "stdafx.h"
#include <iostream>
using namespace std;
class A
{
public :
virtual void GetX() { cout<<X; } ;
int X;
};
class B : public virtual A
{
public :
void setXB() {X = 20;}
};
class C : public virtual A
{
public :
void setXC() {X = 30;}
};
class D : public B , public C
{
public :
} ;
int _tmain(int argc, _TCHAR* argv[])
{
D *p = new D();
p->setXC();
p->setXB();
p->GetX();
delete p;
return 0;
}
PS. By adding virtual keyword to B and C classes we are sure that B and C " share same instance of class A ".
Therefore output will be 20.
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
-- modified at 14:06 Friday 27th January, 2006
|
|
|
|
|
I have a 2 dimensional array created with the new operater,
int (*treeinbunch)[1000][20];
treeinbunch = new int [1000][1000][20];
that works fine throughout the program. When I try to pass it to a function to retrieve values from it, it doesn't work.
The function call uses this: function(int piece[1000][20]) and compiles fine, but
the values of piece in the function are garbage. If I replace piece in the function with *treeinbunch[index][index] it works fine. Why isn't piece initialized with the values of treeinbunch? How do I pass the array treeinbunch without losing its values?
Fleetmanager gone wrong
-- modified at 11:11 Friday 27th January, 2006
|
|
|
|
|
fleetmanager wrote: If I replace piece in the function with *treeinbunch[index][index] it works fine...How do I pass the array treeinbunch without losing its values?
Aren't these two contradictory? Are you still losing values with the modified function signature?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
m_bAutoMenuEnable is member of CFrameWnd.
how to Auto Enable Menu for dialog similar to CFrameWnd?
A nice tool for optimizing your Microsoft html-help contents.
Includeh10
|
|
|
|