triumphost 120 Posting Whiz

K well I designed my Interface already:
http://i.imgur.com/XCJU3.png

I looked at CMake I'm not sure but it seems like its for buildiing my project.. I don't want to build my project. I want my project to build my code in the text editor. I've looked at G++ commands and used a couple but my commands are extremely long!

ProjectFolder>g++ main.cpp -I"Libraries/ZLib" -I"Libraries/Curl"
-I"Libraries/Boost" -I"........\MinGW\include" -L"C:\MinGW\lib\libgdi32.a" -
L"Libraries\ZLib\libz.a" -L"curl" -L"ws2_32" -L"wldap32" -L"winmm" -L"Libraries\
Boost\lib\libboost_regex-mgw46-mt-1_47.a" -L"Libraries\Boost\lib" -l"gdiplus"

Like that but that's only HALF my command :S.. It also gives me a ton of unresolved symbols and external stuff missing. I'm not sure if order matters or not but that command is so long that there has to be an easier or another way.

How can I get my program to do that for me?

triumphost 120 Posting Whiz

Is it necessary to seperate the headers from the source?

For example I don't know why but I love to do:

//Foo.H

class Foo
{
    Foo(){}
    ~Foo(){}

    void Func()
    {
       //.........
       //.........
    }

    void Func2()
    {
        //........
        //........
    }

};

Instead of doing:

//Foo.H
class Foo
{
   Foo();
   ~Foo();

   void Func();
   void Func2();
};

//Foo.cpp
Foo::Foo()
{
  //.....
}

Foo::~Foo()
{
   //......
}

Foo::void Func()
{
   //.....
}

Foo::void Func2()
{
    //....
}

The second example which Hate to do seems like so much more work. Not only that but I'd have to constantly switch back and forth between headers and sources to see whats declared where or what contains what. But now I'm looking up all my habbits to see if they cause performance degradation and I've read the first one does whereas the second doesn't :S

I'm also reading that if i put my definitions inside the class, it's automatically inlined and that if I put the inline keyword in there then it's even worse :S Should I just leave them in there as inline and if not then why? Is there a way to define them inside the class and NOT be inlined?

Is this true? Am I actually doing something bad? I'm being told to never put the definitions in a header.. Only declarations.. Apparently it slows down compile time and slows down my program which is what I read at stack overflow from someone asking a similar question. I use header …

triumphost 120 Posting Whiz

I want to start developing an IDE or at least a Syntax highlighter into my program. Atm it's a simple text editor with basic copy paste functions.

How does Notepad++ do it? Is there a way I can integrate that into my own program? If not then I'll write it on my own. Also how does codeblocks compile our programs. I read that VC++ took 17 years to be created so how come codeblocks is so new and yet it compiles sourcecode :S

Also if codeblocks is using a backend compiler can I use that same thing in my program or is it going to take me years too?

triumphost 120 Posting Whiz

I don't think you can redistribute their files but if your not using an installer, you could open the project menu -> Properties -> C/C++ -> Code Generation -> RunTime Library Set it to /MDd. Maybe this will work for the installer as well depending on how your making it.

That will include all the files needed into your program. Also have you considered adding all the files needed as resources and extracting them when needed?

triumphost 120 Posting Whiz

Mike.. I love you bro. That tiny bit of information saved the day! And thines thank you for everything! Both +Rep that's for sure.

