|
I'll assume we have an array as follows:
enum
{
MatrixWidth = 2,
MatrixHeight = 2
};
char g_Matrix[MatrixWidth][MatrixHeight];
I'll store the coordinates of the hole in the following variables:
int g_HoleX;
int g_HoleY;
To clarrify your matrix has the following properties:
g_Matrix[0][0] = 'C';
g_Matrix[1][0] = 'A';
g_Matrix[0][1] = 'B';
g_Matrix[1][1] = 'h';
g_HoleX = 1;
g_HoleY = 1;
The following function should move the hole:
enum Direction
{
Up,
Down,
Left,
Right
};
bool Move(Direction dir)
{
int x = g_HoleX;
int y = g_HoleY;
switch(dir)
{
case Up:
if (g_HoleY == 0)
{
return false;
}
y -= 1;
break;
case Down:
if (g_HoleY == MatrixHeight-1)
{
return false;
}
y += 1;
break;
case Left:
if (g_HoleX == 0)
{
return false;
}
x -= 1;
break;
case Right:
if (g_HoleX == MatrixWidth-1)
{
return false;
}
x += 1;
break;
}
char temp = g_Matrix[g_HoleX][g_HoleY];
g_Matrix[g_HoleX][g_HoleY] = g_Matrix[x][y];
g_Matrix[x][y] = temp;
g_HoleX = x;
g_HoleY = y;
return true;
}
NOTE: I have not tested any of this. If you want diagonals you'll have to modify it slightly.
Steve
-- modified at 4:56 Wednesday 1st February, 2006
|
|
|
|
|
Hello,
What is the ascii code for CTRL+ESC???
In one of my applications, to enter one test I have to press CTRL+ESC and ESC for returning from it.
I know the ASCII code for ESC. It is 27(0x1B).
But, what is code for CTRL+ESC??
Somebody help!!!!
Regards,
mysticlol
|
|
|
|
|
There are no ASCII code for CTRL-ESC.
The CTRL key is used to remove 0x40 from the normal charater key pressed.
That way one can produce a control-ASCII character from a normal keyboard. For instance, pressing CTRL G will give the ASCII code 0x7 (BEL(L)).
Pressing a plain G will produce the ASCII character G (obviously!), wich has the ASCII code 0x47.
So you have to check for the virtual key codes to be able to trap CTRL-ESC.
|
|
|
|
|
Use GetKeyState() to check if the CTRL key is down when you handle the ESC key.
if (KeyPressed == VK_ESCAPE && (GetKeyState(VK_CONTROL) & (1 << sizeof(SHORT) * 8 - 1)))
{
} The & (1 << sizeof(SHORT) * 8 -1) code is used to check only the high-order bit of GetKeyState 's return value.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
please help me:
i have to create an extension for thunderbird not for firefox so i want tutorial for how to create extension and use this.
reply me ASAP.
Bankey Khandelwal
Software Engineer
|
|
|
|
|
Hi
I am writing an application, which i am using to find out the files opened through the Open/Save As dialog of Ms-Office. The WM_OBJECTSEL message is generated by the dialog whenever a new file is opened. Does anyone know the messages identifier of this message. Thanks in advance.
|
|
|
|
|
Info seems sketchy but I'm guessing like this:
UINT WM_OBJECTSEL = RegisterWindowMessage(_T("WM_OBJECTSEL"));
Steve
|
|
|
|
|
Thanks . But how can i get the filename from this message. Whether the LPARAM or WPARAM will have the value. Can you please brief me on this.
|
|
|
|
|
Hi,
When I run my application the memory usage increases upto 30MB. The moment I minimize the GUI, the memory usage comes down to less than 1MB. Even when I maximize it back, the memory increase is just 2-3MB. I understand that when we minimize the app. the physical memory is temporarily written to the page file on the hard disk. But once I maximize the app, the page file should be written back to physical memory, but it shows much lesser memory usage. Though my application is running fine, but this memory thing is bothering me. Any idea what could be happening?
Thanx,
Ratna
|
|
|
|
|
What language is it written in? What libraries are used? For example, I believe this kind of behavior is common with dotNET applications (from what I hear).
Steve
|
|
|
|
|
Hi,
The front end is in VB6, but no major memory allocation is being done in VB. The backend(dll) is in VC++, where 99% of the memory work is done. Other than that no particular libraries are being used.
Thnx,
Ratna
|
|
|
|
|
This is normal behavior. When you minimize the app, the system makes memory that was allocated for your application available to be used elsewhere. As you run the app, more memory is set aside for your app (it's called the Process Working Set).
Once you have minimized it and then restore it, there is no need to automatically reassign all that memory to your app, as it probably doesn't need it immediately. When you app then requires more memory, it will be added to the working set.
Hope that helps explain it.
Karl - WK5M
PP-ASEL-IA (N43CS)
<kmedcalf@ev1.net>
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
in my MDI project. there is a "CGridCtrl m_Grid" variable in MyView. I want MyView to intercept Windows Message to m_Grid. Can I do that?
I was thinking SubclassDlgItem may work, but I realy can't to figure it out. Any help is appreciate.
|
|
|
|
|
If you just want posted and input messages you could overide PreTranslateMessage in your view class. If you want all messages, not just those dispatched by the message loop, it will be harder. One option would be to subclass the control and have the new WindowProc delegate the work to your view class.
Steve
|
|
|
|
|
Hi there.
I have two projects in a solution (VS8.0) and the first has a dependency on the other. Both projects produce dlls. Now I want to define a simple singleton and use it from both dlls. So the code is easy:
<br />
class _MyProject_Export BuilderFactory :<br />
public util::DllFactory<Builder><br />
{<br />
public:<br />
static BuilderFactory& Instance(void)<br />
{<br />
static BuilderFactory singleton;<br />
return singleton;<br />
}<br />
};<br />
Ok we have a BuilderFactory class that it inherits from another class and just define a static member Instance to get reference to my singleton. Of course having such a code you are going to templatize the code in the following fashion:
<br />
template <class T><br />
class Singleton<br />
{<br />
public:<br />
typedef T SingletonType;<br />
<br />
static T& Instance(void)<br />
{<br />
static T singleton;<br />
return singleton;<br />
}<br />
<br />
private:<br />
Singleton(void) {}<br />
Singleton(const Singleton&);<br />
Singleton& operator =(const Singleton&);<br />
virtual ~Singleton(void) {}<br />
};<br />
<br />
typedef Singleton<<br />
util::DllFactory<Builder><br />
> BuilderFactory;<br />
Both example compile successfully, however the latter doesn't work! Just can't understand why.
I came to believe that in the latter case two different instances exist in my program. As I'm registering builders in the factory from on dll and the second doesnt have any. I suspect that something has to do with exporting of symbols as I don't export anything in the latter case, but what am I supposed to export, the typedef?
Any ideas?
|
|
|
|
|
Is it possible to remove the minimize/maximize/close buttons from a non-dialog application. I'm working on an application where we don't want them displayed. I believe you can disable their functionality by removing their corresponding menu commands, but that still leaves the buttons visible.
|
|
|
|
|
rentzk wrote: Is it possible to remove the minimize/maximize/close
Remove WM_SYSMENU style from the concerned window's style.
Jesus Lives Forever - Amen <marquee direction="up" height="40" scrolldelay="10" step=".5" scrollamount="1" style="background:#99ccff;border-bottom:thin solid 1px #6699cc">
--Owner drawn
--An eye for an eye makes the whole world blind.
--If you find my post helpful then do rate it.
--Jesus is Lord
|
|
|
|
|
Owner drawn wrote: rentzk wrote:
Is it possible to remove the minimize/maximize/close
Remove WM_SYSMENU style from the concerned window's style.
Any sugestions about how to do this to the main window? I've done this before with dialogs in an application, but this is the first time I've ever attempted doing it for the entire program.
|
|
|
|
|
|
I am using a dialog based application. I try to maximize it the dialog to whole screen. but the buttons I add it can not set to the bottom. Anybody please give me a hint or methodes.
In addition, I want to add a connection to the datebase. Is it possible to add it to the dialog?
Thanks in advance!
|
|
|
|
|
HI
Your first part of the question is not that clear.What do you want to do . What I figured is that you want to add Maximized button to the dialog????
As far as Database connection is considered :
Derive a class from CRecordSet
Override method GetDefaultConnect , GetDefaultSQL.
Now include this derived class into your project , Create an object of CDatabaseX(if this is the class that you derived from CRecordSet) and use its function.
You need to know the details of the driver and how are you going to connect through it.(DSN etc...)
Wishes.
Anshuman Dandekar
Dare to Dream,
Care to Achieve.............
|
|
|
|
|
I really want to do is that I try to get white screen with only one status bar. The white screen while display a image.
because I do not want title bar and menu, I think use dialog based application is easier. Am I right?
|
|
|
|
|
I try to hide the menu and only show the toolbar in MFC application? Can somebody tell me how to do it?
|
|
|
|
|
Call SetMenu(NULL) on your main frame, followed by DrawMenuBar() to update the screen
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 have read what i could find and even looked at a few programs from here but i just cant figure out how to get them to change when i press one of them first what event do i use ? a keydown or a keyup or ??? i know VK_CAPITAL is for caps lock and VK_NUMLOCK is num lock and VK_SCROLL is scroll lock but thats about all i know on how to do it. i am very very
EDIT - I figured it out use PreTranslateMessage and
if (GetKeyState(VK_SCROLL) && 0x8000 == 0x8000)<br />
{<br />
m_bar.SetPaneText(3, "SCRL", TRUE);<br />
} works for me anyway
-- modified at 20:05 Tuesday 31st January, 2006
|
|
|
|