mitrmkar 1,056 Posting Virtuoso

so it should scramble the puzzle around right?

movePuzzle is the part where user can swap the order around (but the scrambling should be done in initPuzzle)

Hmm, but looking closely at initPuzzle(), it clearly achieves the scrambling by calling movePuzzle(...) on two occasions.

// scramble the puzzle
   for (y=0; y<=ROWS*COLS; y++) {
      if ((rand() % 2) == 0) {
         movePuzzle(puzzle, 'v', rand() % COLS); 
      }
      else {
         movePuzzle(puzzle, 'h', rand() % ROWS); 
      }
   }

So, this means that you have to write the code for movePuzzle(...) in order to have the puzzle scrambled. Once you have movePuzzle() coded, you can call it from the main() too (passing in the user's input).

mitrmkar 1,056 Posting Virtuoso

The function initPuzzle suppose to populate array, setup the puzzle and scramble the order of number.

As per the code you are given in puzzle.h, the scrambling of the puzzle is actually done by means of the movePuzzle(), hence I asked about its code. If you haven't coded it yet, your output will be the initialized puzzle, i.e. 1,2,3,4,5,6.

mitrmkar 1,056 Posting Virtuoso

does anyone know how to make the initPuzzle works properly?

What code you have in movePuzzle(...)?

mitrmkar 1,056 Posting Virtuoso

Hi, umm... I appreciate the concern for using sstream. But the project specification requires me not to add any other library in the code. I'm not allowed to change the puzzle.h (that means no new library should be used). Sorry but that's the limitation I have

Oh I see, let the professor have his/her ways then. But in the future, you know to avoid atoi() .

mitrmkar 1,056 Posting Virtuoso

About converting the seed, you'd be better of using stringstream (atoi() is a poor choice for that). Below is a snippet for the
conversion ...

#include <sstream>
#include <iostream>
using namespace std;

int main(int argc, char * argv[])
{
	// only two arguments accepted, check ...
	if(argc != 2)
	{
		cout << "Wrong number of arguments: " << argc << endl;
		return 1;
	}
	
	// Initialize the stringstream object with the argument
	stringstream ss(argv[1]);
	unsigned int seed;

	// Try converting the seed
	if( ! (ss >> seed))
	{
		cout << "Invalid argument for seed: " << argv[1] << endl;
		return 1;
	}

	cout << "Got seed: " << seed << endl;

	return 0;
}
mitrmkar 1,056 Posting Virtuoso

Think of bar->second as a map <string, int> , so simply ...

bar->second["abc"] = 123;
mitrmkar 1,056 Posting Virtuoso

Maybe you could post the "includes.h" file?

mitrmkar 1,056 Posting Virtuoso

yeah, I got the same situation.
I changed the path to C:\\TC\\BGI then an error message appear like this:
"16 bit MS-Dos sybsystem
Turbo C++IDE
The NTVDM CPU has encountered an illegal instruction.
CS:0000 IP:00 blah blah"
then I look down to my taskbar, I could saw my program for a moment then it gone.
Could some 1 plz help plz

Maybe print the error message (see grapherrormsg(...)) to a file to get a clue about what's wrong.

mitrmkar 1,056 Posting Virtuoso

Problem is that x is not initialized to zero (I take that you simply want to swap the values).

You might have it a bit simpler like ...

if (numB < numA)
{
    // use x only inside the if-block
    int x = numA;
    numA = numB;
    numB = x;
}
mitrmkar 1,056 Posting Virtuoso

hi,
i tried that before, but the problem with that is it will add all values into same vector<double> test.

When you tried that and noticed that problem, are you sure that you did not have the d.clear(); call. Because the clear(), as you now have it, will empty the vector (of the tmp Demo object) so you'll not be accumulating the values in the vectors.

Maybe I'm not fully understanding you, because I'd still say that if you pass the vector by reference, you'll get what you want. I.e.

I want to have the first double value in points, and the following two double values into unique vector<double> test for each user

mitrmkar 1,056 Posting Virtuoso

Pass the vector by reference just like you already pass the Demo object.

istream& operator>> (std::istream& in, vector<double> & d);
std::istream& operator>> (std::istream& in, vector<double> & d)

Maybe read about References

mitrmkar 1,056 Posting Virtuoso

Some comments ...

//Adding the two numbers together
int Add(int num1, int num2)
{
	int addedTotal;
// sum up the values ...
	addedTotal = num1 + num2;
// display text ...
	cout << "The two numbers added together are: ";
// get the value from user ... why?
	cin >> addedTotal;
// return the value gotten from user ...
	return addedTotal;
}
mitrmkar 1,056 Posting Virtuoso

As long as you have an internet connection, you can always check online, whether or not your code compiles. Below are couple links:
Comeau
and
DINKUMWARE

mitrmkar 1,056 Posting Virtuoso

Retrieves an integer associated with a key in the specified section of an initialization file.

Not sure but I dont think that reads will read a percent, am I wrong??

If you represent the values as integers (e.g. 0 .. 100), then it will work. So a working .ini file might look like ..

[section]
; with % -sign
value1=15%
; without % -sign
value2=99
mitrmkar 1,056 Posting Virtuoso

mitrmkar - Red bar while compiling on line:

if(!ExitWindowsEx(EWX_POWEROFF, SHTDN_REASON_MAJOR_OTHER|SHTDN_REASON_MINOR_OTHER))

I think it is the compiler?
Anyone else using codeblocks?
It always used to work?
Maybe needs a plugin or something similar?

*RAWR* this is doing my head in :|

Maybe your codeblocks is old enough to not to have the following definitions

#ifndef SHTDN_REASON_MAJOR_OTHER
#define SHTDN_REASON_MAJOR_OTHER           0x00000000
#define SHTDN_REASON_MINOR_OTHER           0x00000000
#endif// ndef SHTDN_REASON_MAJOR_OTHER
#ifndef EWX_POWEROFF
#define EWX_POWEROFF           0x00000008
#endif// ndef EWX_POWEROFF

Just add those defines (above main()) and retry.

mitrmkar 1,056 Posting Virtuoso

I am administrator, so... lol
cause my cmd works fine cant get anything working through C++.

Did you get the UAC prompt when you ran the shutdown.exe command? If you did, then you'll need a manifest like jbennet showed.

I think the user will have to be logged in under an Administrative account for that to work.

I think it is rather a Policy Configuration issue, i.e. "Shut down the system" - user right, which is assigned on a per-account/group basis.

mitrmkar 1,056 Posting Virtuoso

Maybe you could try out the following program, and post back its output. It might give some clue about what is not working.

#include <windows.h>
#include <stdio.h>

BOOL SetPrivilege
(
    HANDLE hToken,          // access token handle
    LPCTSTR lpszPrivilege,  // name of privilege to enable/disable
    BOOL bSetPrivilege      // to enable or disable privilege
) 
{
    TOKEN_PRIVILEGES tp;
    LUID luid;

    if (!LookupPrivilegeValue( 
        NULL,            // lookup privilege on local system
        lpszPrivilege,   // privilege to lookup 
        &luid ) )        // receives LUID of privilege
    {
        printf("LookupPrivilegeValue error: %lu\n", GetLastError()); 
        return FALSE; 
    }

    tp.PrivilegeCount = 1;
    tp.Privileges[0].Luid = luid;

    if (bSetPrivilege)
        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    else
        tp.Privileges[0].Attributes = 0;

    if (!AdjustTokenPrivileges(
        hToken, 
        FALSE, 
        &tp, 
        sizeof(TOKEN_PRIVILEGES), 
        (PTOKEN_PRIVILEGES) NULL, 
        (PDWORD) NULL))
    { 
        printf("AdjustTokenPrivileges error: %lu\n", GetLastError()); 
        return FALSE; 
    } 

    if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
    {
        printf("The token does not have the specified privilege.\n");
        return FALSE;
    } 

    printf("Privilege was set ...\n");

    return TRUE;
}

int main()
{
    HANDLE hToken;

    if(!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES, &hToken))
    {
        printf("OpenProcessToken: error %lu\n" , GetLastError());
        return 0;
    }

    if(SetPrivilege(hToken, "SeShutdownPrivilege", TRUE))
    {
        if(!ExitWindowsEx(EWX_POWEROFF, SHTDN_REASON_MAJOR_OTHER|SHTDN_REASON_MINOR_OTHER))
        {
             printf("ExitWindowsEx: error %lu\n" , GetLastError());
        }
        else
        {
              printf("Shutdown initiated ...\n");
        }
    }

    CloseHandle(hToken);

    return 0;
}
mitrmkar 1,056 Posting Virtuoso