This is the completed class (Works exactly as it's supposed to) And it's templated Thines:

#ifndef TEMPLATES_H_INCLUDED
#define TEMPLATES_H_INCLUDED
using namespace System;
using namespace System::Collections::Generic;

template <typename T>
public ref class CustomType sealed
{
    private:
        List<T> TypeData;

    public:
        CustomType() {}
        CustomType(...array<T^> ^Types)          //Basically Variadic Templates.. As good as it gets for MS2010..
        {
            for each (T^ t in Types)
            {
                TypeData.Add(*t);
            }
        }
        ~CustomType() {}

        int size()
        {
            return (TypeData.Count);
        }

        T^ operator [](int I)
        {
            if (I < 0 && (this->size() == 0))
                throw gcnew System::ArgumentException("Parameter cannot be null");

            return TypeData[I];
        }

        void operator()(...array<T^> ^Types)
        {
            for each (T^ t in Types)
            {
                TypeData.Add(*t);
            }
        }

        operator const List<T>^ ()
        {
            return TypeData;
        }

        bool operator == (CustomType %CT)
        {
            for (int I = 0; I < CT.size(); I++)
            {
                if (this->TypeData[I] != CT.TypeData[I])
                    return false;
            }
            return true;
        }

        bool operator != (CustomType %CT)
        {
            for (int I = 0; I < CT.size(); I++)
            {
                if (this->TypeData[I] == CT.TypeData[I])
                    return false;
            }
            return true;
        }

        CustomType^ operator = (CustomType %CT)
        {
            if (this != %CT)
            {
                if (this->size() > 0)
                    TypeData.Clear();

                for (int I = 0; I < CT.size(); I++)
                    TypeData.Add(CT.TypeData[I]);
            }
            return this;
        }

        CustomType^ operator << (const T^ t)
        {
            TypeData.Add(*t);
            return this;
        }

        virtual String^ ToString() override
        {
            String^ Str;
            if (this->size() != 0)
            {
                Str = "[";
                for (int …
triumphost 120 Posting Whiz

I've overridden ToString already. I'm not sure what the GetHashCode is for.

Also the class is actually so that I can make custom types. Like arrays of any types without having to worry about sizes and stuff. I can add to the array anytime and remove from it at any time. I can add any amount of parameters at once to the array. It can be of type string, int, bool, etc..

I use it like:

CustomType<int> IA(1, 2, 3, 4, 5, 6, 7...... ); //Any amount..
CustomType<string> SA("one", "two", "three", "four"...); //etc..
CustomType<string> SA2("meh", "bleh", "waw.");
CustomType<CustomType<int>> I2DA;  //A 2Dimensional Array of Integers.

SA = SA2;  //This would remove all elements from SA and copy the ones from SA2.
SA == SA2; //I compare the elements for equality.
MessageBox::Show(SA.ToString);  //This prints all elements in SA to look like:  ["A", "B", "C"]..

Also I know I can just do this with a List but it's more work the more I use it as every time I'd be defining and enumerable type and I can't easily add a large amount of elements as easily as the above.. Even though Lists have AddRange Properties. It's not the same. It's the ease of access.

Hmm that really is the only way to override the comparrison? Is that how I can override the assignment as well?

triumphost 120 Posting Whiz

Ok this is my new header but I cannot for the life of me get the operator == overloaded.. Help me please!

I just want to be able to do if (CustomtypeA == CustomtypeB).. But it keeps telling me that
error C2679: binary '==' : no operator found which takes a right-hand operand of type 'CustomType<T>' (or there is no acceptable conversion)

#ifndef TEMPLATES_H_INCLUDED
#define TEMPLATES_H_INCLUDED
using namespace System;
using namespace System::Collections::Generic;

template <typename T>
public ref class CustomType
{
    private:
        List<T> TypeData;

    public:
        CustomType() {}
        CustomType(...array<T^> ^Types)          //Basically Variadic Templates.. As good as it gets for MS2010..
        {
            for each (T^ t in Types)
            {
                TypeData.Add(*t);
            }
        }
        ~CustomType() {}

        int size()
        {
            return (TypeData.Count);
        }

        CustomType^ operator [](int I)
        {
            assert(I >= 0 && (TypeData.size() != 0));
            return TypeData[I];
        }

        void operator()(...array<T^> ^Types)
        {
            for each (T^ t in Types)
            {
                TypeData.Add(*t);
            }
        }

        operator const List<T>^ ()
        {
            return TypeData;
        }

        bool operator ==(CustomType ^CT)
        {
            return (this->TypeData == CT->TypeData);
        }

        bool operator !=(const CustomType ^CT)
        {
            return !(this->TypeData == CT.TypeData);
        }

        CustomType^ operator =(const CustomType ^CT)
        {
            if (this != &CT)
            {
                if (TypeData.size() > 0)
                    TypeData.Clear();

                for (size_t I = 0; I < CT.TypeData.size(); I++)
                    TypeData.Add(*CT.TypeData[I]);
            }
            return this;
        }

        CustomType^ operator << (const T^ t)
        {
            TypeData.Add(*t);
            return this;
        }

        virtual String^ ToString() override
        {
            String^ Str;
            if (this->size() != 0)
            {
                Str = "[";
                for (int I = 0; I < this->size() - 1; I++)
                {
                    Str += TypeData[I];
                    Str += ", …
triumphost 120 Posting Whiz

I'm trying to convert My Console classes to .Net classes because I can't use std::vector or anything like that in WindowsFormsApplications. So I decided to convert all Vectors to Lists and I thought that the classes work the same but my code below throws a massive amount of errors and I have no clue why.. It's quite short and simple to read.

using namespace System;
using namespace System::Collections::Generic;

template <typename T>
public ref class CustomType
{
    private:
        List<T> TypeData;

    public:
        CustomType() {}
        CustomType(...array<T^> ^Types)          //Basically Variadic Templates.. As good as it gets for MS2010..
        {
            for each (T^ o in Types)
                TypeData.Add(o);
        }
        ~CustomType() {}

        int size() {return TypeData.size();}

        CustomType& operator [](int I)
        {
            assert(I >= 0 && !TypeData.empty());
            return TypeData[I];
        }

        const CustomType& operator [](int I) const
        {
            assert(I >= 0 && !TypeData.empty());
            return TypeData[I];
        }

        operator const List<T>& () const
        {
            return TypeData;
        }

        bool operator == (const CustomType &CT) const
        {
            return (TypeData == CT.TypeData);
        }
};

I use the above like this:

    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
                 CustomType<int> Meh(0, 1, 2, 3, 4);
             }

But that does not work at all.. It's basically supposed to add Meh to the list within the class and I can access it at anytime to get the data.

Please help me. How do I overload in .Net and what is that Shevron? The ^ operator? I read that it's top level but have no clue what I read because I understood very little. …

triumphost 120 Posting Whiz

Deceptikon gave an amazing answer but I want to share what I figured out by accident yesterday.
You can declare a function inside a function via a data structure:

std::thread f()
{
    typedef struct
    {
        void somefunction(){}
    } t;

    return t.somefunction();
}

//OR

std::thread f()
{
    struct t
    {
        void somefunction(){}
    }
    t meh;

    return meh.somefunction();
}

the structs and the functions within them are limited to the outer function's scope. That means you can't access the struct or embedded functions from outside thread f();

triumphost 120 Posting Whiz

Ahh the 100.0 solved it. It works with doubles as long as I have the trailing decimal. Without that it overflows. I checked the values via cout before the function returns and they were all less than 255. Just happened to be the decimal. Figured that out after googling for hours last night lol. Thank you though. +Rep.

triumphost 120 Posting Whiz

What is the difference between these two and why does one compile fine compared to the other :S

//MyFile.h
#include<iostream>
using namespace std;

inline std::ostream& operator << (std::ostream& Str, const RGB &Rgb)
{
    Str<<"R: "<<(int)Rgb.R<<"  G: "<<(int)Rgb.G<<"  B: "<<(int)Rgb.B;
    return Str;
}


//Main.cpp

#include <iostream>
#include "MyFile.h"

using namespace std;

int main()
{
   cout<<Rgb(16777215);      //Results in an error!
}

The above gives an error but the below thing does not:

//Main.cpp

#include <iostream>

using namespace std;

inline std::ostream& operator << (std::ostream& Str, const RGB &Rgb)
{
    Str<<"R: "<<(int)Rgb.R<<"  G: "<<(int)Rgb.G<<"  B: "<<(int)Rgb.B;
    return Str;
}

int main()
{
   cout<<Rgb(16777215);      //Results are printed correctly.
}
triumphost 120 Posting Whiz
std::cout<<student[x].name<< "    " <<student[x].num;
triumphost 120 Posting Whiz

Ahh I'm aware that I can have constructors and destructors but after a couple hours I figured out my problem (still unsolved though):

RGB M = Rgb(255, 255, 255);
cout<<M.Color<<endl;            //Prints 16777215. This is correct.
cout<<(int)M.R;                   //Prints 255. This is also correct.


//In my bitmap function:

Pixels = new RGB[Info.bmiHeader.biSizeImage];
SetFilePointer(hFile, bFileHeader.bfOffBits, 0, FILE_BEGIN);
ReadFile(hFile, Pixels, Info.bmiHeader.biSizeImage, &Read, 0);
DC = GetDC(0);
Image = CreateDIBitmap(DC, &Info.bmiHeader, CBM_INIT, Pixels, &Info, DIB_RGB_COLORS);       //Read all values into Pixels.



cout<<Pixels[0].Color;         //Prints 42577 which is wrong. It should be: 5350912
cout<<Pixels[0].R<<end;     //This prints correctly.
cout<<Pixels[0].G<<end;     //This prints correctly.
cout<<Pixels[0].B<<end;     //This prints correctly.


//So I used this to swap them and the Pixels[0].Color prints properly:
COLORREF ColorSwap(COLORREF Color)
{
    BYTE Red = ((Color & 0xff0000) >> 16);
    BYTE Green = ((Color & 0x00ff00) >> 8);
    BYTE Blue = (Color & 0xff);

    return ((Blue << 16) + (Green << 8) + Red);
}

How can I just swap all the R's & B's in my bitmap function so that RGB.Color will always print in the RGB format instead of BGR?

triumphost 120 Posting Whiz
typedef union
{
    unsigned Color;
    struct
    {
        unsigned char B, G, R, A;
    };
} RGB, *PRGB;


inline RGB Rgb(int R, int G, int B) {RGB Result = {((COLORREF)((BYTE)(R)|((BYTE)(G) << 8)|((BYTE)(B) << 16)))}; return Result;}
inline RGB Rgb(COLORREF Color) {RGB Result = {Color}; return Result;}

The above is my code for an RBG Data structure. I populate it like so:

PRGB Pixels  = new RGB[100];
CreateDIBitmap(DC, &Info.bmiHeader, CBM_INIT, Pixels, &Info, DIB_RGB_COLORS);    //Populates Pixels with colours..

The problem is that if I do: cout<<Pixels[0].Color; It prints the wrong Colours.. but if I docout<<Pixels[0].R; then it prints the correct R, G, and B values. Can anyone tell me why it never prints Colour Correctly?

Is there a way I can automatically populate Color?

triumphost 120 Posting Whiz

I have the following:

typedef union
{
    unsigned Color;
    struct
    {
        unsigned char B, G, R, A;
    };
} RGB, *PRGB;

Then I have:

RGB Rgb(XYZ Xyz)
{
    RGB Result;
    double X = Xyz.X / 100;
    double Y = Xyz.Y / 100;
    double Z = Xyz.Z / 100;

    double Red = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
    double Green = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
    double Blue = X * 0.0557 + Y * -0.2040 + Z * 1.0570;

    Red = (Red > 0.0031308) ? (1.055 * pow(Red, (1/2.4)) - 0.055) : 12.92 * Red;
    Green = (Green > 0.0031308) ? (1.055 * pow(Green, (1/2.4)) - 0.055) : 12.92 * Green;
    Blue = (Blue > 0.0031308) ? (1.055 * pow(Blue, (1/2.4)) - 0.055) : 12.92 * Blue;

    //Printing Red here and blue here are perfectly fine..
    //The problem is here..
    Result.R = (unsigned char)round(Red * 255);
    Result.G = (unsigned char)round(Green * 255);
    Result.B = (unsigned char)round(Blue * 255);

    return Result;
}

In that function above, my values overflow even though I rounded it. When printed, it prints random values which I know is an overflow.
If I change all the doubles to floats, it works perfectly fine and prints the correct value every time. Why? How can I keep it as double? Or should I just change it all to float? I wanted double because it holds more decimal places..

triumphost 120 Posting Whiz

Its for Windows. Uhh A carret is that blinking thing we get in a text editor when typing right? I can't use a carret to click. I actually want to create a mouse that I can programatically move and make it click stuff in my application window while I'm free to use my actual mouse to do other things.

Basically:
DisableMouseButton: Lets the user click on the applications surface. Allows user to control application mouse.
EnableMouseButton: Blocks the user from controlling the application mouse. Application can use it's own mouse to click on it's surface while the user is doing other stuff with the actual mouse.

I just don't know how to actually create the mouse.

triumphost 120 Posting Whiz

I have an application that will be minimized and running in the background. I want this application to have it's own moveable mouse so that it does not use my current mouse. How can I accomplish this?

I'm not exactly sure where to start to create a mouse for it.

triumphost 120 Posting Whiz

I have an application I'm updating from Java 6 to 7 inorder to get it to run.

The code looks like:

    public Canvas(GraphicsConfiguration config) {
        this();
        graphicsConfig = config;
    }

But when compiled I get:

"graphicsConfig is private access" @ line graphicsConfig = config.

How can I do the same thing in Java 7?

triumphost 120 Posting Whiz

Well considering how long of a post it is, most people will skip right over it. Post where the problem is. I don't think anyone wants to read 3 header files to answer one compiler error.

triumphost 120 Posting Whiz
cout<< "Name your favourite soccer team in uppercase\n";

    cin>>s;
    if (isupper(s))
       cout<<toupper(s[0]);
    else
       cout<<s;
triumphost 120 Posting Whiz

I don't think you can without creating a new variable aka a tracker variable. It can even be implemented in your class I suppose. The only other way " I " can possibly think of is to do what vectors do and keep a pointer to the beginning of the array and one to the end.. then minus them for the size and capacity.. but that's far from what you want and I suggest just changing the arrays to vectors. Vectors come with a .Size() method to keep track automatically for you..

If you cannot do that then I guess you can view this thread and gather what you can from it: http://www.gamedev.net/topic/345898-finding-array-length----c/

Even though I doubt it could be useful.

triumphost 120 Posting Whiz

You can't do that.. I cannot remember why but I remember ancient dragon telling me that it's a no-no. Something to do with pointers if I remember correctly.. Instead I was told to make a tracker variable and everytime you add to the array, increment the tracker by that amount. Else use std::vector instead. I'd assume the same applies to you unless of course I'm wrong.

triumphost 120 Posting Whiz

Welll you can of course edit it yourself.. Add a boolean parameter.. If true, Lowercase.. If false, Uppercase.. It's up to you to decide how your going to use it.. you can probably just copy the code inbetween it if you do not want a function..

triumphost 120 Posting Whiz

That would go anywhere that you want stuff to print to and from the screen.

Example:

if you wanted to get everything written to the console into a file.. you can do:

FILE *stream ; //Redirect Output from console to a TextFile
if((stream = freopen("C:\Somefile.txt", "w", stdout)) == NULL)
{
    cout<<"Meh this will be written to a file.. and anything inbetween these braces will be written to C:\SomeFile.txt.. Even user input will get put into that file.";
}

stream = freopen("CON", "w", stdout); //Redirect Output to the Screen

cout<<"Now anything after that line above such as this line.. will be printed to the console screen..";

//Now if you close the stream, it will print to the screen automatically.

That's how I used it when Narue gave me it a couple years back when I needed to write the console to the file. Not sure if I used it right the first time I got it but that's how I'd still use it and it works.

triumphost 120 Posting Whiz

Here I'm pretty sure you can use these.. I wrote them myself a while ago while writing an include for bitmap finding.. Usually we don't actually give out code but I can see that you tried and plus this code isn't complicated so I'm sure it's ok for me to share.

Also where it shows comments.. you can use those instead of the ToUpper.. but I just used ToUpper instead of using the Ascii table. Does uppercase, lowercase and capitalization. Enjoy. Note: If you uncomment the ascii table ones, you won't need any additional includes..

string UpperCase(string Str)
{
    /**
for (unsigned short I = 0; I < Str.size(); I++)
if(Str[I] >= 0x61 && Str[I] <= 0x7A)
Str[I] = Str[I] - 0x20;
**/
    //Str[I] -= 'a' - 'A' ;
    for (unsigned short I = 0; I < Str.length(); I++)
    {
        Str[I] = toupper(Str[I]);
    }
    return Str;
}

string LowerCase(string Str)
{
    /**
for (unsigned short I = 0; I < Str.size(); I++)
if(Str[I] >= 0x41 && Str[I] <= 0x5A)
Str[I] = Str[I] + 0x20;
**/
    //Str[I] += 'a' - 'A' ;
    for (unsigned short I = 0; I < Str.length(); I++)
    {
        Str[I] = tolower(Str[I]);
    }
    return Str;
}

string Capital(string Str)
{
    Str[0] = toupper(Str[0]);
    return Str;
}
triumphost 120 Posting Whiz

FILE *stream ; //Redirect Output from console to a TextFile
if((stream = freopen("C:\Somefile.txt", "w", stdout)) == NULL)

stream = freopen("CON", "w", stdout); //Redirect Output to the Screen

triumphost 120 Posting Whiz

Double backslash in strings is equivalent to a single forward slash if your talking about paths.

triumphost 120 Posting Whiz

It still crashes if I do that.

triumphost 120 Posting Whiz

I have a class that just creates a blank bitmap it's quite large so I removed a LOT! of code to make it easier to see my problem. No knowledge of bitmaps required. I declared "Pixels" as an array of RGB but in one function, Pixels is empty whereas in other functions I initialize Pixels using the new operator.

In the destructor, I delete[] Pixels. But it will throw an error if it isn't initialized.

typedef union
{
    unsigned Color;
    struct
    {
        unsigned char B, G, R, A;
    };
} RGB, *PRGB;

class Bitmap
{
    private:
        HDC DC;
        PRGB Pixels;
        HBITMAP Image;
        BITMAPINFO Info;
        int width, height, size;
        BITMAPFILEHEADER bFileHeader;

    public:
        Bitmap(int Width, int Height)
        {
            memset(&Info, 0, sizeof(BITMAPINFO));
            Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
            Info.bmiHeader.biPlanes = 1;
            Info.bmiHeader.biBitCount = 32;
            Info.bmiHeader.biCompression = BI_RGB;
            Info.bmiHeader.biWidth = width;
            Info.bmiHeader.biHeight = -height;
            size = ((width * 32 + 31) / 32) * 4 * height;
            DC = CreateCompatibleDC(0);
            Image = CreateDIBSection(DC, &Info, DIB_RGB_COLORS, (void**)&Pixels, 0, 0);
            SelectObject(DC, Image);
            //I've tried Pixels = new RGB[100];  Doesn't work since it's still blank.
        }

        /* Other bitmap functions here that does Pixels = new RGB[...]; */

        ~Bitmap()
        {
            if (Pixels)
                delete[] Pixels;
            DeleteDC(DC);
            DeleteObject(Image);
        }
};


int main()
{
    Bitmap X(100, 100);   //Crashes my program due to Pixels being deleted when not initialized.
    Bitmap Y("C:/Users.......");  //Will not crash my program since pixels is initialize with new[];
    return 0;
}

Any ideas what I can do so that I do not have to remove it from my destructor? …

triumphost 120 Posting Whiz

How can I stop a process cleanly given it's name?

I can use TerminateProcess but it says it does not allow the application to clean up and of course I want it to clean up. This application does not have a WM_CLOSE or WM_QUIT.. I tried.. and I cannot send it PostMessage(HWND, WM_QUIT, 0, 0);

Why? because instead of it closing, it will minimize to system tray -__-

Again I don't want to use a dirty thing like TerminateProcess so does anyone have any ideas?

triumphost 120 Posting Whiz

I have the following code which tracks the mouse movements on a control and if the mouse hovers it will beep. I want it to draw specific images on Hover and when it leaves, draw a different image. How can I accomplish this?

I subclassed the buttons to figure out if the mouse is over them and if the mouse clicked them but now I need to know how to paint. I've tried WM_PAINT events and WM_DRAWITEM events but I cannot figure out why it doesn't draw and I think I'm just drawing wrong. Does anyone have an example of how I can accomplish this task?

In my main WindowProc, I loaded the images already, I just need to know how to blit them to the specific button.

void TrackMouse(HWND hwnd)
{
    TRACKMOUSEEVENT tme;
    tme.cbSize = sizeof(TRACKMOUSEEVENT);
    tme.dwFlags = TME_HOVER | TME_LEAVE;
    tme.dwHoverTime = 1;
    tme.hwndTrack = hwnd;
    TrackMouseEvent(&tme);
}

LRESULT CALLBACK OwnerDrawButtonProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    static WNDPROC OrigBtnProc = (WNDPROC)(static_cast<LONG_PTR>(GetWindowLongPtr(hwnd, GWLP_USERDATA)));
    switch (uMsg)
    {
        case WM_MOUSEMOVE:
        {
            if (!MouseEntered)
            {
                TrackMouse(hwnd);
            }
            return CallWindowProc(OrigBtnProc, hwnd, uMsg, wParam, lParam);
        }
        break;

        case WM_MOUSEHOVER:
            MouseEntered = true;
            MessageBeep(0);  //After Beeping, I want to draw Image1.
            return CallWindowProc(OrigBtnProc, hwnd, uMsg, wParam, lParam);
        break;

        case WM_MOUSELEAVE:
            MouseEntered = false; //If the mouse Leaves, I want to draw Image2.
            return CallWindowProc(OrigBtnProc, hwnd, uMsg, wParam, lParam);
        break;

        default:
            return CallWindowProc(OrigBtnProc, hwnd, uMsg, wParam, lParam);
    }
}
triumphost 120 Posting Whiz

I have a button created as follows:

    HWND License; HBITMAP MainButtons;


    Case WM_CREATE:
        License = CreateWindowEx(WS_EX_TRANSPARENT, L"Button", L"License", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_BITMAP, 26, 77, 75, 23, hwnd, (HMENU)ID_LICENSE, hInst, 0);

        MainButtons = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MAINBUTTONS), IMAGE_BITMAP, 0, 0, LR_SHARED);

        SendMessage(License, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)MainButtons); 
    break;

But my button looks like: http://i.imgur.com/TkjiQ.png

The text disappeared, the WinXP button somehow got painted too! I need the button to look like: http://i.imgur.com/B2pEo.png

I cannot figure out what I'm doing wrong at all.. I've followed all the tutorials and that is how they say to set the image/icon/background.. I do not want my text on the button to disappear. ={

What am I doing wrong?

triumphost 120 Posting Whiz

I'm trying to clip my Button with the following code but it does not work at all..

#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

#pragma comment(lib, "Gdiplus.lib")

void RegionCloseButton(HWND hwnd)
{
    CloseRegion = GetDC(hwnd);
    CloseRegionMem = CreateCompatibleDC(CloseRegion);
    Gdiplus::Graphics graphics(CloseRegion);
    Gdiplus::FontFamily fontFamily(L"Courier New");
    Gdiplus::GraphicsPath path;
    Gdiplus::PointF Origin(5, 5);
    path.AddString(L"X", -1, &fontFamily, Gdiplus::FontStyleBold, 15, Origin, NULL);
    Gdiplus::Region StringRegion(&path);

    Gdiplus::Pen pen(Gdiplus::Color(255, 0, 0, 0));
    graphics.DrawPath(&pen, &path);
}

The following is the .Net equivalent

System::Void Close_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e)
{
    System::Drawing::Drawing2D::GraphicsPath^ GraphicsPath = gcnew System::Drawing::Drawing2D::GraphicsPath;
    System::String^ stringText = "X";
    FontFamily^ family = gcnew FontFamily("Courier New");
    int fontStyle = (int)FontStyle::Bold;
    float emSize = 15;
    Point origin(5, 5);
    StringFormat^ format = gcnew StringFormat(StringFormat::GenericDefault);
    GraphicsPath->AddString(stringText, family, fontStyle, emSize, origin, format);

    Close->Region = gcnew System::Drawing::Region(GraphicsPath);
    this->Invalidate();

    delete Region;
    delete format;
    delete family;
}

And in the end it looks like (.Net):
[Img]http://i.imgur.com/FQqMD.png[/Img]

I want to do that to the close button in Win32API in my WM_Paint but I cannot get it to clip. It doesn't even draw the X at all.

This is my entire Source Code: http://pastebin.com/vGD5a2UQ

triumphost 120 Posting Whiz

Well sorta. I figured out how to tell if it's ran by just writing bytes to the end of the file and checked for it on second run. But this time I actually want to read a file's OP codes..

Like in OllyDBG if I decompile an EXE I can see the OPCodes and understand and modify them. In C++ I want to read an EXE's opcodes and read/write. In the above example, I want to open my EXE and write a messagebox to it or anything really.

triumphost 120 Posting Whiz

Does C++ Console apps have a TryParse equivalent.. I mean .Net has it for both C# and C++ but why does C++ Consoles NOT have this! Or am I just wrong and cannot find it?

I was thinking of writing my own with templates that can be use for ANY type but I'm not sure how I would check if the values are 'parse-able' or not and then to reset the variable upon fail I guess that's where I'd catch an exception :S

triumphost 120 Posting Whiz

Hey all, I've been searching Rohitab, CodeProject and various other sites to figure out how to write OPCodes to a file and cannot figure it out. I thought I'd ask here because it's the only site I have an account on and I usually get my answers here or hints.

I was to basically open a file and write:

MOV EBX 10; Stuff like that.

Or

NOP;

But I'm not sure how to actually write it to a file or how to read it either.

I know in C++ I can do:

int main()
{
   __asm
   {
      push 0;
      push title;
      push caption;
      call MessageBoxA;
   }
}

But I cannot figure out how to actually write that to a file and how to check if a file has stuff like that in it.

triumphost 120 Posting Whiz

you can use stringstream to convert to hex or cast each character to decimal like:

(int)String[I];

Then

int DecToHex(int DecNumber)
{
    int Hexa = 0, Pos = 1;
    while (DecNumber > 0)
    {
        Hexa += (DecNumber % 16) * Pos;
        DecNumber /= 16;
        Pos *= 10;
    }
    return Hexa;
}

Which will give you the hex equivalent of the decimal.. Now convert that to a string with 0x infront of it and whala.

EDIT: Hmm Why does my code tags look like that :S Wish we had the old ones back..

triumphost 120 Posting Whiz

If My guess is correct, I think you phrase the question wrong because of the way your saying that it reads contents of the file.. I think you mean read the instructions of an EXE file. Such as the OPCodes or I think what you mean by "EXE's have a lot of nulls" is that they have a lot of NOP's Aka No-Operations.

That's Assembly code. ReadFile doesn't do that for you. It opens the file as a text and reads the contents of that. It's the same as opening the EXE in Notepad and reading it. ReadFile reads in Binary MODE but doesn't actually read in the assembly of the file.

I'm also looking for a way to read/write Assembly to an exe. So.. :S If I find a way then I'll answer here until then I'll just be looking around.

triumphost 120 Posting Whiz

Ahh that makes sense but how would I even modify the copy :S I can't think of "what" to do to the file or how to modify it.. I just want to check if it's been ran already :c

triumphost 120 Posting Whiz

How can I have my program modify itself?

Example:

Size = 1mb ..Run program once.. size = ++1mb

On Second Run, check if itself is 1mb

Or something of the sort :S.

I need to be able to check if my program has ever been ran before..

So.. Is there any way to tell if it's ever been ran on that particular machine without making a text file or extra files?
My Idea was to make it modify itself and then check if it is modified. If so then it has been ran already. Or maybe have it update it's own resources internally and on the second run, check if that resource changed?

Any Ideas?

triumphost 120 Posting Whiz

It isn't optional but.. I've used it normally without the last 3 parameters in my console app and it works.. Also for the DLL, if I do put the last 3 parameters, I get the exact same error still.

And the last 2 parameters are reserved for future use so I cannot use them :S

triumphost 120 Posting Whiz

Hey all, Back with another Win32 question. When I paint to my window (create a background image), what happens is that everything is fine until I draw the window off the screen causing it to invalidate everything.. When dragged back onscreen, my background is redrawn but my controls are all gone until I hover over the spot where they were before.. THEN they reappear.. I need help fixing it please!! I've been trying for so long and cannot figure it out.

   hwnd = CreateWindowEx(WS_EX_TOOLWINDOW, szClassName, L"Reflector", WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, 291, 157, HWND_DESKTOP, NULL, hThisInstance, NULL);

    CreateRegion(hwnd);                  //Create a Region and Blt a bitmap to it.. AKA create Background Image.
    ShowWindow (hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while (GetMessage (&messages, NULL, 0, 0))
    {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }

    return messages.wParam;
}

RECT WindowRect;
POINT Offset, CursorPos;

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT PS;

    switch (message)
    {
        case WM_CREATE:
            License = CreateWindow(L"Button", L"License", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 26, 77, 75, 23, hwnd, (HMENU)ID_LICENSE, hInst, 0);
            WinXP = CreateWindow(L"Button", L"Win-XP", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 195, 77, 75, 23, hwnd, (HMENU)ID_WINXP, hInst, 0);
            Injection = CreateWindow(L"Button", L"Trial", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 26, 120, 75, 23, hwnd, (HMENU)ID_Trial, hInst, 0);
            Help = CreateWindow(L"Button", L"Help", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 195, 120, 75, 23, hwnd, (HMENU)ID_HELP, hInst, 0);
            break;

        case WM_COMMAND:
            switch(wParam)
            {
                case ID_CLOSE:
                break;
            }
            break;

        case WM_LBUTTONDOWN:
            SetCapture(hwnd);
            GetWindowRect(hwnd, &WindowRect);
            GetCursorPos(&Offset);
            ScreenToClient(hwnd, &Offset);
            break;

        case WM_LBUTTONUP:
            ReleaseCapture();
            break;

        case WM_MOUSEMOVE:
            GetCursorPos(&CursorPos);
            if (wParam & MK_LBUTTON)    //wParam …
triumphost 120 Posting Whiz
        case WM_MOUSEMOVE:
                if (wParam & MK_LBUTTON)
                {
                    RECT WindowRect;
                    POINT CursorPos;
                    GetWindowRect(hwnd, &WindowRect);
                    GetCursorPos(&CursorPos);
                    SetWindowPos(hwnd, 0, WindowRect.left - CursorPos.x, WindowRect.top - CursorPos.y, 291, 157, 0);
                }
            break;

Hey Guys The above code isn't working for me. I'm trying to have the user Drag my borderless window but the thing just jumps to the 0, 0 immediately! Can someone explain why? Or what I should do?

triumphost 120 Posting Whiz
void DLL_EXPORT Replace(LPCTSTR OriginalFile, LPCTSTR FileToReplace, LPCTSTR BackupOfFileToReplace)
{
    HGLOBAL LoadResource(HMODULE hModule,  HRSRC hResInfo);
    try
    {
        BOOL WINAPI ReplaceFile(OriginalFile, FileToReplace, BackupOfFileToReplace);
        MessageBox(NULL, "Done", "Alert", 0);
    }
    catch (...){}
}

The above is my code and it gives me errors like:

In function 'void Replace(LPCTSTR, LPCTSTR, LPCTSTR)':|
warning: '__stdcall__' attribute only applies to function types [-Wattributes]|
error: expression list treated as compound expression in initializer [-fpermissive]|
warning: left operand of comma operator has no effect [-Wunused-value]|
warning: right operand of comma operator has no effect [-Wunused-value]|
error: invalid conversion from 'LPCTSTR {aka const char*}' to 'BOOL {aka int}' [-fpermissive]|
warning: unused variable 'ReplaceFile' [-Wunused-variable]|
||=== Build finished: 2 errors, 4 warnings ===|

I've googled everything and cannot for the life of me figure out why it's giving me these errors.. I have all the right includes, everything! Any help is appreciated.

triumphost 120 Posting Whiz

I have a modified a DLL called UserEnv and I decided to check out reverse engineering and assembly.. When my DLL Loads, it writes and displays a messagebox saying it's loaded.. Sorta like injection into notepad which I learned from: How To Inject Into Notepad

The DLL Now looks like:
[IMG]http://i.imgur.com/JMwj7.png[/IMG]

But I cannot figure out how to remove the msgbox.. I tried NOPing all four Pushes and I tried JMP right over it.. Not sure if I'm doing the right lines or addresses..

Help me please?

I posted here because I thought it was written in C++ so it'd be fine? Or should I just get the thread moved to the assembly section?

triumphost 120 Posting Whiz

Thread has no work.. I don't see anything inside the threadproc :S

triumphost 120 Posting Whiz

You have to uninstall Mingw first.. and DevC++.. I'm on Windows 8 and it works VS2010 and codeblocks works fine..

Consumer Preview here.

triumphost 120 Posting Whiz

Try this.. Works on integers. Deletes all the ONES if there are an even number of them.. and deletes all but the last one if it's odd.

#include <Windows.h>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<int> Meh;
    Meh.push_back(1); Meh.push_back(2); Meh.push_back(3);

    int tracker = 0;
    int LastOne = 0;

    for(int I = 0; I < Meh.size(); I++)
    {
        if (Meh[I] == 1)
        {
            ++tracker;
            ++LastOne;
        }
    }

    if(tracker % 2 == 0)
        for (int I = 0; I < Meh.size(); I++)
        {
            if (Meh[I] == 1)
            {
                Meh.erase(Meh.begin() + I);
                I = 0;
            }
        }
    else
        for (int I = 0; I < Meh.size(); I++)
        {
            if (LastOne == 1)
                break;

            if (I == LastOne + 1)
                break;

            if(Meh[I] == 1)
            {
                Meh.erase(Meh.begin() + I);
                I = 0;
                LastOne -= 1;
            }
        }

    for (int I = 0; I < Meh.size(); I++)
        cout<<Meh[I]<<endl;
}
triumphost 120 Posting Whiz

Do you not have any code to show? We are not allowed to do homework FOR you.. we can help but not do it.

triumphost 120 Posting Whiz

for(int x=0;x<7;x++)

Should be X < 8 OR X <= 7 for the condition.. 0 counts as the first row of course.. you have 9 columns.. only showing 8.