cambalinho 142 Practically a Posting Shark

to be honest i don't get what i need.
i have 1 code for detect if the class have a function(even if is a prototype), but no for test if the function is defined :(
these macro help me do that, but isn't compatible with Visual Studio.
so let me ask you: how can i test if the function was defined?

cambalinho 142 Practically a Posting Shark

i have these GNU macro:

#if defined __GNUC__
    #define EVENT [[gnu::weak]]
#elif defined __clang__
    #define EVENT [[llvm::weak]]
#endif
#define IS_EVENT_DEFINED(sym) (static_cast<bool>(sym))

these macro works fine. and help me test if the function(even with a prototype) was defined.
my problem is can i convert

[[gnu::weak]]

to Visual Studio code(for be compatible)?
because the Visual Studio don't have 'weak'

cambalinho 142 Practically a Posting Shark

Moderator: i'm sorry, but i can't add the code on same textbox code.. isn't my error :(
edit: i fixed, just for delete the '-' after ':', after new line.. i don't know why

cambalinho 142 Practically a Posting Shark

the C++ have virtual functions, but, for me they have 1 problem: on derived class, i must prototype them, for define them on Global Scope.
how can i avoid the re-prototype them on derived class?
i tried 1 way:

template <class Type>
class TypeHasToString
{
    // This type won't compile if the second template parameter isn't of type T,
    // so I can put a function pointer type in the first parameter and the function
    // itself in the second thus checking that the function has a specific signature.
    template <typename T, T> struct TypeCheck;
    typedef char Yes;
    typedef long No;

    // A helper struct to hold the declaration of the function pointer.
    // Change it if the function signature changes.
    template <typename T> struct ToString
    {
        typedef void (T::*fptr)();
    };

    template <typename T> static Yes HasToString(TypeCheck< typename ToString<T>::fptr, &T::MouseClick >*); //function name
    template <typename T> static No  HasToString(...);

public:
    static bool const value = (sizeof(HasToString<Type>(0)) == sizeof(Yes));
};

template <typename CBase>
class test
{
    CBase* atPointer = nullptr;

public:
    void MouseClick(){;};
    test(CBase *clsPointer) : atPointer(clsPointer)
    {
        atPointer=clsPointer;
        //use it:
        std::cout << TypeHasToString<CBase>::value;
    }

    void call()
    {
        atPointer->MouseClick();
    }
};

//ClassWithEvents(test,FormEvents, b);

class InstanceName : public test<InstanceName>
{ // manual expansion of ClassWithEvents
public:
    InstanceName() : test(this){;}

    ~InstanceName(){;}

public:
    void MouseClick();
//  void Move();                       // error 1
} InstanceName;

// void b::MouseClick()                    // possible error 2
void InstanceName::MouseClick()
{
    std::cout << "Mouse click";
}

these template is for test if the class test::CBase have the MouseClick().
these …

cambalinho 142 Practically a Posting Shark

i know save the Image on IStream. but what isn't saved like the original: the backcolor goes to black instead stays white.
i belive that the problem is the transparent color, because isn't saved on IStream.
i had tryied use the ColorPalette(Image.GetPalette() and Image.SetPalette(), but the ColorPalette.Count it's zero), but i get an error: '2 - Invalid Parameter'.
can anyone advice me for save the gif frames correctly on IStream or just change the transparent color to false?

cambalinho 142 Practically a Posting Shark

i did a class for the timer precision using the timeSetEvent(). of course i can have more than 7 instances from the Timer class(with 200ms or something so small). is these a limitation or what?

class Timer
{

private:
    static unsigned int TimerCount;
    UINT_PTR timerid;
    UINT m_uResolution=0;
    unsigned int TimerID=0;
    unsigned int intInterval=0;

    static void CALLBACK _TimerProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
    {
        Timer* obj=reinterpret_cast<Timer*>(dwUser);
        if(obj->timerprocedure!=nullptr)
            obj->timerprocedure();
    }

public:

    std::function<void()> timerprocedure=EmptyEvent;
    Timer(std::function<void()> tmrprocedure=EmptyEvent)
    {
        TimerCount++;
        TimerID=TimerCount-1;
        timerprocedure=tmrprocedure;
    }

    void Stop()
    {
        if(timerid!=0)
        {
            timeKillEvent(timerid);
            timeEndPeriod (m_uResolution);
        }
    }

    unsigned int GetInterval()
    {
        return intInterval;
    }

    void SetInterval(unsigned int uintInterval)
    {
        intInterval = uintInterval;
    }

    property <unsigned int> Interval{GetProperty(Timer::GetInterval),SetProperty(Timer::SetInterval)};

    void Start()
    {
        Stop();
        TIMECAPS tc;
        timeGetDevCaps(&tc, sizeof(TIMECAPS));
        m_uResolution = min(max(tc.wPeriodMin, 0), tc.wPeriodMax);
        timeBeginPeriod(m_uResolution);
        timerid =timeSetEvent(intInterval, m_uResolution, &Timer::_TimerProc, reinterpret_cast<DWORD>(this),TIME_PERIODIC);

        if (timerid==0)
            DebugText("error\t" + to_string(GetLastError()));
    }

    ~Timer()
    {
        Stop();
    }
};
unsigned int Timer::TimerCount=0;

after 7 instances(maybe less) the timerid give me NULL and the GetLastError() give me:
5 - access denied.
(on test i'm using it for gif animations)
is the timeSetEvent() limited or i'm using several resources?

cambalinho 142 Practically a Posting Shark

after several tests, i fixed the function:

void Shadow(int PosX=0, int PosY=0, COLORREF ShadowColor=RGB(0,0,0))
    {
        pixeldata pixels=GetImagePixel(HBitmap);

        size_t pixelSize = HBitmap.bitperpixel() / 8;
        size_t scanlineSize = (pixelSize * HBitmap.Width() + 3) & ~3;

        int x=0, y=0;
        COLORREF BackColor;
        for(y=0; y<HBitmap.Height(); y++)
        {
            for(x=0; x<HBitmap.Width(); x++)
            {
                if((y+PosY)>=HBitmap.Height() || (x+PosX)>=HBitmap.Width())
                    continue;
                //getting pixel and drawed pixel positions:
                size_t pixelOffset = y * scanlineSize + x * pixelSize;//actual pixel position
                size_t pixelOffset2 =(y+PosY) * scanlineSize + (x+PosX) * pixelSize; //the position where the shadow pixel is drawed

                //gettin backcolor:
                if(x==0 && y==0)
                {
                   BackColor=RGB(pixels[pixelOffset+2],pixels[pixelOffset+1],pixels[pixelOffset+ 0]);
                }


                //getting actual color:
                COLORREF clrActualColor=RGB(pixels[pixelOffset+2],pixels[pixelOffset+1],pixels[pixelOffset+ 0]);
                COLORREF clrActualColor2=RGB(pixels[pixelOffset2+2],pixels[pixelOffset2+1],pixels[pixelOffset2+ 0]);
                if((clrActualColor!=BackColor && clrActualColor!=ShadowColor)&& clrActualColor2==BackColor)//if the actual color is diferent of backcolor then:
                {
                    pixels[pixelOffset2+2]=GetRValue(ShadowColor);
                    pixels[pixelOffset2+1]=GetGValue(ShadowColor);
                    pixels[pixelOffset2+0]=GetBValue(ShadowColor);
                }
            }
        }
        SetImageData(HBitmap,pixels);
    }

i did several mistakes:
1 - i didn't tested the x+PosX and y+PosY limits;
2 - i was not testing, correctly, the clrActualColor.
i hope these topic make the readers thinking where i did the mistakes and why ;)
shadow_effect.png

cambalinho 142 Practically a Posting Shark

i have these code for get image pixel data:

typedef std::vector<BYTE> pixeldata;
pixeldata GetImagePixel(HDC hdcImage)
{
    BITMAP bmp = {0};
    BITMAPINFO Info = {0};
    memset( &bmp, 0, sizeof(BITMAP) );
    HBITMAP hBitmap =(HBITMAP) GetCurrentObject(hdcImage, OBJ_BITMAP);
    GetObject(hBitmap, sizeof(BITMAP), &bmp);

    BITMAPINFO info { };
    info.bmiHeader.biSize = sizeof(info.bmiHeader);
    info.bmiHeader.biWidth = bmp.bmWidth;
    // pay attention to the sign, you most likely want a
    // top-down pixel array as it's easier to use
    info.bmiHeader.biHeight = -bmp.bmHeight;
    info.bmiHeader.biPlanes = 1;
    info.bmiHeader.biBitCount = 32;
    info.bmiHeader.biCompression = BI_RGB;

    // the following calculations work for 16/24/32 bits bitmaps
    // but assume a byte pixel array
    size_t pixelSize = info.bmiHeader.biBitCount / 8;
    // the + 3 ) & ~3 part is there to ensure that each
    // scan line is 4 byte aligned
    size_t scanlineSize = (pixelSize * info.bmiHeader.biWidth + 3) & ~3;
    size_t bitmapSize = bmp.bmHeight * scanlineSize;

    pixeldata pixels(bitmapSize);
    GetDIBits(hdcImage, hBitmap, 0, bmp.bmHeight, &pixels[0], &info, DIB_RGB_COLORS);
    bmp.bmHeight = std::abs(bmp.bmHeight);
    return pixels;
}

void SetImageData(HDC hdcDestination, pixeldata pixels)
{
    BITMAP bmp = {0};
    BITMAPINFO Info = {0};
    memset( &bmp, 0, sizeof(BITMAP) );
    HBITMAP hBitmap =(HBITMAP) GetCurrentObject(hdcDestination, OBJ_BITMAP);
    GetObject(hBitmap, sizeof(BITMAP), &bmp);
    BITMAPINFO info { };
    info.bmiHeader.biSize = sizeof(info.bmiHeader);
    info.bmiHeader.biWidth = bmp.bmWidth;
    // pay attention to the sign, you most likely want a
    // top-down pixel array as it's easier to use
    info.bmiHeader.biHeight = -bmp.bmHeight;
    info.bmiHeader.biPlanes = 1;
    info.bmiHeader.biBitCount = 32;
    info.bmiHeader.biCompression = BI_RGB;

    SetDIBits(hdcDestination, hBitmap, 0, bmp.bmHeight, &pixels[0], &info, DIB_RGB_COLORS);
}
//how use it
/*pixeldata pixels=GetImagePixel(imgImage);

size_t pixelSize = bm.bmBitsPixel / 8;
size_t scanlineSize = (pixelSize * bm.bmWidth + 3) & …
cambalinho 142 Practically a Posting Shark

i'm getting problems, again, on how i get the frame delay on gif files using Image class:

UINT TotalBuffer = img2.GetPropertyItemSize(PropertyTagFrameDelay);
            //img2 = (PropertyItem*)malloc(TotalBuffer);//my compiler gives an error
            img2.GetPropertyItem(PropertyTagFrameDelay,TotalBuffer,&img2);
            framedelay=TotalBuffer;

seems that the GDIPLUS can be a litte diferent from compiler to compiler :(
so how can i get the frame delay?

cambalinho 142 Practically a Posting Shark
cambalinho 142 Practically a Posting Shark

why these option isn't a standard option?

cambalinho 142 Practically a Posting Shark

after several searchs i found the SHGetFolderPath(): https://msdn.microsoft.com/en-us/library/windows/desktop/bb762181%28v=vs.85%29.aspx

heres a sample:

char programs[255+1];
    SHGetFolderPath(NULL,CSIDL_PROGRAM_FILESX86 ,NULL,SHGFP_TYPE_DEFAULT,programs);
    MessageBox(NULL,programs,"hi",0);

Only some CSIDL values are supported, including the following:

CSIDL_ADMINTOOLS
CSIDL_APPDATA
CSIDL_COMMON_ADMINTOOLS
CSIDL_COMMON_APPDATA
CSIDL_COMMON_DOCUMENTS
CSIDL_COOKIES
CSIDL_FLAG_CREATE
CSIDL_FLAG_DONT_VERIFY
CSIDL_HISTORY
CSIDL_INTERNET_CACHE
CSIDL_LOCAL_APPDATA
CSIDL_MYPICTURES
CSIDL_PERSONAL
CSIDL_PROGRAM_FILES
CSIDL_PROGRAM_FILES_COMMON
CSIDL_SYSTEM
CSIDL_WINDOWS

anotherthing: the GetUserName() give us the user name:

char username[255+1];
    DWORD username_len = 255+1;
    GetUserName(username, &username_len);
    MessageBox(NULL,username,"hi",0);

thanks to all

cambalinho 142 Practically a Posting Shark

using:

char username[255+1];
DWORD username_len = 255+1;
GetUserName(username, &username_len);

i get the actual user name.

but how can i get the program folder name for execute a program?
the '%ProgramFiles(x86)%' on folder name string is ignored :(

cambalinho 142 Practically a Posting Shark

i created the cls file:

Imports System
    Imports System.Runtime.InteropServices
    Imports Microsoft.Win32

    Namespace WindowScriptingObject

        <Guid("7448E08D-ED0F-4E23-B528-91937BB41756"), _
        InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
       Public Interface _WindowScriptingObject
            <DispId(1)> Function ActiveWindow() As Integer
            <DispId(2)> Function WindowText(ByVal hWnd As Integer) As String
        End Interface

        <Guid("B146BF9E-78FC-4DB0-ABFE-9FF026B43E4D"), _
         ClassInterface(ClassInterfaceType.None), _
         ProgId("WindowScriptingObject")> Public Class WindowScriptingObject
            Implements _WindowScriptingObject

            Public WindowScriptingObject()

            Public Declare Auto Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow"() As Integer
            Public Declare Auto Function GetWindowText Lib "user32.dll" (ByVal hwnd As Int32, <Out()> ByVal lpString As System.Text.StringBuilder, ByVal cch As Int32) As Int32
            Public Function ActiveWindow() As Integer Implements _WindowScriptingObject.ActiveWindow
     ActiveWindow=GetForegroundWindow()

            End Function

            Public Function WindowText(hwnd as Integer) As String Implements _WindowScriptingObject.WindowText
     on error resume next
     Dim b As New System.Text.StringBuilder(ChrW(0), 512)
                    Dim ret = GetWindowText(hWnd, b, b.Capacity)
     WindowText = b.tostring
            End Function


        End Class

    End Namespace

and the bat file:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:library /out:"%userprofile%\desktop\win32.dll" "%userprofile%\desktop\win32.cls" /verbose

    "C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm" /codebase "%userprofile%\desktop\win32.dll" /tlb:"%userprofile%\desktop\win32.tlb" /v

    If /i "%cmdcmdline:~0,6%"=="cmd /c" pause

after click on bat file the dll and tlb file was created.
heres the sample:

Set wso=CreateObject("WindowScriptingObject")
    x = wso.ActiveWindow
    msgbox x, , "vbs"
    msgbox wso.windowtext(x), , "vbs"

error message:
'the ActiveX component can't create a 'WindowScriptingObject' object'

so what i'm doing wrong?

cambalinho 142 Practically a Posting Shark

i never used VBScript.
how can i use win32 functions?

cambalinho 142 Practically a Posting Shark

the window have a icon, on caption\title bar. that icon show us the System Menu(mouse right button).
my objective is add to it the Allways on Top option. using a program, on background, i can do it. but i will have another program on process's. so is there another way for add that option on System Menu?

cambalinho 142 Practically a Posting Shark

i can change the windows media player skin.
readers: please save the skin on a folder instead execute it, when on download. or will get an error.
when i execute the windows media player show me the skin that i had selected. but why the button play is disable?(i have a automatic playlist)

cambalinho 142 Practically a Posting Shark

can i add 1 item on standard System Menu?
(my big objective is just add 1 item for put the window allways on top)

cambalinho 142 Practically a Posting Shark

i have my own region class:

class region
{

private:

    BYTE* Get24BitPixels(HBITMAP pBitmap, WORD *pwWidth, WORD *pwHeight)
    {
        // a bitmap object just to get bitmap width and height
        BITMAP bmpBmp;

        // pointer to original bitmap info
        LPBITMAPINFO pbmiInfo;

        // bitmap info will hold the new 24bit bitmap info
        BITMAPINFO bmiInfo;

        // width and height of the bitmap
        WORD wBmpWidth, wBmpHeight;

        // ---------------------------------------------------------
        // get some info from the bitmap
        // ---------------------------------------------------------
        GetObject(pBitmap, sizeof(bmpBmp),&bmpBmp);
        pbmiInfo   = (LPBITMAPINFO)&bmpBmp;

        // get width and height
        wBmpWidth  = (WORD)pbmiInfo->bmiHeader.biWidth;
        wBmpWidth -= (wBmpWidth%4);                       // width is 4 byte boundary aligned.
        wBmpHeight = (WORD)pbmiInfo->bmiHeader.biHeight;

        // copy to caller width and height parms
        *pwWidth  = wBmpWidth;
        *pwHeight = wBmpHeight;
        // ---------------------------------------------------------

        // allocate width * height * 24bits pixels
        //BYTE *pPixels = new BYTE[wBmpWidth*wBmpHeight*3];
        BYTE *pPixels = new (std::nothrow) BYTE[wBmpWidth*wBmpHeight*3];
        if (pPixels==0)
            return NULL;

        // get user desktop device context to get pixels from
        HDC hDC = GetWindowDC(NULL);

        // fill desired structure
        bmiInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        bmiInfo.bmiHeader.biWidth = wBmpWidth;
        bmiInfo.bmiHeader.biHeight = -wBmpHeight;
        bmiInfo.bmiHeader.biPlanes = 1;
        bmiInfo.bmiHeader.biBitCount = 24;
        bmiInfo.bmiHeader.biCompression = BI_RGB;
        bmiInfo.bmiHeader.biSizeImage = wBmpWidth*wBmpHeight*3;
        bmiInfo.bmiHeader.biXPelsPerMeter = 0;
        bmiInfo.bmiHeader.biYPelsPerMeter = 0;
        bmiInfo.bmiHeader.biClrUsed = 0;
        bmiInfo.bmiHeader.biClrImportant = 0;

        // get pixels from the original bitmap converted to 24bits
        int iRes = GetDIBits(hDC,pBitmap,0,wBmpHeight,(LPVOID)pPixels,&bmiInfo,DIB_RGB_COLORS);

        // release the device context
        ReleaseDC(NULL,hDC);

        // if failed, cancel the operation.
        if (!iRes)
        {
            delete[] pPixels;
            return NULL;
        };

        // return the pixel array
        return pPixels;
    }

    HRGN RegionbyBitmap(HBITMAP pBitmap,COLORREF clrTransparent=-1 )
    {

        // bitmap width and height
        WORD wBmpWidth,wBmpHeight;

        // the final region and a temporary …
cambalinho 142 Practically a Posting Shark

finally it's working greate:

void SetCaretPos(POINT pos)
    {
        LONG characterIndexLine =0;
        characterIndexLine=(LONG) SendMessage(consoleedit, EM_LINEINDEX, (WPARAM) pos.y-1,0);
        characterIndexLine+=(LONG)pos.x;
        CHARRANGE cr;
        cr.cpMin = characterIndexLine;
        cr.cpMax = characterIndexLine;
        SendMessage(consoleedit, EM_EXSETSEL, 0, (LPARAM)&cr);
    }

    COORD GetCaretPos( )
    {
        COORD pos;
        //getting the line where is the caret(WPARAM is -1 for the caret position):
        pos.Y=(LONG) SendMessage(consoleedit, EM_LINEFROMCHAR,(WPARAM)-1,0)+1;

        //getting the caret on text position:
        CHARRANGE cr;
        cr.cpMin = 0;
        cr.cpMax = 0;
        SendMessage(consoleedit, EM_EXGETSEL, 0, (LPARAM)&cr);

        //getting the 1st charater line position(is gived on text position). for use the caret position, we can use -1:
        LONG firstcharacter=SendMessage(consoleedit, EM_LINEINDEX, (WPARAM)-1,0);

        //the caret text position minus the 1st character on that line, will give me the x:
        pos.X=cr.cpMin-firstcharacter;
        return pos;
    }

why on set '-1' and on get '+1'?
because the lines are indexed by zero.
thanks for all
PS: readers when we need use 1 function name igual of the win32 function name, we must use '::' before the win32 functions name ;)

nullptr: you tryied tell me something. but with more search i get it.. thanks

cambalinho 142 Practically a Posting Shark

nullptr: that gives me the character position on where is the caret. but give me the text position and not the line position.(the coordenates are gived by entire text, and not line position). i can't divide with number of lines because the lines don't have the same lenght deppending on it's font

cambalinho 142 Practically a Posting Shark

the GetCaretPos() don't works on richedit :(
unless, first, i need recreate it?

cambalinho 142 Practically a Posting Shark

i'm trying getting the richedit caret positions. seems that i can't use the caret functions.

LONG firstCharIndex(HWND hwnd)
    {
        POINT pt;
        pt.x=0;
        pt.y=0;
        LONG n = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&pt);
        return LOWORD(n);
    }

   COORD GetCaretPos( )
        {
            COORD pos;
            //getting the line from caret position:
            pos.Y=(LONG) SendMessage(consoleedit, EM_LINEFROMCHAR,(WPARAM)-1,0);
            CHARRANGE cr;
            cr.cpMin = 0;
            cr.cpMax = 0;
            SendMessage(consoleedit, EM_EXGETSEL, 0, (LPARAM)&cr);
            pos.X=cr.cpMin - firstCharIndex(consoleedit);
            DebugText("min: " + to_string(cr.cpMin) + " first: " + to_string(firstCharIndex(consoleedit)) );
            return pos;
        }

i get the Y correctly, but i don't understand how can i get the X.. can anyone advice me?

cambalinho 142 Practically a Posting Shark

nullptr: that thread is limited.
heres my code:

void SetWindowSize(COORD newsize)//newaize recive the number of characters been showed on window
    {
        CONSOLE_SCREEN_BUFFER_INFOEX consolesize;

        consolesize.cbSize=sizeof(consolesize);

        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

        GetConsoleScreenBufferInfoEx(hConsole,&consolesize);

        COORD c;
        c.X = newsize.X;
        c.Y = newsize.Y;
        consolesize.dwSize = c;
        consolesize.dwMaximumWindowSize = c; //change the window max size

        consolesize.srWindow.Left = 0;
        consolesize.srWindow.Right = c.X;
        consolesize.srWindow.Top = 0;
        consolesize.srWindow.Bottom = c.Y;
        //srWindow, c and dwMaximumWindowSize are the same
        //here i don't use pixels. for that i must get the current font size and then calculate the number of characters

        SetConsoleScreenBufferInfoEx(hConsole, &consolesize);
        SetConsoleWindowInfo(hConsole, FALSE, &consolesize.srWindow);
    }

these code works fine. but for we use pixels, instead characters number, we must get the current font size and calculate the number of characters:
horizontalnumberofcharacters=(pixelswidth-bordersize)/currentfontsize.x;
verticalnumberofcharacters=(pixelsheight-bordersize)/currentfontsize.y;
- i don't have sure about border size, we can get it. but will be (-bordersize*2)?
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
(that function isn't completed for these and see if the border is showed and the SM_CYCAPTION is for caption border size)
thanks to all

cambalinho 142 Practically a Posting Shark

is SetConsoleScreenBufferSize() limitted?
if i use it on constructor, works. affter that don't... confused :(
the GetLastError() is 87 - 'The parameter is incorrect.'

cambalinho 142 Practically a Posting Shark

how can i resize a window console buffer?
i know that i can use the SetConsoleScreenBufferSize(), but i'm getting problems convert from pixels to characters, because the vertical scrollbar is showed and the size isn't changed correctly, because it's more big than the buffer size:

CONSOLE_SCREEN_BUFFER_INFOEX consolesize;
        consolesize.cbSize=sizeof(consolesize);
        GetConsoleScreenBufferInfoEx(hConsole,&consolesize);
        COORD c;
        consolesize.srWindow.Right  = newsize.X+consolesize.srWindow.Right;
        consolesize.srWindow.Bottom = newsize.Y + consolesize.srWindow.Left;
        CONSOLE_FONT_INFO consolefont={0} ;
        GetCurrentConsoleFont(hConsole, FALSE,&consolefont);
        GetConsoleFontSize(hConsole,consolefont.nFont);
        c.X =(consolesize.srWindow.Right)/consolefont.dwFontSize.X;
        c.Y =(consolesize.srWindow.Bottom)/consolefont.dwFontSize.Y;
        SetConsoleScreenBufferSize( hConsole, c );
        SetConsoleWindowInfo(hConsole, FALSE, &consolesize.srWindow);

how can i fix these problem?

cambalinho 142 Practically a Posting Shark

triumphost: i had found some errors on your code.. i fix them, but i don't get any results :(

friend std::ostream& operator << (std::ostream& lhs, const image& rhs)
    {
        STATSTG stats = {0};
        IStream* pIStream = nullptr;
        CLSID pngClsid;
        CreateStreamOnHGlobal(nullptr, TRUE, &pIStream);
        GetEncoderClsid(L"image/gif", &pngClsid);
        rhs.img->Save(pIStream, &pngClsid, nullptr);
        pIStream->Stat(&stats, 0);
        ULONG dwRead = 0;
        STATSTG stInformation;
        std::size_t size = stats.cbSize.QuadPart;
        std::vector<unsigned char> pixels;
        pixels.resize(size);
        pIStream->Read(&pixels[0], size, &dwRead);
        pIStream->Release();
        lhs.write(reinterpret_cast<const char*>(&size), sizeof(size));
        lhs.write(reinterpret_cast<const char*>(&pixels[0]), size);
        return lhs;
    }


    friend std::istream& operator >> (std::istream& lhs, image& rhs)
    {   

        std::size_t size = 0;
        std::vector<unsigned char> pixels;
        IStream *pStream = nullptr;
        ULONG dwWritten = 0;
        LARGE_INTEGER li;
        li.QuadPart = 0;
        lhs.read(reinterpret_cast<char*>(&size), sizeof(size));
        pixels.resize(size);
        lhs.read(reinterpret_cast<char*>(&pixels[0]), size);
        CreateStreamOnHGlobal(nullptr, TRUE, &pStream);
        pStream->Write(&pixels[0], size, &dwWritten);
        pStream->Seek(li, STREAM_SEEK_SET, nullptr);
        pixels = std::vector<unsigned char>();
        rhs.img->FromStream(pStream, FALSE);
        pStream->Release();
        return lhs;
    }

i don't get any results :(

cambalinho 142 Practically a Posting Shark

how can i get IStream size?

cambalinho 142 Practically a Posting Shark

error:

pStream->cbSize.QuadPart

error: 'IStream' has no member named 'cbSize'|

cambalinho 142 Practically a Posting Shark

i'm sorry, but your correction have a memory leak.
"You can write the GDIPlus::Image by getting its HBitmap or its pixels."
for static images. but not animated gif's. that's why i need write\read them in stream way:

friend std::ostream& operator << (std::ostream& lhs, const image& rhs)
    {
        if(IfFileExists(rhs.strfilename)==true)
            lhs<<rhs.strfilename;
        else
        {
            IStream* pIStream1 = NULL;
            CreateStreamOnHGlobal(NULL,FALSE,&pIStream1);
            CLSID pngClsid;
            GetEncoderClsid(L"image/gif", &pngClsid);
            rhs.img->Save(pIStream1,&pngClsid,NULL);
            lhs<< pIStream1;
        }
        return lhs;
    }


    friend std::istream& operator >> (std::istream& lhs, image& rhs)
    {

        lhs>>rhs.strfilename;
        if(IfFileExists(rhs.strfilename)==true)
            rhs.readimagefile(rhs.strfilename);//FileName it's a property
        else
        {
            IStream* pIStream1 = NULL;

            lhs>> (char*)pIStream1;
            rhs.img->FromStream(pIStream1,FALSE);
        }
        return lhs;
    }

but i get a memory leak :(

cambalinho 142 Practically a Posting Shark

i have news :)
now i overload the string ostream and istream:

std::ostream& operator << (std::ostream& lhs, const string& rhs)
{
    int stringsize=rhs.size();
    lhs<<stringsize;
    lhs.write(reinterpret_cast< const char*>(&rhs),rhs.size());
    return lhs;
}

std::istream& operator >> (std::istream& lhs, string& rhs)
{
    string chrfilename;
    int stringsize;
    lhs>>stringsize;
    lhs.read(reinterpret_cast<char*>(&chrfilename), stringsize);
    rhs=chrfilename;
    return lhs;
}

but string have them, but it's limited. i mean it will read until space ' '... using these overloading we can read a entire string.
i need ask anotherthing:
- using your code, i can overloading for HBITMAP;
- but i don't know how i will do it for Image GDIPLUS :(
we have the Save() method with IStream but it's diferent from ostream and istream, right?

cambalinho 142 Practically a Posting Shark

thanks for that triumphost.
now i need another correction :(
i can overloading the operator >> and <<. but can i overloading the read() and write()?
i need overloading these operator for just use the object name for write\read it on file

cambalinho 142 Practically a Posting Shark

see just in these way:

friend ofstream& operator << (ofstream &os, const image &img2)
    {
        os << img2.strfilename;
        return os;
    }

    friend ifstream& operator << (ifstream &is, image &img2)
    {
        if(img2.isGDIPLUSIniciated==false)
        {
            Gdiplus::GdiplusStartup(&img2.m_gdiplusToken, &img2.gdiplusStartupInput, NULL);
            img2.isGDIPLUSIniciated=true;
        }
        is >> img2.strfilename ;
        img2.readimagefile(img2.strfilename);
        return is;
    }

like you see i only save the string file name(just testing). the image is showed, but when i closes, the problem continues

cambalinho 142 Practically a Posting Shark

true.. now i have miss something that i don't know :(
these functions aren't completed, but they miss something that i don't know:

friend ofstream& operator << (ofstream &os, const image &img2)
    {
        os << img2.imageweight << img2.imageheight << img2.strfilename;
        os.write(reinterpret_cast<const char*>(img2.hbmMask), sizeof(HBITMAP));
        os.write(reinterpret_cast<const char*>(img2.img), sizeof(Image));

        return os;
    }

    friend ifstream& operator << (ifstream &is, image &img2)
    {
        if(img2.isimgused==false)
            img2.isimgused==true;
        if(img2.isGDIPLUSIniciated==false)
        {
            Gdiplus::GdiplusStartup(&img2.m_gdiplusToken, &img2.gdiplusStartupInput, NULL);
            img2.isGDIPLUSIniciated=true;
        }
        is >> img2.imageweight >> img2.imageheight >> img2.strfilename ;
        is.read(reinterpret_cast<char*>(img2.hbmMask), sizeof(HBITMAP));
        img2.readimagefile(img2.strfilename);
        return is;
    }

the problem continues even test it with readimagefile() function. the HBITMAP is returned without the problem. the problem is when i close the aplication :(

cambalinho 142 Practically a Posting Shark

from your 1st code i get these error:
"'std::ofstream& image::operator<<(std::ofstream&, const image&)' must take exactly one argument"
why?

cambalinho 142 Practically a Posting Shark

i'm sorry triumphost, but how can i overloading ofstream and ifstream?

friend ofstream &operator << (ofstream &f, const image &obj)
    {
        f<<obj.HBitmap <<obj.imageweight << obj.imageheight<<obj.img;
        return f;
    }

    friend ifstream &operator >> (ifstream &f, const image &obj)
    {
        f>>obj.HBitmap >>obj.imageweight >> obj.imageheight>>obj.img;
        return f;
    }

error message: "cannot bind 'std::basic_istream<char>' lvalue to 'std::basic_istream<char>&&'"

cambalinho 142 Practically a Posting Shark

triumphost: the error only happens when i close\ends the program.
now i use C++ code, it's more stable.
i can use the string.
but i have my image class: have a HBITMAP object. now i don't get any error, unless i use my image class. can you explain better?

struct user
{
    string name="";
    string adress="";
    image foto;
    int age=0;

};

user usrName[2];
user usrName2[2];

template<typename structure>
void SaveDataBase(string filename,structure &StructureVariable )
{
    remove(filename.c_str());
    ofstream writefile;
    writefile.open(filename.c_str(), ios::out | ios::binary);
    writefile.write ((char *)&StructureVariable,sizeof(structure));
    writefile.close();
}

template<typename structure>
void ReadDataBase(string filename,structure &StructureVariable )
{
    ifstream readfile;
    readfile.open(filename.c_str(), ios::out | ios::binary);
    readfile.read ((char*)&StructureVariable,sizeof(structure));
    readfile.close();
}
//using it:
    usrName[0].adress="viseu";
    usrName[0].age=23;
    usrName[0].name="joaquim";
    usrName[0].foto.FileName="C:\\Nova pasta\\acrobat.bmp";
    usrName[1].adress="viseu2";
    usrName[1].age=233;
    usrName[1].name="joaquim2";
    usrName[1].foto.FileName="C:\\Nova pasta\\acrobat.bmp";

    remove("C:\\Nova pasta\\username1.dat");
    SaveDataBase("C:\\Nova pasta\\username1.dat",usrName);
    ReadDataBase("C:\\Nova pasta\\username1.dat",usrName2);

when i close\ends the program, i get the error. if i take of the image object, no error happens.
heres the image error: https://onedrive.live.com/?id=C3EF456E15C8DEB6!1299&cid=C3EF456E15C8DEB6&group=0&parId=C3EF456E15C8DEB6!197&o=OneUp
these is a Windows message. so i only can show you: 'the program stops working\responding'

cambalinho 142 Practically a Posting Shark

triumphost: i'm sorry, but i can read the file. my problem is, only, when i close\ends the program

cambalinho 142 Practically a Posting Shark

i have these code for save a structure data to a file and then read it:

struct user
{
    string name;
    image foto;
    string adress;
    int age;
};

user usrName={"joaquim",image("C:\\Nova pasta\\acrobat.bmp"), "viseu",32};
user usrName2;

FILE* f = fopen("C:\\Nova pasta\\username1.dat", "w+b");
    if(f==NULL)
        DebugText("error");
    fwrite(&usrName, sizeof( user), 1, f);
    fseek(f, 0, SEEK_SET);
    fread(&usrName2, sizeof(user), 1, f);
    fclose(f);

    img=usrName2.foto;

only when i end the program, i get, sometimes, a memory leak.
what you can tell me?
(image is my image class, for working with images)

cambalinho 142 Practically a Posting Shark

i need just an intro about Matrix. what is Matrix and what i can do?
i understand that i can rotate, scale, mirror and more. but can i swap pixels?(convert red to green)
i don't know so much about Matrix intro :(

cambalinho 142 Practically a Posting Shark

i'm sorry, is my code\question confused?

cambalinho 142 Practically a Posting Shark

sorry continues with some problems. but i fix it:

class BitmapDC
{
private:
    MemoryDC hdcbitmap;
    HGDIOBJ bitmapold;
    HBITMAP bitmapcurrent;

    MemoryDC hdcbitmap2;
    HGDIOBJ bitmapold2;
    HBITMAP bitmapcurrent2;

    int intwidth;
    int intheight;

    void init(int width, int height)
    {
        bitmapcurrent = CreateBitmap(width, height, 1, 32, NULL);
        bitmapold = SelectObject(hdcbitmap, bitmapcurrent);
        intwidth=width;
        intheight=height;
    }

    void destroy()
    {
        SelectObject(hdcbitmap, bitmapold);
        DeleteObject(bitmapcurrent);
    }

    void destroyreturn()
    {
        SelectObject(hdcbitmap2, bitmapold2);
        DeleteObject(bitmapcurrent2);
    }


public:

    BitmapDC(int width, int height)
    {
        init(width, height);
    }

    BitmapDC()
    {
        init(1, 1);
    }

    void resize(int width, int height)
    {
        destroy();
        init(width, height);
        destroyreturn();
        bitmapcurrent2 = CreateBitmap(intwidth, intheight, 1, 32, NULL);
        bitmapold2 = SelectObject(hdcbitmap2, bitmapcurrent2);
        BitBlt(hdcbitmap2, 0, 0, intwidth, intheight, hdcbitmap, 0, 0, SRCCOPY);
        SelectObject(hdcbitmap2, bitmapold2);

    }

    int Width()
    {
        return intwidth;
    }

    int Height()
    {
        return intheight;
    }

    BitmapDC& operator= (const BitmapDC &bitmapsource)
    {
        if (this == &bitmapsource)      // Same object?
            return *this;
        destroy();
        init(bitmapsource.intwidth, bitmapsource.intheight);
        BitBlt(hdcbitmap, 0, 0, intwidth, intheight, bitmapsource.hdcbitmap, 0, 0, SRCCOPY);
        return *this;
    }

    BitmapDC& operator= (const HBITMAP &bitmapsource)
    {
        destroy();
        BITMAP bm;
        GetObject(bitmapsource,sizeof(bm),&bm);
        init(bm.bmWidth, bm.bmHeight);
        DrawHBITMAPtoHDC(bitmapsource,hdcbitmap);
        return *this;
    }

    //testing the bitmao value if is nullptr
    bool operator != ( nullptr_t ) const
    {
        return bitmapcurrent != nullptr;
    }

    bool operator==(const BitmapDC &other) const
    {
        return (other.bitmapcurrent == this->bitmapcurrent);
    }

    bool operator!=(const BitmapDC &other) const
    {
        return !(*this == other);
    }

    operator HBITMAP()
    {
        destroyreturn();
        bitmapcurrent2 = CreateBitmap(intwidth, intheight, 1, 32, NULL);
        bitmapold2 = SelectObject(hdcbitmap2, bitmapcurrent2);
        BitBlt(hdcbitmap2, 0, 0, intwidth, intheight, hdcbitmap, 0, 0, SRCCOPY);
        SelectObject(hdcbitmap2, bitmapold2);
        return bitmapcurrent2;
    }

    operator HDC() const
    {
        return hdcbitmap;
    }

    ~BitmapDC()
    {
       destroy(); …
cambalinho 142 Practically a Posting Shark

can i print it on a pdf file(or other virtual printer) for don't lose so many cartridges?
i had installed 1, but i only get a empty page :(

cambalinho 142 Practically a Posting Shark

i'm sorry, but i get errors here:

operator HBITMAP() const
    {
        if (bitmapold)
        {
            SelectObject(hdcbitmap, bitmapold);
            bitmapold = nullptr;//error
        }
        return bitmapcurrent;
    }

"assignment of member 'BitmapDC::bitmapold' in read-only object"
i get these same error on other places that we assign

cambalinho 142 Practically a Posting Shark

i was close to finish the code... but i lose the cartridges on printer :(
in time i will came back here

cambalinho 142 Practically a Posting Shark

correct me more. how can i fix it for i return the HBITMAP?

cambalinho 142 Practically a Posting Shark

i'm sorry i can't see what is the include file.
i can't use the GetPrinterDC() function.

cambalinho 142 Practically a Posting Shark

but i don't use VS20015 and i don't want show the printer dialog. these is just for print what is on window

cambalinho 142 Practically a Posting Shark

ok.. almost done:

void print()
        {
            //getting the default printer name
            char szPrinterName[255];
            unsigned long lPrinterNameLength;
            GetDefaultPrinter( szPrinterName, &lPrinterNameLength );

            //getting printer DC
            HDC printerDC = CreateDC( "WINSPOOL",szPrinterName, NULL, NULL);

            //starting doc and pages:
            DOCINFO doc;
            doc.cbSize = sizeof(DOCINFO);
            doc.lpszDocName = "1st doc";
            StartDoc(printerDC, &doc);
            StartPage(printerDC);

            //draw on printer using GDI functions
            RECT windowRect;
            GetClientRect(hwnd,&windowRect);
            SetMapMode(printerDC, GetMapMode(GetDC(hwnd)));
            BitBlt(printerDC,0,0,windowRect.right,windowRect.bottom,GetDC(hwnd),0,0,SRCCOPY);

            //end pages and doc
            EndPage(printerDC);
            EndDoc(printerDC);

            //delete the printer DC
            DeleteDC(printerDC);
        }

my problem is: how can i convert pixels to printer scale mode(i don't know.. is realy dpi?)?

cambalinho 142 Practically a Posting Shark

can i print a window without printer dialog?