I dont know how to read a number value..

See GetPrivateProfileInt Function

mitrmkar 1,056 Posting Virtuoso

Btw that command wont work on vista i dont think

Nothing in the MSDN documentation on ExitWindowsEx() indicates that. How did you came into that conclusion?

mitrmkar 1,056 Posting Virtuoso

So what looks to be the problem?

There might be many reasons, e.g. any application you have open may also abort the shutdown (since you are not forcing it), maybe your system does not support the power-off feature or your program lacks the shutdown privilege etc.

To get a bit more clue about what is going wrong, check which error code GetLastError() returns immediately after the ExitWindowsEx() call ... I.e.

if( ! ExitWindowsEx(...))
{
    // maybe lastError will tell something useful ...
    DWORD lastError = GetLastError();
}

Note that even if ExitWindowsEx() returns non-zero, it does not necessarily mean that the shutdown will eventually occur. (Read the MSDN documentation carefully and (try to) understand it.)

You might also try the How to Shut Down the System sample function (it shows how to enable the shutdown privilege among other things).

mitrmkar 1,056 Posting Virtuoso

Never use system() on Win32
Use Win32 api (TP and others)

What on earth "TP and others" means?

mitrmkar 1,056 Posting Virtuoso

yes. it's just a cpp file (probably could be .h) that holds some enums. no actual code in it or includes

