Skip to main content
"it needs the GDI+ library and header includes for Windows, to compile."
Link
Post Reopened by Jamal
deleted 2 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

C++ Win32 GDI+ Memorymemory and Stylestyle

// Includes
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0502
#include <windows.h>
#include <stdio.h> 
#include <windowsx.h>
#include <string>
#include <cstdlib>
#include <iostream>
#include <gdiplus.h>

// Global Variables
HWND hWnd;
HINSTANCE hInstance;
ULONG_PTR gdiplusToken;
int count;
Style lk;
 
 
// Functions
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void LoadStyle();
void UnloadStyle();
 
 
 
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) {
   
    // GDI+
    GdiplusStartupInput gdiplusStartupInput;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
   
    // Normal Vars
    HWND hwnd;              
    MSG messages;            
    WNDCLASSEX wincl;      
 
    // window structure to register
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      
    wincl.style = CS_DBLCLKS;            
    wincl.cbSize = sizeof (WNDCLASSEX);
    // defaults
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                  
    // background color
    wincl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
 
    // register window class
    if (!RegisterClassEx (&wincl))
        return 0;
 
    // Create window
    hwnd = CreateWindowEx(0, szClassName, L"Test Transparent Static Main Window", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, HWND_DESKTOP, NULL, hThisInstance, NULL);        
    ShowWindow (hwnd, nFunsterStil);
   
    // Set globals
    hWnd = hwnd;
    hInstance = hThisInstance;
   
    // Main window message loop
    while (GetMessage (&messages, NULL, 0, 0)) {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return messages.wParam;
}
 
 
// Main Window Procedure
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
 
    switch (message) {
 
        case WM_CREATE: {    
            LoadStyle();
            const int timerSpeed = 75;
            SetTimer(hwnd, ID_TIMER, timerSpeed, NULL);
        } break;
           
        case WM_PAINT: {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
        } break;
       
       case WM_DESTROY: {
            UnloadStyle();
            GdiplusShutdown(gdiplusToken);
            PostQuitMessage(0);  
        } break;
 
        case WM_TIMER: {
           
            // Start -----------------------------------------------------------------------------------------------------------------------------------
            HDC hdc = GetDC(hWnd);
            Graphics *g = new Graphics(hdc);
            g->FillRectangle(lk.blackBrush, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
            g->SetTextRenderingHint(TextRenderingHintAntiAlias);
           
            // Draw Strings
            g->DrawString(L"String1", -1, lk.font, PointF(0, 0), lk.textColor1);  
            g->DrawString(L"String2", -1, lk.font, PointF(0, 120), lk.textColor2);                
           
            // Done
            ReleaseDC(hWnd, hdc);
            delete hdc;
            g->Flush();
            delete g;
            // -------------------------------------------------------------------------------------------------------------------------------------
       
        } break;
       
        default: {
            return DefWindowProc (hwnd, message, wParam, lParam);
        }
    }
    return 0;
}
 
 
 
void LoadStyle() {
    lk.blackBrush = new SolidBrush(Color(25,10,10,10));
    lk.penBorder = new Pen(Color(100,255,255,255), 3);            
    lk.fontFamily = new FontFamily(L"Times New Roman");
    lk.font = new Font(lk.fontFamily, 32, FontStyleBold, UnitPixel);
    lk.textColor1 = new SolidBrush(Color(100,100,100,100));
    lk.textColor2 = new SolidBrush(Color(200,200,200,200));
}                
 
void UnloadStyle() {
    delete lk.blackBrush;
    delete lk.penBorder;
    delete lk.fontFamily;
    delete lk.font;
    delete lk.textColor1;
    delete lk.textColor2;    
}

I compiled this with wxDevC++, and it needs the GDI+ library and header includes for windowsWindows, to compile.

On a larger program I have had memory fluctuating from plus minus 4mbs4MBs. Not a lot, but questionable why is it doing that?

This is a short replication, itwhich fluctuates by .1mb1MB.

I'm wondering if there is a mistake, or is that normal? Other programs on my computer I seeexperience no fluctuation in its memory usage.

Also, I saved all the common used GDI+ tools so they did not need to be created every time. Good Is that good or bad?

Thanks.

// Includes
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0502
#include <windows.h>
#include <stdio.h> 
#include <windowsx.h>
#include <string>
#include <cstdlib>
#include <iostream>
#include <gdiplus.h>

// Global Variables
HWND hWnd;
HINSTANCE hInstance;
ULONG_PTR gdiplusToken;
int count;
Style lk;
 
 
// Functions
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void LoadStyle();
void UnloadStyle();
 
 
 
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) {
   
    // GDI+
    GdiplusStartupInput gdiplusStartupInput;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
   
    // Normal Vars
    HWND hwnd;              
    MSG messages;            
    WNDCLASSEX wincl;      
 
    // window structure to register
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      
    wincl.style = CS_DBLCLKS;            
    wincl.cbSize = sizeof (WNDCLASSEX);
    // defaults
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                  
    // background color
    wincl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
 
    // register window class
    if (!RegisterClassEx (&wincl))
        return 0;
 
    // Create window
    hwnd = CreateWindowEx(0, szClassName, L"Test Transparent Static Main Window", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, HWND_DESKTOP, NULL, hThisInstance, NULL);        
    ShowWindow (hwnd, nFunsterStil);
   
    // Set globals
    hWnd = hwnd;
    hInstance = hThisInstance;
   
    // Main window message loop
    while (GetMessage (&messages, NULL, 0, 0)) {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return messages.wParam;
}
 
 
// Main Window Procedure
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
 
    switch (message) {
 
        case WM_CREATE: {    
            LoadStyle();
            const int timerSpeed = 75;
            SetTimer(hwnd, ID_TIMER, timerSpeed, NULL);
        } break;
           
        case WM_PAINT: {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
        } break;
       
       case WM_DESTROY: {
            UnloadStyle();
            GdiplusShutdown(gdiplusToken);
            PostQuitMessage(0);  
        } break;
 
        case WM_TIMER: {
           
            // Start -----------------------------------------------------------------------------------------------------------------------------------
            HDC hdc = GetDC(hWnd);
            Graphics *g = new Graphics(hdc);
            g->FillRectangle(lk.blackBrush, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
            g->SetTextRenderingHint(TextRenderingHintAntiAlias);
           
            // Draw Strings
            g->DrawString(L"String1", -1, lk.font, PointF(0, 0), lk.textColor1);  
            g->DrawString(L"String2", -1, lk.font, PointF(0, 120), lk.textColor2);                
           
            // Done
            ReleaseDC(hWnd, hdc);
            delete hdc;
            g->Flush();
            delete g;
            // -------------------------------------------------------------------------------------------------------------------------------------
       
        } break;
       
        default: {
            return DefWindowProc (hwnd, message, wParam, lParam);
        }
    }
    return 0;
}
 
 
 
void LoadStyle() {
    lk.blackBrush = new SolidBrush(Color(25,10,10,10));
    lk.penBorder = new Pen(Color(100,255,255,255), 3);            
    lk.fontFamily = new FontFamily(L"Times New Roman");
    lk.font = new Font(lk.fontFamily, 32, FontStyleBold, UnitPixel);
    lk.textColor1 = new SolidBrush(Color(100,100,100,100));
    lk.textColor2 = new SolidBrush(Color(200,200,200,200));
}                
 
void UnloadStyle() {
    delete lk.blackBrush;
    delete lk.penBorder;
    delete lk.fontFamily;
    delete lk.font;
    delete lk.textColor1;
    delete lk.textColor2;    
}

C++ Win32 GDI+ Memory and Style

// Includes
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0502
#include <windows.h>
#include <stdio.h> 
#include <windowsx.h>
#include <string>
#include <cstdlib>
#include <iostream>
#include <gdiplus.h>

// Global Variables
HWND hWnd;
HINSTANCE hInstance;
ULONG_PTR gdiplusToken;
int count;
Style lk;
 
 
// Functions
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void LoadStyle();
void UnloadStyle();
 
 
 
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) {
   
    // GDI+
    GdiplusStartupInput gdiplusStartupInput;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
   
    // Normal Vars
    HWND hwnd;              
    MSG messages;            
    WNDCLASSEX wincl;      
 
    // window structure to register
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      
    wincl.style = CS_DBLCLKS;            
    wincl.cbSize = sizeof (WNDCLASSEX);
    // defaults
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                  
    // background color
    wincl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
 
    // register window class
    if (!RegisterClassEx (&wincl))
        return 0;
 
    // Create window
    hwnd = CreateWindowEx(0, szClassName, L"Test Transparent Static Main Window", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, HWND_DESKTOP, NULL, hThisInstance, NULL);        
    ShowWindow (hwnd, nFunsterStil);
   
    // Set globals
    hWnd = hwnd;
    hInstance = hThisInstance;
   
    // Main window message loop
    while (GetMessage (&messages, NULL, 0, 0)) {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return messages.wParam;
}
 
 
// Main Window Procedure
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
 
    switch (message) {
 
        case WM_CREATE: {    
            LoadStyle();
            const int timerSpeed = 75;
            SetTimer(hwnd, ID_TIMER, timerSpeed, NULL);
        } break;
           
        case WM_PAINT: {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
        } break;
       
       case WM_DESTROY: {
            UnloadStyle();
            GdiplusShutdown(gdiplusToken);
            PostQuitMessage(0);  
        } break;
 
        case WM_TIMER: {
           
            // Start -----------------------------------------------------------------------------------------------------------------------------------
            HDC hdc = GetDC(hWnd);
            Graphics *g = new Graphics(hdc);
            g->FillRectangle(lk.blackBrush, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
            g->SetTextRenderingHint(TextRenderingHintAntiAlias);
           
            // Draw Strings
            g->DrawString(L"String1", -1, lk.font, PointF(0, 0), lk.textColor1);  
            g->DrawString(L"String2", -1, lk.font, PointF(0, 120), lk.textColor2);                
           
            // Done
            ReleaseDC(hWnd, hdc);
            delete hdc;
            g->Flush();
            delete g;
            // -------------------------------------------------------------------------------------------------------------------------------------
       
        } break;
       
        default: {
            return DefWindowProc (hwnd, message, wParam, lParam);
        }
    }
    return 0;
}
 
 
 
void LoadStyle() {
    lk.blackBrush = new SolidBrush(Color(25,10,10,10));
    lk.penBorder = new Pen(Color(100,255,255,255), 3);            
    lk.fontFamily = new FontFamily(L"Times New Roman");
    lk.font = new Font(lk.fontFamily, 32, FontStyleBold, UnitPixel);
    lk.textColor1 = new SolidBrush(Color(100,100,100,100));
    lk.textColor2 = new SolidBrush(Color(200,200,200,200));
}                
 
void UnloadStyle() {
    delete lk.blackBrush;
    delete lk.penBorder;
    delete lk.fontFamily;
    delete lk.font;
    delete lk.textColor1;
    delete lk.textColor2;    
}

I compiled this with wxDevC++, it needs the GDI+ library and header includes for windows, to compile.

On a larger program I have had memory fluctuating from plus minus 4mbs. Not a lot, but questionable why is it doing that?

This is a short replication, it fluctuates by .1mb.

I'm wondering if there is a mistake, is that normal? Other programs on my computer I see no fluctuation in its memory usage.

Also, I saved all the common used GDI+ tools so they did not need to be created every time. Good or bad?

Thanks.

Win32 GDI+ memory and style

I compiled this with wxDevC++, and it needs the GDI+ library and header includes for Windows, to compile.

On a larger program I have had memory fluctuating from plus minus 4MBs. Not a lot, but why is it doing that?

This is a short replication, which fluctuates by .1MB.

I'm wondering if there is a mistake, or is that normal? Other programs on my computer experience no fluctuation in its memory usage.

Also, I saved all the common used GDI+ tools so they did not need to be created every time. Is that good or bad?

// Includes
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0502
#include <windows.h>
#include <stdio.h> 
#include <windowsx.h>
#include <string>
#include <cstdlib>
#include <iostream>
#include <gdiplus.h>

// Global Variables
HWND hWnd;
HINSTANCE hInstance;
ULONG_PTR gdiplusToken;
int count;
Style lk;
 
 
// Functions
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void LoadStyle();
void UnloadStyle();
 
 
 
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) {
   
    // GDI+
    GdiplusStartupInput gdiplusStartupInput;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
   
    // Normal Vars
    HWND hwnd;              
    MSG messages;            
    WNDCLASSEX wincl;      
 
    // window structure to register
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      
    wincl.style = CS_DBLCLKS;            
    wincl.cbSize = sizeof (WNDCLASSEX);
    // defaults
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                  
    // background color
    wincl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
 
    // register window class
    if (!RegisterClassEx (&wincl))
        return 0;
 
    // Create window
    hwnd = CreateWindowEx(0, szClassName, L"Test Transparent Static Main Window", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, HWND_DESKTOP, NULL, hThisInstance, NULL);        
    ShowWindow (hwnd, nFunsterStil);
   
    // Set globals
    hWnd = hwnd;
    hInstance = hThisInstance;
   
    // Main window message loop
    while (GetMessage (&messages, NULL, 0, 0)) {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return messages.wParam;
}
 
 
// Main Window Procedure
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
 
    switch (message) {
 
        case WM_CREATE: {    
            LoadStyle();
            const int timerSpeed = 75;
            SetTimer(hwnd, ID_TIMER, timerSpeed, NULL);
        } break;
           
        case WM_PAINT: {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
        } break;
       
       case WM_DESTROY: {
            UnloadStyle();
            GdiplusShutdown(gdiplusToken);
            PostQuitMessage(0);  
        } break;
 
        case WM_TIMER: {
           
            // Start -----------------------------------------------------------------------------------------------------------------------------------
            HDC hdc = GetDC(hWnd);
            Graphics *g = new Graphics(hdc);
            g->FillRectangle(lk.blackBrush, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
            g->SetTextRenderingHint(TextRenderingHintAntiAlias);
           
            // Draw Strings
            g->DrawString(L"String1", -1, lk.font, PointF(0, 0), lk.textColor1);  
            g->DrawString(L"String2", -1, lk.font, PointF(0, 120), lk.textColor2);                
           
            // Done
            ReleaseDC(hWnd, hdc);
            delete hdc;
            g->Flush();
            delete g;
            // -------------------------------------------------------------------------------------------------------------------------------------
       
        } break;
       
        default: {
            return DefWindowProc (hwnd, message, wParam, lParam);
        }
    }
    return 0;
}
 
 
 
void LoadStyle() {
    lk.blackBrush = new SolidBrush(Color(25,10,10,10));
    lk.penBorder = new Pen(Color(100,255,255,255), 3);            
    lk.fontFamily = new FontFamily(L"Times New Roman");
    lk.font = new Font(lk.fontFamily, 32, FontStyleBold, UnitPixel);
    lk.textColor1 = new SolidBrush(Color(100,100,100,100));
    lk.textColor2 = new SolidBrush(Color(200,200,200,200));
}                
 
void UnloadStyle() {
    delete lk.blackBrush;
    delete lk.penBorder;
    delete lk.fontFamily;
    delete lk.font;
    delete lk.textColor1;
    delete lk.textColor2;    
}
added 4872 characters in body
Source Link
// Includes
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0502
#include <windows.h>
#include <stdio.h> 
#include <windowsx.h>
#include <string>
#include <cstdlib>
#include <iostream>
#include <gdiplus.h>

// Global Variables
HWND hWnd;
HINSTANCE hInstance;
ULONG_PTR gdiplusToken;
int count;
Style lk;
 
 
// Functions
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void LoadStyle();
void UnloadStyle();
 
 
 
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) {
   
    // GDI+
    GdiplusStartupInput gdiplusStartupInput;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
   
    // Normal Vars
    HWND hwnd;              
    MSG messages;            
    WNDCLASSEX wincl;      
 
    // window structure to register
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      
    wincl.style = CS_DBLCLKS;            
    wincl.cbSize = sizeof (WNDCLASSEX);
    // defaults
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                  
    // background color
    wincl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
 
    // register window class
    if (!RegisterClassEx (&wincl))
        return 0;
 
    // Create window
    hwnd = CreateWindowEx(0, szClassName, L"Test Transparent Static Main Window", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, HWND_DESKTOP, NULL, hThisInstance, NULL);        
    ShowWindow (hwnd, nFunsterStil);
   
    // Set globals
    hWnd = hwnd;
    hInstance = hThisInstance;
   
    // Main window message loop
    while (GetMessage (&messages, NULL, 0, 0)) {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return messages.wParam;
}
 
 
// Main Window Procedure
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
 
    switch (message) {
 
        case WM_CREATE: {    
            LoadStyle();
            const int timerSpeed = 75;
            SetTimer(hwnd, ID_TIMER, timerSpeed, NULL);
        } break;
           
        case WM_PAINT: {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
        } break;
       
       case WM_DESTROY: {
            UnloadStyle();
            GdiplusShutdown(gdiplusToken);
            PostQuitMessage(0);  
        } break;
 
        case WM_TIMER: {
           
            // Start -----------------------------------------------------------------------------------------------------------------------------------
            HDC hdc = GetDC(hWnd);
            Graphics *g = new Graphics(hdc);
            g->FillRectangle(lk.blackBrush, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
            g->SetTextRenderingHint(TextRenderingHintAntiAlias);
           
            // Draw Strings
            g->DrawString(L"String1", -1, lk.font, PointF(0, 0), lk.textColor1);  
            g->DrawString(L"String2", -1, lk.font, PointF(0, 120), lk.textColor2);                
           
            // Done
            ReleaseDC(hWnd, hdc);
            delete hdc;
            g->Flush();
            delete g;
            // -------------------------------------------------------------------------------------------------------------------------------------
       
        } break;
       
        default: {
            return DefWindowProc (hwnd, message, wParam, lParam);
        }
    }
    return 0;
}
 
 
 
void LoadStyle() {
    lk.blackBrush = new SolidBrush(Color(25,10,10,10));
    lk.penBorder = new Pen(Color(100,255,255,255), 3);            
    lk.fontFamily = new FontFamily(L"Times New Roman");
    lk.font = new Font(lk.fontFamily, 32, FontStyleBold, UnitPixel);
    lk.textColor1 = new SolidBrush(Color(100,100,100,100));
    lk.textColor2 = new SolidBrush(Color(200,200,200,200));
}                
 
void UnloadStyle() {
    delete lk.blackBrush;
    delete lk.penBorder;
    delete lk.fontFamily;
    delete lk.font;
    delete lk.textColor1;
    delete lk.textColor2;    
}

http://pastebin.com/Y8K3Lcn1 I compiled this with wxDevC++, it needs the GDI+ library and header includes for windows, to compile.

On a larger program I have had memory jumpingfluctuating from plus minus 4mbs. Not a lot, but questionable. why is it doing that?

This is a short version, memory jumps slightlyreplication, .1mb. (By that I mean it starts 1mb, then 1fluctuates by .1mb back to 1 etc...)

http://pastebin.com/Y8K3Lcn1

On a larger program I have had memory jumping from plus minus 4mbs. Not a lot, but questionable. This is a short version, memory jumps slightly, .1mb. (By that I mean it starts 1mb, then 1.1mb back to 1 etc...)

// Includes
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0502
#include <windows.h>
#include <stdio.h> 
#include <windowsx.h>
#include <string>
#include <cstdlib>
#include <iostream>
#include <gdiplus.h>

// Global Variables
HWND hWnd;
HINSTANCE hInstance;
ULONG_PTR gdiplusToken;
int count;
Style lk;
 
 
// Functions
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void LoadStyle();
void UnloadStyle();
 
 
 
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) {
   
    // GDI+
    GdiplusStartupInput gdiplusStartupInput;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
   
    // Normal Vars
    HWND hwnd;              
    MSG messages;            
    WNDCLASSEX wincl;      
 
    // window structure to register
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      
    wincl.style = CS_DBLCLKS;            
    wincl.cbSize = sizeof (WNDCLASSEX);
    // defaults
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                  
    // background color
    wincl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
 
    // register window class
    if (!RegisterClassEx (&wincl))
        return 0;
 
    // Create window
    hwnd = CreateWindowEx(0, szClassName, L"Test Transparent Static Main Window", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, HWND_DESKTOP, NULL, hThisInstance, NULL);        
    ShowWindow (hwnd, nFunsterStil);
   
    // Set globals
    hWnd = hwnd;
    hInstance = hThisInstance;
   
    // Main window message loop
    while (GetMessage (&messages, NULL, 0, 0)) {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return messages.wParam;
}
 
 
// Main Window Procedure
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
 
    switch (message) {
 
        case WM_CREATE: {    
            LoadStyle();
            const int timerSpeed = 75;
            SetTimer(hwnd, ID_TIMER, timerSpeed, NULL);
        } break;
           
        case WM_PAINT: {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
        } break;
       
       case WM_DESTROY: {
            UnloadStyle();
            GdiplusShutdown(gdiplusToken);
            PostQuitMessage(0);  
        } break;
 
        case WM_TIMER: {
           
            // Start -----------------------------------------------------------------------------------------------------------------------------------
            HDC hdc = GetDC(hWnd);
            Graphics *g = new Graphics(hdc);
            g->FillRectangle(lk.blackBrush, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
            g->SetTextRenderingHint(TextRenderingHintAntiAlias);
           
            // Draw Strings
            g->DrawString(L"String1", -1, lk.font, PointF(0, 0), lk.textColor1);  
            g->DrawString(L"String2", -1, lk.font, PointF(0, 120), lk.textColor2);                
           
            // Done
            ReleaseDC(hWnd, hdc);
            delete hdc;
            g->Flush();
            delete g;
            // -------------------------------------------------------------------------------------------------------------------------------------
       
        } break;
       
        default: {
            return DefWindowProc (hwnd, message, wParam, lParam);
        }
    }
    return 0;
}
 
 
 
void LoadStyle() {
    lk.blackBrush = new SolidBrush(Color(25,10,10,10));
    lk.penBorder = new Pen(Color(100,255,255,255), 3);            
    lk.fontFamily = new FontFamily(L"Times New Roman");
    lk.font = new Font(lk.fontFamily, 32, FontStyleBold, UnitPixel);
    lk.textColor1 = new SolidBrush(Color(100,100,100,100));
    lk.textColor2 = new SolidBrush(Color(200,200,200,200));
}                
 
void UnloadStyle() {
    delete lk.blackBrush;
    delete lk.penBorder;
    delete lk.fontFamily;
    delete lk.font;
    delete lk.textColor1;
    delete lk.textColor2;    
}

I compiled this with wxDevC++, it needs the GDI+ library and header includes for windows, to compile.

On a larger program I have had memory fluctuating from plus minus 4mbs. Not a lot, but questionable why is it doing that?

This is a short replication, it fluctuates by .1mb.

Post Closed as "Not suitable for this site" by Jamal
Source Link
Loading