There is a contradiction, in your first post you say that "Each file has: #include "include.h"". If enum.cpp actually includes include.h, that results in the error you described.

[EDIT]
Assuming "Each file" refers to source files ...
[/EDIT]

mitrmkar 1,056 Posting Virtuoso
+		rgbb	0x0044714c "øÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍþÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"	unsigned char [3]

And when Im writing to a new file, it writes just the bits, and put all this junk just after it??...Am Im imagining too much?

Now remember the second parameter to write() , that specifies how many bytes are written.

PS. Maybe you could try to re-post your code

mitrmkar 1,056 Posting Virtuoso

Learn how to use code tags, without code tags, your code is pretty much unreadable.

If you expect to be helped, shouldn't you ask a question?

mitrmkar 1,056 Posting Virtuoso

using this :

writer.write(reinterpret_cast<char*>(&img_pix[i].rgb) ,sizeof(img_pix[i].rgb));

the file gets 10,7 MB o__o"
using this :

writer.write(reinterpret_cast<char*>(&img_pix[i].rgb[0]) ,sizeof(img_pix[i].rgb[0]));

the file gets 3,4 MB ..
using this:

writer.write(&img_pix[i].rgbb[0],sizeof(img_pix[i].rgbb[0]));

the file gets 914KB
using this:

writer.write(reinterpret_cast<char*>(&img_pix[i].rgbb) ,sizeof(img_pix[i].rgbb));

the file gets 2,67 MB
using this:

writer.write(reinterpret_cast<char*>(&img_pix[i].rgbb[0]) ,sizeof(img_pix[i].rgbb[0]));

the file gets 914 KB

It seems that you are desperately trying various ways to write the file.

Maybe relax and try to master e.g. a binary .pnm file of a very small size, say 2x2 pixels hence being easily viewed in any hexeditor at a glance (notepad and wordpad surely are poor choices for checking the files' content).

Try for example the following struct for reading/writing

struct Pixel
{
    // 3 bytes represents a single pixel
    unsigned char rgb[3];
};

Then when you read in the file you might

// ... code here to read in the file's header ...

// allocate enough memory to read in rest of the file
const int pixels = width * height;
Pixel * p = new Pixel[pixels];

for(int ii = 0; ii < pixels; ++ii)
{
    // read 3 bytes at a time
    if( ! file.read(reinterpret_cast<char *>(p[ii].rgb), 3))
    {
        // should not happen, handle error ...
        break;
    }
}

// all done

Then to write the file, you can iterate over the array issuing file.write(reinterpret_cast<const char *>(p[ii].rgb), 3) Remember that the second parameter to both read() and write() determines how many bytes each I/O operation involves.

mitrmkar 1,056 Posting Virtuoso

I'm running MSVC 6.0 on Vista Home Premium

Umm, maybe you misunderstood me (?). I was not trying to say that MSVC 6.0 cannot be used on Windows versions later than "Windows Server 2003".

Instead, I was trying to say that the "Windows Server 2003 Platform SDK" is the last SDK version that is compatible and works with MSVC 6.0.

Ancient Dragon commented: I re-read your post and you are right -- I misread it. +36
mitrmkar 1,056 Posting Virtuoso

Okay so i have windows XP, Microsoft Visual C++ 2008 Express Edition, what SDK do i need?

You might look at Using Visual C++ 2008 Express with the Windows SDK

Nick Evan commented: Good link +14
mitrmkar 1,056 Posting Virtuoso

So does anyone know where i can get a replacement winbase.h?
Or perhaps where i could just re-download all headers?

Don't ever replace/modify the system header files, instead simply get a complete SDK, which is guaranteed to be compatible with your compiler.

mitrmkar 1,056 Posting Virtuoso

With MSVC 6.0, the latest Windows SDK that can be used is the Windows Server 2003 Platform SDK

Either switch to that old SDK or get e.g. a VS Express edition, which works with your current SDK.

mitrmkar 1,056 Posting Virtuoso

void createAlpha(char **&data, int elements); Sorry, but that is strictly a C++ feature, not C.

mitrmkar 1,056 Posting Virtuoso

Assuming that the warnings are ok and they are arising out of so many different files, is there a way to supress them in the Makefile so that they dont pop up?

Consult the compiler documentation.

mitrmkar 1,056 Posting Virtuoso

Unmanaged Win32 Code, is directly interfacing with the win32 API. Managed Win32 is using the MFC. Which is what MVC++ users tend to do. Thus you do not need the catorgarized link that he sent you, but you need the MFC, since this will probably easier for you. The MFC (Microsoft Fundamental Class) is a wrapper for the Win32 API making it easier and faster (in some cases) to write GUI Interfaces

That's not true by any means. MFC (Microsoft Foundation Classes) is just a wrapper around the Win32 API.
One definition of Managed code

In my opinion, in order for the MFC to be proficiently used, the basic knowledge of the underlying Win32 API concepts is pretty much required.

mitrmkar 1,056 Posting Virtuoso
mitrmkar 1,056 Posting Virtuoso

The function prototype for ON_MESSAGE() is afx_msg LRESULT memberFxn( WPARAM, LPARAM ); Ctry_ENTERDlg::OnBnClickedButton1 does not match, so you might add a new member function which handles the message.

See User-Defined Handlers

mitrmkar 1,056 Posting Virtuoso

Unfortunately, there is only one occurrence of the prototype, and thats in the header of the static library.

I'm really at a loss at this point...

You might try posting on the MSDN's Visual C++ General forum.

mitrmkar 1,056 Posting Virtuoso

It is enabled and it doesnt seem to work. Could you write a quick code example which works for you so I can test it out? I thought my example worked but maybe it doesnt.

struct test
{
    int completion;
};

int main(int argc, char *argv[])
{
    test code;
    code // <- type in a . and a list displaying 
         // 'Variable int completion' should appear
    return EXIT_SUCCESS;
}

That works for me, I'm trying out the 7.0 RC3 version.

mitrmkar 1,056 Posting Virtuoso

...ask this type of question in a public greek lounge.

Err, this is "Geeks' Lounge" not "Greek Lounge". Maybe you'd like to submit your post at Greek Lounge ;)

mitrmkar 1,056 Posting Virtuoso

Hey

In VS, you can in a struct do:

struct test{
int tes;
}tt;

then when I put tt., it would display the all fields in a tooltip which in this case would display tes. Is "IntelliSense" (I know it is not called that) in wxDev-C++?

It's called code completion/class browsing in wxDev-C++. See Tools/Editor Options/Class browsing.

mitrmkar 1,056 Posting Virtuoso

If I use the uncommented 3 lines for getting an int out of a stringstream, the value in MPV is wrong. However, if I make a new stringstream, then it works fine. I thought setting .str("") was essentially resetting the stringstream?

If the stream object is in error state, then you also need to call clear() in order to make the object functional again. Could that be the reason in this case?

mitrmkar 1,056 Posting Virtuoso

I'm dealing with a map of vectors, and I'm making sure I clean up all the memory used. So, what exactly is the best way to handle this?

As soon as the map goes out of scope, its destructor takes care of destructing all the vectors, whose destructors in turn destruct all the strings. So it all happens automagically (as long as you are not storing pointers to objects)

mitrmkar 1,056 Posting Virtuoso

resource.h is not the place to define _WIN32_IE. Do it instead above the #includes, i.e.

#define _WIN32_IE 0x0301
#include <windows.h>
#include <commctrl.h>

Or alternatively in the project's configuration.

mitrmkar 1,056 Posting Virtuoso

I still get an error:

Main.cpp In function `BOOL DlgProc(HWND__*, UINT, WPARAM, LPARAM)': 
Main.cpp `InitCommonControlsEx' undeclared (first use this function) 
  (Each undeclared identifier is reported only once for each function it appears in.) 
 Makefile.win [Build Error]  [Main.o] Error 1

In your project, #define _WIN32_IE to at least 0x0300 .

InitCommonControlsEx() takes a pointer to a INITCOMMONCONTROLSEX struct. You are not using the function correctly ...

I added the WM_CREATE in the Message switch

case WM_CREATE:
    InitCommonControlsEx();
break;
mitrmkar 1,056 Posting Virtuoso

A typo has slipped in ... it should be localVariable .

mitrmkar 1,056 Posting Virtuoso

Seems pretty simple to me, add this to the dialog message procedure, and windows shouldn't handle the ALT-F4.

case WM_SYSKEYDOWN: break;

Hmm .. that renders the system menu completely ineffective, which is probably not what the OP wants.

mitrmkar 1,056 Posting Virtuoso

You sure it's not WM_CLOSE?

Yes, SC_CLOSE comes with WM_SYSCOMMAND.

mitrmkar 1,056 Posting Virtuoso

How can i prevent a dialog closing by Alt+F4 ?
I am using PreTranslateMessage()

Instead of PreTranslateMessage(), add a handler for WM_SYSCOMMAND and detect SC_CLOSE.

mitrmkar 1,056 Posting Virtuoso

Setting the Default to a specific button is not the solution I want because in the future I would want 10 edit boxes with 10 buttons to correspond to each box.
I'm looking for a more generic solution.
Thanks.

Seems that I misunderstood the problem. Anyhow, the CMyEdit class' code that you have should capture the Enter key.
Maybe you don't have the following in the dialog class implementation

DDX_Control(pDX, IDC_EDIT1, m_eFirst);
mitrmkar 1,056 Posting Virtuoso

Read about Name Decoration. You need to learn how to use extern "C" .

mitrmkar 1,056 Posting Virtuoso

What I would like is that when write text in the first edit box and hit ENTER the dialog would push the first button that I created.

That functionality can be achieved by simply making sure that:

  • the first button (only) has the 'default button' -option checked
  • the first edit box does not have the 'want return' -option checked OR it is not a multiline edit control
mitrmkar 1,056 Posting Virtuoso

Could you post the latest version of the project?