Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "resource.h"
- #include <windows.h>
- #include <windowsx.h> // for TransparentBlt()
- #include <commctrl.h>
- #include <gdiplus.h>
- #pragma comment( linker, "/manifestdependency:\"type='win32' \
- name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
- processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
- language='*'\"")
- #pragma comment( lib, "comctl32.lib")
- #pragma comment( lib, "Msimg32.lib" ) // for TransparentBlt()
- #pragma comment( lib, "Gdiplus.lib" )
- using namespace Gdiplus;
- // variable for storing the instance
- static HINSTANCE hInst;
- // icons
- static HICON hIcon, // main window's icon
- hiAdmin; // icon in the left corner of the status bar
- // Images for logos
- Image *image, // left logo on main window's top banner
- *image1, // right logo on main window's top banner
- *btn5; // map for the orange static control
- // variables for painting the window
- static HBRUSH hbPozadina, // gray background brush for grid on the top
- BlueFrame, // needed to frame blue static controls
- hbr; // orange brush for orange panel
- static HBITMAP bmpBTN1, // image for top left blue static control
- bmpBTN2, // image for top right blue static control
- //============ these two make one image =========== //
- bmpBTN3, // left image for bottom left blue static control
- bmpBTN3a, // right image for bottom left blue static control
- //==================================================//
- bmpBTN4, // image for bottom right blue static control
- bmpSimbol, // middle logo on the main window's top banner
- bmpInfo, // top left image for child window of the 1st orange static control
- bmpLink, // top left image for child window of the 3rd orange static control
- bmpHelp; // top left image for child window of the 2nd orange static control
- /****************************** helper functions for WM_PAINT **************************/
- // Fills triangle with gradient brush
- void GradientTriangle( HDC MemDC, LONG x1, LONG y1, LONG x2, LONG y2, LONG x3, LONG y3,
- COLORREF top, COLORREF bottom )
- {
- TRIVERTEX vertex[3];
- vertex[0].x = x1;
- vertex[0].y = y1;
- vertex[0].Red = GetRValue(bottom) << 8;
- vertex[0].Green = GetGValue(bottom) << 8;
- vertex[0].Blue = GetBValue(bottom) << 8;
- vertex[0].Alpha = 0x0000;
- vertex[1].x = x2;
- vertex[1].y = y2;
- vertex[1].Red = GetRValue(top) << 8;
- vertex[1].Green = GetGValue(top) << 8;
- vertex[1].Blue = GetBValue(top) << 8;
- vertex[1].Alpha = 0x0000;
- vertex[2].x = x3;
- vertex[2].y = y3;
- vertex[2].Red = GetRValue(bottom) << 8;
- vertex[2].Green = GetGValue(bottom) << 8;
- vertex[2].Blue = GetBValue(bottom) << 8;
- vertex[2].Alpha = 0x0000;
- // Create a GRADIENT_TRIANGLE structure that
- // references the TRIVERTEX vertices.
- GRADIENT_TRIANGLE gTriangle;
- gTriangle.Vertex1 = 0;
- gTriangle.Vertex2 = 1;
- gTriangle.Vertex3 = 2;
- // Draw a shaded triangle.
- GradientFill( MemDC, vertex, 3, &gTriangle, 1, GRADIENT_FILL_TRIANGLE);
- }
- // draws the background for the part of the window between header and footer
- void drawBackground( HDC MemDC, RECT r )
- {
- /******************** main window's gradient background ***************/
- GradientTriangle( MemDC, r.right, r.bottom - r.top - 30, r.left, r.bottom - r.top - 30,
- r.left, r.top + 120, RGB( 0x95, 0xB3, 0xD7 ), RGB( 0xDB, 0xE5, 0xF1 ) );
- GradientTriangle( MemDC, r.right, r.bottom - r.top - 30, r.right, r.top + 120,
- r.left, r.top + 120, RGB( 0x95, 0xB3, 0xD7 ), RGB( 0xDB, 0xE5, 0xF1 ) );
- }
- // draws the header of the main window
- void drawHeader( HDC MemDC, RECT rect, HBRUSH hbPozadina )
- {
- FillRect( MemDC, &rect, hbPozadina );
- // draw grid on the banner background
- LOGBRUSH lbPozadina;
- HGDIOBJ hPenPozadina = NULL, hOldPenPozadina;
- lbPozadina.lbColor = RGB( 216, 216, 216 );
- lbPozadina.lbHatch = 0;
- lbPozadina.lbStyle = BS_SOLID;
- hPenPozadina = ExtCreatePen( PS_COSMETIC | PS_SOLID, 1, &lbPozadina, 0, NULL);
- hOldPenPozadina = SelectObject( MemDC, hPenPozadina); // needed for cleanup
- for( int i = rect.left + 12; i< rect.right; i += 12)
- {
- MoveToEx( MemDC, i, rect.top, NULL );
- LineTo( MemDC, i, rect.bottom - rect.top + 1 );
- }
- for( int i = rect.top + 12; i< rect.bottom; i += 12)
- {
- MoveToEx( MemDC, rect.left, i, NULL );
- LineTo( MemDC, rect.right - rect.left + 1, i );
- }
- // perform proper cleanup
- SelectObject( MemDC, hOldPenPozadina);
- DeleteObject(hPenPozadina);
- /********* draw a line at the bottom of the top banner ******/
- LOGBRUSH lb;
- HGDIOBJ hPen = NULL, hOldPen;
- lb.lbColor = RGB( 0, 0, 0 );
- lb.lbHatch = 0;
- lb.lbStyle = BS_SOLID;
- hPen = ExtCreatePen( PS_COSMETIC | PS_SOLID, 1, &lb, 0, NULL);
- hOldPen = SelectObject( MemDC, hPen ); // needed for proper cleanup
- MoveToEx( MemDC, rect.left, rect.top + 120, NULL );
- LineTo( MemDC, rect.right - rect.left + 1, rect.top + 120 );
- // perform proper cleanup
- SelectObject( MemDC, hOldPen );
- DeleteObject(hPen);
- }
- // fills rectangle with gradient brush
- void GradientRectangle( HDC MemDC, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF top,
- COLORREF bottom )
- {
- // vertexes for static's gradient color
- TRIVERTEX vertexS[2];
- vertexS[0].x = x1;
- vertexS[0].y = y1;
- vertexS[0].Red = GetRValue(top) << 8;
- vertexS[0].Green = GetGValue(top) << 8;
- vertexS[0].Blue = GetBValue(top) << 8;
- vertexS[0].Alpha = 0x0000;
- vertexS[1].x = x2;
- vertexS[1].y = y2;
- vertexS[1].Red = GetRValue(bottom) << 8;
- vertexS[1].Green = GetGValue(bottom) << 8;
- vertexS[1].Blue = GetBValue(bottom) << 8;
- vertexS[1].Alpha = 0x0000;
- // Create a GRADIENT_RECT structure that
- // references the TRIVERTEX vertices.
- GRADIENT_RECT gRect;
- gRect.UpperLeft = 0;
- gRect.LowerRight = 1;
- // Draw a shaded rectangle.
- GradientFill( MemDC, vertexS, 2, &gRect, 1, GRADIENT_FILL_RECT_V );
- }
- // fills the "button" with blue gradient and frames it with blue brush
- void FillButton( HDC MemDC, RECT rect, HBRUSH BlueFrame )
- {
- // fill upper half of the rectangle
- GradientRectangle( MemDC, rect.left, rect.top, rect.right,
- rect.top + ( rect.bottom - rect.top ) / 2,
- RGB( 0x95, 0xB3, 0xD7 ), RGB( 0x4F, 0x8B, 0xBD ) );
- // fill bottom half of the rectangle
- GradientRectangle( MemDC, rect.left, rect.top + ( rect.bottom - rect.top ) / 2,
- rect.right, rect.bottom, RGB( 0x4F, 0x8B, 0xBD ), RGB( 0x95, 0xB3, 0xD7 ) );
- FrameRect( MemDC, &rect, BlueFrame );
- }
- // draws the "status bar" at the bottom of the main window
- void drawFooter( HDC MemDC, RECT r, COLORREF top, COLORREF bottom )
- {
- // down triangle
- GradientTriangle( MemDC,
- r.right, r.bottom,
- ( r.right - r.left ) / 2,
- r.bottom - r.top - 15,
- r.left, r.bottom,
- top, bottom );
- // upper triangle
- GradientTriangle( MemDC,
- r.right, r.bottom - r.top - 30,
- ( r.right - r.left ) / 2, r.bottom - r.top - 15,
- r.left, r.bottom - r.top - 30,
- top, bottom );
- // left triangle
- GradientTriangle( MemDC,
- r.left, r.bottom,
- ( r.right - r.left ) / 2, r.bottom - r.top - 15,
- r.left, r.bottom - r.top - 30,
- top, bottom );
- // right triangle
- GradientTriangle( MemDC,
- r.right, r.bottom - r.top - 30,
- ( r.right - r.left ) / 2, r.bottom - r.top - 15,
- r.right, r.bottom,
- top, bottom );
- // draw icon
- DrawIconEx( MemDC, r.left, r.bottom - r.top - 30, hiAdmin, 30, 30, NULL, NULL, DI_NORMAL );
- }
- // draw orange panel on which map and 3 static controls will be drawn
- void drawOrangePanel( HDC MemDC, RECT r, COLORREF top, COLORREF bottom )
- {
- // down triangle
- GradientTriangle( MemDC,
- r.right, r.bottom,
- r.left + ( r.right - r.left ) / 2,
- r.top + ( r.bottom - r.top ) / 2,
- r.left, r.bottom,
- top, bottom );
- // upper triangle
- GradientTriangle( MemDC,
- r.right, r.top,
- r.left + ( r.right - r.left ) / 2,
- r.top + ( r.bottom - r.top ) / 2,
- r.left, r.top,
- top, bottom );
- // left triangle
- GradientTriangle( MemDC,
- r.left, r.bottom,
- r.left + ( r.right - r.left ) / 2,
- r.top + ( r.bottom - r.top ) / 2,
- r.left, r.top,
- top, bottom );
- // right triangle
- GradientTriangle( MemDC,
- r.right, r.top,
- r.left + ( r.right - r.left ) / 2, r.top + ( r.bottom - r.top ) / 2,
- r.right, r.bottom,
- top, bottom );
- }
- void drawStrings( HDC MemDC, RECT r )
- {
- // rectangle for header
- RECT rect, baner; // needed for proper positioning
- SIZE sBaner; // needed for proper positioning
- HFONT hf, hfOld;
- long lfHeight;
- rect.left = r.left;
- rect.top = r.top;
- rect.right = r.right;
- rect.bottom = 120;
- /************************ middle orange text ************************/
- // set font size below via function's first argument
- lfHeight = -MulDiv( 14, GetDeviceCaps( MemDC, LOGPIXELSY), 72 );
- hf = CreateFont( lfHeight, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, L"Arial Black" );
- SetBkMode( MemDC, TRANSPARENT );
- SetTextColor( MemDC, RGB( 255, 163, 94 ) ); // orange
- hfOld = (HFONT)SelectObject( MemDC, hf ); // needed for cleanup
- GetTextExtentPoint32( MemDC, L"ГЕОТЕРМАЛНИ ИНФОРМАЦИОНИ СИСТЕМ ГРАДА БЕОГРАДА-ГЕОТЕРМИСТ",
- wcslen(L"ГЕОТЕРМАЛНИ ИНФОРМАЦИОНИ СИСТЕМ ГРАДА БЕОГРАДА-ГЕОТЕРМИСТ"), &sBaner );
- // proper positioning
- baner.left = r.left + 60;
- baner.right = r.right - r.left - 60;
- baner.top = r.top + 15;
- baner.bottom = r.top + sBaner.cy;
- DrawTextEx( MemDC, L"ГЕОТЕРМАЛНИ ИНФОРМАЦИОНИ СИСТЕМ ГРАДА БЕОГРАДА-ГЕОТЕРМИСТ",
- wcslen(L"ГЕОТЕРМАЛНИ ИНФОРМАЦИОНИ СИСТЕМ ГРАДА БЕОГРАДА-ГЕОТЕРМИСТ"), &baner,
- DT_CENTER | DT_VCENTER | DT_NOCLIP | DT_WORDBREAK, 0 );
- SelectObject( MemDC, hfOld ); // proper cleanup
- DeleteObject( hf );
- /******************************* top left text ************************/
- //position it properly
- baner.left = r.left + 90;
- baner.top = r.top + sBaner.cy + 28;
- baner.right = 460;
- baner.bottom = r.bottom;
- lfHeight = -MulDiv( 8, GetDeviceCaps( MemDC, LOGPIXELSY), 72 );
- hf = CreateFont( lfHeight, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, L"Arial Black" );
- SetTextColor( MemDC, RGB( 0, 0, 0 ) );
- hfOld = (HFONT)SelectObject( MemDC, hf ); // needed for proper cleanup
- DrawTextEx( MemDC, L"УПРАВА ГРАДА БЕОГРАДА\nСЕКРЕТАРИЈАТ ЗА КОМУНАЛНЕ И СТАМБЕНЕ ПОСЛОВЕ\nУПРАВА ЗА ЕНЕРГЕТИКУ",
- wcslen(L"УПРАВА ГРАДА БЕОГРАДА\nСЕКРЕТАРИЈАТ ЗА КОМУНАЛНЕ И СТАМБЕНЕ ПОСЛОВЕ\nУПРАВА ЗА ЕНЕРГЕТИКУ"),
- &baner, DT_CENTER | DT_NOCLIP | DT_WORDBREAK, 0 );
- /*************************** top right text *************************/
- // position it properly
- baner.top = r.top + sBaner.cy + 28;
- baner.left = r.right - 350;
- baner.right = r.right - 100;
- baner.bottom = r.bottom;
- DrawTextEx( MemDC, L"УНИВЕРЗИТЕТ У БЕОГРАДУ\nРУДАРСКО ГЕОЛОШКИ ФАКУЛТЕТ\nДЕПАРТМАН ЗА ХИДРОГЕОЛОГИЈУ",
- wcslen(L"УНИВЕРЗИТЕТ У БЕОГРАДУ\nРУДАРСКО ГЕОЛОШКИ ФАКУЛТЕТ\nДЕПАРТМАН ЗА ХИДРОГЕОЛОГИЈУ"),
- &baner, DT_CENTER | DT_VCENTER | DT_NOCLIP | DT_WORDBREAK, 0 );
- SelectObject( MemDC, hfOld ); // proper cleanup
- DeleteObject( hf );
- //========= draw right text in status bar =============//
- lfHeight = -MulDiv( 8, GetDeviceCaps( MemDC, LOGPIXELSY), 72 );
- hf = CreateFont( lfHeight, 0, 0, 0, FW_BOLD, TRUE, 0, 0, 0, 0, 0, 0, 0, L"Arial Black" );
- hfOld = (HFONT)SelectObject( MemDC, hf ); // needed for proper cleanup
- GetTextExtentPoint32( MemDC, L"ЦЕНТАР ЗА ОБНОВЉИВЕ ВОДНЕ ЕНЕРГЕТСКЕ РЕСУРСЕ",
- wcslen(L"ЦЕНТАР ЗА ОБНОВЉИВЕ ВОДНЕ ЕНЕРГЕТСКЕ РЕСУРСЕ"), &sBaner );
- // position it properly
- rect.bottom = r.bottom;
- rect.right = r.left + sBaner.cx + 30;
- rect.left = r.left + 30;
- rect.top = r.bottom - r.top - 30;
- // draw it to the back buffer
- DrawTextEx( MemDC, L"РУДАРСКО ГЕОЛОШКИ ФАКУЛТЕТ\nЦЕНТАР ЗА ОБНОВЉИВЕ ВОДНЕ ЕНЕРГЕТСКЕ РЕСУРСЕ",
- wcslen(L"РУДАРСКО ГЕОЛОШКИ ФАКУЛТЕТ\nЦЕНТАР ЗА ОБНОВЉИВЕ ВОДНЕ ЕНЕРГЕТСКЕ РЕСУРСЕ"),
- &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP | DT_WORDBREAK, 0 );
- SelectObject( MemDC, hfOld ); // proper cleanup
- DeleteObject( hf );
- //============== right text in the status bar ==================//
- lfHeight = -MulDiv( 10, GetDeviceCaps( MemDC, LOGPIXELSY), 72 );
- hf = CreateFont( lfHeight, 0, 0, 0, FW_BOLD, TRUE, 0, 0, 0, 0, 0, 0, 0, L"Arial" );
- hfOld = (HFONT)SelectObject( MemDC, hf ); // needed for proper cleanup
- GetTextExtentPoint32( MemDC, L" Дејан Миленић & Ана Врањеш © 2013 сва права задржана",
- wcslen(L" Дејан Миленић & Ана Врањеш © 2013 сва права задржана"), &sBaner );
- // position it properly
- rect.bottom = r.bottom;
- rect.right = r.right - 10;
- rect.left = r.right - r.left - sBaner.cx - 10;
- rect.top = r.bottom - r.top - sBaner.cy;
- // draw it to the back buffer
- DrawTextEx( MemDC, L" Дејан Миленић & Ана Врањеш © 2013 сва права задржана",
- wcslen(L" Дејан Миленић & Ана Врањеш © 2013 сва права задржана"),
- &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP | DT_WORDBREAK | DT_NOPREFIX, 0 );
- // perform proper cleanup
- SelectObject( MemDC, hfOld );
- DeleteObject(hf);
- /****************** draw static control's background ******************/
- //=============== top left blue static control ================//
- //position it properly
- rect.left = ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 230 + ( r.bottom - r.top - 450 ) / 3;
- rect.right = 150 + ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 270 + ( r.bottom - r.top - 450 ) / 3;
- // draw text
- // set font size below via function's first argument
- lfHeight = -MulDiv( 8, GetDeviceCaps( MemDC, LOGPIXELSY ), 72);
- hf = CreateFont( lfHeight, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, L"Arial Black");
- hfOld = (HFONT)SelectObject( MemDC, hf );
- DrawTextEx( MemDC, L"УНОС ПОДАТАКА", wcslen(L"УНОС ПОДАТАКА"),
- &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_WORDBREAK, 0 );
- //================= top right blue static control =====================//
- //position it properly
- rect.left = 150 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 230 + ( r.bottom - r.top - 450 ) / 3;
- rect.right = 300 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 270 + ( r.bottom - r.top - 450 ) / 3;
- // draw text
- DrawTextEx( MemDC, L"ПРЕГЛЕД ПОДАТАКА", wcslen(L"ПРЕГЛЕД ПОДАТАКА"),
- &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_WORDBREAK, 0 );
- //================= bottom left blue static control =====================//
- //position it properly
- rect.left = ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 380 + 2 * ( r.bottom - r.top - 450 ) / 3;
- rect.right = 150 + ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 420 + 2 * ( r.bottom - r.top - 450 ) / 3;
- // draw text
- DrawTextEx( MemDC, L"ИЗВЕШТАЈ", wcslen(L"ИЗВЕШТАЈ"),
- &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_WORDBREAK, 0 );
- //================= bottom right blue static control =====================//
- //position it properly
- rect.left = 150 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 380 + 2 * ( r.bottom - r.top - 450 ) / 3;
- rect.right = 300 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 420 + 2 * ( r.bottom - r.top - 450 ) / 3;
- // draw text
- DrawTextEx( MemDC, L"ПРЕТРАГА", wcslen(L"ПРЕТРАГА"),
- &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_WORDBREAK, 0 );
- SelectObject( MemDC, hfOld );
- DeleteObject(hf);
- //================ text for orange static controls =============//
- // first one
- rect.left = 3 * ( r.right - r.left ) / 4 + 10;
- rect.top = r.top + 160;
- rect.right = r.right - r.top - 50;
- rect.bottom = r.top + 180;
- //============= draw text ======//
- lfHeight = -MulDiv( 10, GetDeviceCaps( MemDC, LOGPIXELSY ), 72);
- hf = CreateFont(lfHeight, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0,L"Arial Unicode MS");
- hfOld = (HFONT)SelectObject( MemDC, hf );
- DrawTextEx( MemDC, L"ИНФОРМАЦИЈЕ", wcslen(L"ИНФОРМАЦИЈЕ"), &rect,
- DT_VCENTER | DT_LEFT | DT_SINGLELINE, 0 );
- // second one
- rect.left = 3 * ( r.right - r.left ) / 4 + 10;
- rect.top = r.top + 200;
- rect.bottom = r.top + 220;
- //====== draw text ======//
- DrawTextEx( MemDC, L"ПОМОЋ", wcslen(L"ПОМОЋ"), &rect,
- DT_VCENTER | DT_LEFT | DT_SINGLELINE, 0 );
- // third one
- rect.left = 3 * ( r.right - r.left ) / 4 + 10;
- rect.top = r.top + 240;
- rect.bottom = r.top + 260;
- //====== draw text ======//
- DrawTextEx( MemDC, L"КОРИСНИ ЛИНКОВИ", wcslen(L"КОРИСНИ ЛИНКОВИ"), &rect,
- DT_VCENTER | DT_LEFT | DT_SINGLELINE, 0 );
- // font is no longer needed, so do cleanup
- SelectObject( MemDC, hfOld );
- DeleteObject(hf);
- }
- void drawImages( HDC hdc, HDC MemDC, RECT r )
- {
- HDC hdcMemImg = CreateCompatibleDC(hdc); // back buffer for bitmaps
- RECT rect = { 0, 0, 0, 0 }; // needed for proper positioning
- /******************* top middle logo ********************/
- BITMAP b;
- memset( &b, 0 , sizeof(BITMAP) );
- GetObject( bmpSimbol, sizeof(BITMAP), &b );
- // needed for proper cleanup
- // ( we select a bitmap from resource file )
- HBITMAP oldBmp = (HBITMAP)SelectObject( hdcMemImg, bmpSimbol );
- // draw bitmap to the back buffer
- TransparentBlt( MemDC, ( r.right - r.left - 64 ) / 2, r.top + 45, 64, 64,
- hdcMemImg, 0, 0, b.bmWidth, b.bmHeight, RGB( 0, 0, 0) );
- SelectObject( hdcMemImg, oldBmp ); // proper cleanup
- //=============== top left blue static control ================//
- //position it properly
- rect.left = ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 120 + ( r.bottom - r.top - 450 ) / 3;
- rect.right = 150 + ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 270 + ( r.bottom - r.top - 450 ) / 3;
- memset( &b, 0, sizeof(BITMAP) );
- GetObject( bmpBTN1, sizeof(BITMAP), &b );
- oldBmp = (HBITMAP)SelectObject( hdcMemImg, bmpBTN1 );
- // draw bitmap on back buffer
- TransparentBlt( MemDC, rect.left + 20, rect.top + 10, rect.right - rect.left - 30,
- rect.bottom - rect.top - 40,
- hdcMemImg, 0, 0, b.bmWidth, b.bmHeight, RGB( 0, 0, 0 ) );
- SelectObject( hdcMemImg, oldBmp );
- //================= top right blue static control =====================//
- //position it properly
- rect.left = 150 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 120 + ( r.bottom - r.top - 450 ) / 3;
- rect.right = 300 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 270 + ( r.bottom - r.top - 450 ) / 3;
- memset( &b, 0, sizeof(BITMAP) );
- GetObject( bmpBTN2, sizeof(BITMAP), &b );
- oldBmp = (HBITMAP)SelectObject( hdcMemImg, bmpBTN2 );
- // draw bitmap on back buffer
- TransparentBlt( MemDC, rect.left + 15, rect.top + 10, rect.right - rect.left - 30,
- rect.bottom - rect.top - 40, hdcMemImg, 0, 0, b.bmWidth, b.bmHeight, RGB( 255, 0, 255 ) );
- SelectObject( hdcMemImg, oldBmp );
- //================= bottom left blue static control =====================//
- //position it properly
- rect.left = ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 270 + 2 * ( r.bottom - r.top - 450 ) / 3;
- rect.right = 150 + ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 420 + 2 * ( r.bottom - r.top - 450 ) / 3;
- memset( &b, 0, sizeof(BITMAP) );
- GetObject( bmpBTN3, sizeof(BITMAP), &b );
- oldBmp = (HBITMAP)SelectObject( hdcMemImg, bmpBTN3 );
- // draw left bitmap on back buffer
- TransparentBlt( MemDC, rect.left + 5, rect.top + 20, ( rect.right - rect.left) / 2,
- rect.bottom - rect.top - 60, hdcMemImg, 0, 0, b.bmWidth, b.bmHeight, RGB( 0, 0, 0 ) );
- SelectObject( hdcMemImg, oldBmp );
- // draw right bitmap on back buffer
- memset( &b, 0 , sizeof(BITMAP) );
- GetObject( bmpBTN3a, sizeof(BITMAP), &b );
- oldBmp = (HBITMAP)SelectObject( hdcMemImg, bmpBTN3a );
- TransparentBlt( MemDC, rect.left + ( rect.right - rect.left) / 2 + 5, rect.top + 20,
- ( rect.right - rect.left) / 2 - 5, rect.bottom - rect.top - 60,
- hdcMemImg, 0, 0, b.bmWidth, b.bmHeight, RGB( 0, 0, 0 ) );
- SelectObject( hdcMemImg, oldBmp );
- //================= bottom right blue static control =====================//
- //position it properly
- rect.left = 150 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 270 + 2 * ( r.bottom - r.top - 450 ) / 3;
- rect.right = 300 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 420 + 2 * ( r.bottom - r.top - 450 ) / 3;
- memset( &b, 0, sizeof(BITMAP) );
- GetObject( bmpBTN4, sizeof(BITMAP), &b );
- oldBmp = (HBITMAP)SelectObject( hdcMemImg, bmpBTN4 );
- // draw bitmap on back buffer
- TransparentBlt( MemDC, rect.left + 25, rect.top + 10, rect.right - rect.left - 50,
- rect.bottom - rect.top - 40, hdcMemImg, 0, 0, b.bmWidth, b.bmHeight, RGB( 0, 0, 0 ) );
- SelectObject( hdcMemImg, oldBmp );
- //================= static controls on orange panel ==================//
- // first one
- rect.left = 3 * ( r.right - r.left ) / 4 - 30;
- rect.top = r.top + 150;
- rect.right = r.right - r.top - 50;
- rect.bottom = r.top + 180;
- //=============== draw bitmap =============//
- memset( &b, 0, sizeof(BITMAP) );
- GetObject( bmpInfo, sizeof(BITMAP), &b );
- oldBmp = (HBITMAP)SelectObject( hdcMemImg, bmpInfo );
- // draw bitmap on back buffer
- TransparentBlt( MemDC, rect.left, rect.top, 30, 30, hdcMemImg, 0, 0,
- b.bmWidth, b.bmHeight, RGB( 255, 163, 94 ) );
- SelectObject( hdcMemImg, oldBmp );
- // second one
- rect.left = 3 * ( r.right - r.left ) / 4 - 30;
- rect.top = r.top + 190;
- rect.bottom = r.top + 220;
- //=============== draw bitmap =============//
- memset( &b, 0, sizeof(BITMAP) );
- GetObject( bmpHelp, sizeof(BITMAP), &b );
- oldBmp = (HBITMAP)SelectObject( hdcMemImg, bmpHelp );
- // draw bitmap on back buffer
- TransparentBlt( MemDC, rect.left, rect.top, 30, 30, hdcMemImg, 0, 0,
- b.bmWidth, b.bmHeight, RGB( 255, 163, 94 ) );
- SelectObject( hdcMemImg, oldBmp );
- // third one
- rect.left = 3 * ( r.right - r.left ) / 4 - 30;
- rect.top = r.top + 230;
- rect.bottom = r.top + 260;
- //=============== draw bitmap =============//
- memset( &b, 0, sizeof(BITMAP) );
- GetObject( bmpLink, sizeof(BITMAP), &b );
- oldBmp = (HBITMAP)SelectObject( hdcMemImg, bmpLink );
- // draw bitmap on back buffer
- TransparentBlt( MemDC, rect.left, rect.top, 30, 30, hdcMemImg, 0, 0,
- b.bmWidth, b.bmHeight, RGB( 255, 163, 94 ) );
- SelectObject( hdcMemImg, oldBmp );
- //========= draw EMF and PNG files =========//
- {
- Graphics graphics( MemDC );
- /******* fourth orange static control with the map ( EMF file ) ********/
- // proper positioning
- rect.top = r.top + 270;
- rect.bottom = r.bottom - 60;
- rect.left = 3 * ( r.right - r.left ) / 4 - 30;
- //============= aspect ratio ================//
- UINT o_height = btn5->GetHeight(), o_width = btn5->GetWidth();
- float scale = 0.5;
- int mapPosX, mapPosY;
- scale = (float)( rect.right - rect.left ) / o_width;
- if( (float)( rect.bottom - rect.top ) / o_height < scale )
- scale = (float)( rect.bottom - rect.top ) / o_height;
- int marginX = ( rect.right - rect.left ) - (int)( o_width * scale );
- int marginY = ( rect.bottom - rect.top ) - (int)( o_height * scale );
- marginX /= 2;
- marginY /= 2;
- mapPosX = rect.left + marginX;
- mapPosY = rect.top + marginY;
- graphics.DrawImage( btn5, mapPosX, mapPosY, (int)( o_width * scale ),
- (int)( o_height * scale ) );
- /******************** top left logo ( PNG file ) *******************/
- o_height = image->GetHeight();
- o_width = image->GetWidth();
- graphics.DrawImage( image, r.left + 5, r.top + 10, o_width, o_height );
- /******************** top right logo ( PNG file ) *******************/
- o_height = image1->GetHeight();
- o_width = image1->GetWidth();
- graphics.DrawImage( image1, r.right - r.left - 90, r.top + 10, o_width, o_height );
- }
- DeleteDC(hdcMemImg); // release memory DC
- }
- void onPaint( HWND hwnd, WPARAM wParam, LPARAM lParam )
- {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint( hwnd, &ps);
- RECT r; // rectangle for main window's client area
- GetClientRect( hwnd, &r);
- HDC MemDC = CreateCompatibleDC(hdc); // back buffer
- // compatible bitmap for MemDC
- HBITMAP bmp = CreateCompatibleBitmap( hdc, r.right - r.left, r.bottom - r.top ),
- oldBmp = (HBITMAP)SelectObject( MemDC, bmp ); // needed for cleanup
- /*************** draw banner ******************/
- // position it properly at the top
- RECT rect;
- rect.left = r.left;
- rect.top = r.top;
- rect.right = r.right;
- rect.bottom = 120;
- // draw background for middle part of the window
- drawBackground( MemDC, r );
- // draw header with grid lines
- drawHeader( MemDC, rect, hbPozadina );
- // draw "status bar"
- drawFooter( MemDC, r, RGB( 0x48, 0xAC, 0xC6), RGB( 0x31, 0x83, 0x99 ) );
- /****************** draw static control's background ******************/
- //=============== top left static control ================//
- //position it properly
- rect.left = ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 120 + ( r.bottom - r.top - 450 ) / 3;
- rect.right = 150 + ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 270 + ( r.bottom - r.top - 450 ) / 3;
- // draw gradient button
- FillButton( MemDC, rect, BlueFrame );
- //================= top right static control =====================//
- //position it properly
- rect.left = 150 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 120 + ( r.bottom - r.top - 450 ) / 3;
- rect.right = 300 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 270 + ( r.bottom - r.top - 450 ) / 3;
- // draw gradient button
- FillButton( MemDC, rect, BlueFrame );
- //================= bottom left static control =====================//
- //position it properly
- rect.left = ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 270 + 2 * ( r.bottom - r.top - 450 ) / 3;
- rect.right = 150 + ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 420 + 2 * ( r.bottom - r.top - 450 ) / 3;
- // draw gradient button
- FillButton( MemDC, rect, BlueFrame );
- //================= bottom right static control =====================//
- //position it properly
- rect.left = 150 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.top = 270 + 2 * ( r.bottom - r.top - 450 ) / 3;
- rect.right = 300 + 2 * ( 3 * ( r.right - r.left ) / 4 - 340 ) / 3;
- rect.bottom = 420 + 2 * ( r.bottom - r.top - 450 ) / 3;
- // draw gradient button
- FillButton( MemDC, rect, BlueFrame );
- //======================== draw orange panel =================//
- //position it properly
- rect.left = 3 * ( r.right - r.left ) / 4 - 40;
- rect.top = r.top + 140;
- rect.right = rect.left + ( r.right - r.left ) / 4;
- rect.bottom = rect.top + ( r.bottom - r.top - 190 );
- drawOrangePanel( MemDC, rect, RGB( 0xFF, 0xC8, 0xAA ), RGB( 0xFF, 0x96, 0x48 ) );
- // draw all the text
- drawStrings( MemDC, r );
- // draw all the bitmaps and EMF files
- drawImages( hdc, MemDC, r );
- /****************** draw back buffer on the screen DC *****************/
- BitBlt( hdc, 0, 0, r.right - r.left, r.bottom - r.top, MemDC, 0, 0, SRCCOPY );
- /************** cleanup *******************/
- SelectObject( MemDC, oldBmp );
- DeleteObject(bmp); // compatible bitmap for MemDC
- DeleteDC(MemDC);
- EndPaint( hwnd, &ps);
- }
- // WinMain's procedure
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch(msg)
- {
- case WM_CREATE:
- {
- image = Image::FromFile(L".\\resources\\BG.png"), // upper left logo
- image1 = Image::FromFile(L".\\resources\\RGF.png"); // upper right logo
- btn5 = Image::FromFile(L".\\resources\\BTN5.emf"); // map in the bottom of the orange button
- // load gray background brush for the top banner
- hbPozadina = CreateSolidBrush( RGB( 230, 230, 230 ) );
- // load left icon in the status bar
- hiAdmin = LoadIcon( hInst, MAKEINTRESOURCE(IDI_ICON2) );
- // bitmaps for static controls
- bmpBTN1 = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP1) );
- bmpBTN2 = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP10) );
- /** these two bitmaps make one image for the bottom right blue static control **/
- bmpBTN3 = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP3) );
- bmpBTN3a = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP5) );
- //**********************************************************************//
- bmpBTN4 = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP4) );
- bmpSimbol = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP16) );
- bmpInfo = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP6) );
- bmpLink = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP7) );
- bmpHelp = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP8) );
- //******** brushes ***********//
- // brush for orange panel that holds 3 static controls and a map
- hbr = CreateSolidBrush( RGB( 255, 163, 94 ) );
- // blue frame for blue static controls
- BlueFrame = CreateSolidBrush( RGB(79, 129, 189) );
- /*******************************************/
- // get rectangle dimensions of the main window
- RECT rec;
- GetClientRect( hwnd, &rec );
- /******* main window's static controls ******/
- // top left
- HWND hsUnosPodataka = CreateWindowEx( 0, L"Static",
- L"", WS_VISIBLE | WS_CHILD | SS_NOTIFY,
- ( 3 * ( rec.right - rec.left ) / 4 - 340 ) / 3,
- 120 + ( rec.bottom - rec.top - 450 ) / 3,
- 150, 150, hwnd, (HMENU)4000, hInst, 0);
- // top right
- HWND hsPregledPodataka = CreateWindowEx( 0, L"Static", L"",
- WS_VISIBLE | WS_CHILD | SS_NOTIFY,
- 150 + 2 * ( 3 * ( rec.right - rec.left ) / 4 - 340 ) / 3,
- 120 + ( rec.bottom - rec.top - 450 ) / 3,
- 150, 150, hwnd, (HMENU)4001, hInst, 0);
- // bottom left
- HWND hsIzvestaj = CreateWindowEx(0, L"Static", L"",
- WS_VISIBLE | WS_CHILD | SS_NOTIFY,
- ( 3 * ( rec.right - rec.left ) / 4 - 340 ) / 3,
- 270 + 2 * ( rec.bottom - rec.top - 450 ) / 3,
- 150, 150, hwnd, (HMENU)4002, hInst, 0);
- // bottom right
- HWND hsPretraga = CreateWindowEx(0, L"Static", L"",
- WS_VISIBLE | WS_CHILD | SS_NOTIFY,
- 150 + 2 * ( 3 * ( rec.right - rec.left ) / 4 - 340 ) / 3,
- 270 + 2 * ( rec.bottom - rec.top - 450 ) / 3,
- 150, 150, hwnd, (HMENU)4003, hInst, 0);
- //============= static controls on the orange panel ==============//
- // first one from the top
- HWND hsInfoInfo = CreateWindowEx(0, L"Static",
- L"", WS_VISIBLE | WS_CHILD | SS_NOTIFY,
- 3 * ( rec.right - rec.left ) / 4 - 30, rec.top + 150,
- ( rec.right - rec.left ) / 4 - 20, 30, hwnd, (HMENU)4007, hInst, 0);
- // second one from the top
- HWND hsInfoHelp = CreateWindowEx(0, L"Static",
- L"", WS_VISIBLE | WS_CHILD | SS_NOTIFY,
- 3 * ( rec.right - rec.left ) / 4 - 30, rec.top + 190,
- ( rec.right - rec.left ) / 4 - 20, 30, hwnd, (HMENU)4009, hInst, 0);
- // third one from the top
- HWND hsInfoLink = CreateWindowEx(0, L"Static",
- L"", WS_VISIBLE | WS_CHILD | SS_NOTIFY,
- 3 * ( rec.right - rec.left ) / 4 - 30, rec.top + 230,
- ( rec.right - rec.left ) / 4 - 20, 30, hwnd, (HMENU)4008, hInst, 0);
- // fourth one-it will contain a map
- HWND hsInfoKarta = CreateWindowEx(0, L"Static",
- L"", WS_VISIBLE | WS_CHILD | SS_NOTIFY,
- 3 * ( rec.right - rec.left ) / 4 - 30, rec.top + 270,
- ( rec.right - rec.left ) / 4 - 20, rec.bottom - rec.top - 330,
- hwnd, (HMENU)4010, hInst, 0);
- }
- return (LRESULT)0;
- case WM_COMMAND:
- // just beep when user clicks on static control
- switch( LOWORD(wParam) )
- {
- case 4000:
- case 4001:
- case 4002:
- case 4003:
- case 4007:
- case 4008:
- case 4009:
- case 4010:
- MessageBeep(MB_ICONEXCLAMATION);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- break;
- case WM_ERASEBKGND:
- return (LRESULT)1; // so we avoid flicker ( all painting is in WM_PAINT )
- case WM_PAINT:
- {
- // paint the picture
- onPaint( hwnd, wParam, lParam );
- }
- return (LRESULT)0;
- case WM_SIZE:
- {
- RECT rec;
- GetClientRect( hwnd, &rec );
- SetWindowPos( GetDlgItem( hwnd, 4000 ), NULL, ( 3 * ( rec.right - rec.left ) / 4 - 340 ) / 3,
- 120 + ( rec.bottom - rec.top - 450 ) / 3, 150, 150,
- SWP_NOZORDER | SWP_NOCOPYBITS );
- SetWindowPos( GetDlgItem( hwnd, 4001 ), NULL, 150 + 2 * ( 3 * ( rec.right - rec.left ) / 4 - 340 ) / 3,
- 120 + ( rec.bottom - rec.top - 450 ) / 3,
- 150, 150, SWP_NOZORDER | SWP_NOCOPYBITS);
- SetWindowPos( GetDlgItem( hwnd, 4002 ), NULL, ( 3 * ( rec.right - rec.left ) / 4 - 340 ) / 3,
- 270 + 2 * ( rec.bottom - rec.top - 450 ) / 3,
- 150, 150, SWP_NOZORDER | SWP_NOCOPYBITS );
- SetWindowPos( GetDlgItem( hwnd, 4003 ), NULL, 150 + 2 * ( 3 * ( rec.right - rec.left ) / 4 - 340 ) / 3,
- 270 + 2 * ( rec.bottom - rec.top - 450 ) / 3,
- 150, 150, SWP_NOZORDER | SWP_NOCOPYBITS );
- SetWindowPos( GetDlgItem( hwnd, 4007 ), NULL, 3 * ( rec.right - rec.left ) / 4 - 30, rec.top + 150,
- ( rec.right - rec.left ) / 4 - 20, 30, SWP_NOZORDER | SWP_NOCOPYBITS );
- SetWindowPos( GetDlgItem( hwnd, 4008 ), NULL, 3 * ( rec.right - rec.left ) / 4 - 30, rec.top + 190,
- ( rec.right - rec.left ) / 4 - 20, 30, SWP_NOZORDER | SWP_NOCOPYBITS );
- SetWindowPos( GetDlgItem( hwnd, 4009 ), NULL, 3 * ( rec.right - rec.left ) / 4 - 30, rec.top + 230,
- ( rec.right - rec.left ) / 4 - 20, 30, SWP_NOZORDER | SWP_NOCOPYBITS );
- SetWindowPos( GetDlgItem( hwnd, 4010 ), NULL, 3 * ( rec.right - rec.left ) / 4 - 30, rec.top + 270,
- ( rec.right - rec.left ) / 4 - 20, rec.bottom - rec.top - 330,
- SWP_NOZORDER | SWP_NOCOPYBITS );
- InvalidateRect( hwnd, NULL, FALSE );
- }
- return (LRESULT)0;
- case WM_CTLCOLORSTATIC:
- return (LRESULT)( (HBRUSH)GetStockObject(NULL_BRUSH) );
- case WM_CLOSE:
- // destroy bitmaps
- DeleteObject(bmpSimbol);
- DeleteObject(bmpBTN1);
- DeleteObject(bmpBTN2);
- DeleteObject(bmpBTN3);
- DeleteObject(bmpBTN4);
- DeleteObject(bmpInfo);
- DeleteObject(bmpLink);
- DeleteObject(bmpHelp);
- // destroy icons
- DestroyIcon(hIcon);
- DestroyIcon(hiAdmin);
- // destroy brushes
- DeleteObject(hbPozadina);
- DeleteObject(hbr);
- DeleteObject(BlueFrame);
- // delete Image objects
- delete image;
- delete image1;
- delete btn5;
- DestroyWindow(hwnd);
- return (LRESULT)0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return (LRESULT)0;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- // WinMain
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
- int nCmdShow)
- {
- // store hInstance in global variable for later use
- hInst = hInstance;
- // load main icon
- hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_ICON1));
- WNDCLASSEX wc;
- HWND hwnd;
- MSG Msg;
- /*********** variables for GDI+ initialization *****************/
- GdiplusStartupInput gdiplusStartupInput;
- ULONG_PTR gdiplusToken;
- /************** Initialize GDI+. *************************/
- GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
- /*************** finished GDI+ initialisation ********************/
- // initialize common controls
- INITCOMMONCONTROLSEX iccex;
- iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
- iccex.dwICC = ICC_STANDARD_CLASSES ;
- InitCommonControlsEx(&iccex);
- // register main window class
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInst;
- wc.hIcon = hIcon;
- wc.hCursor = LoadCursor( NULL, IDC_ARROW );
- wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
- wc.lpszMenuName = NULL;
- wc.lpszClassName = L"Main_Window";
- wc.hIconSm = hIcon;
- if(!RegisterClassEx(&wc))
- {
- MessageBox(NULL, L"Window Registration Failed!", L"Error!", MB_ICONEXCLAMATION |
- MB_OK);
- return 0;
- }
- // create main window
- hwnd = CreateWindowEx( 0, // WS_EX_COMPOSITED "improved" drawing of the edges
- L"Main_Window",
- L"Геотермист",
- WS_OVERLAPPEDWINDOW,
- ( GetSystemMetrics(SM_CXMAXIMIZED) - 1020 ) / 2,
- ( GetSystemMetrics(SM_CYMAXIMIZED) - 600 ) / 2,
- 1020, 600, NULL, NULL, hInstance, 0 );
- if(hwnd == NULL)
- {
- MessageBox(NULL, L"Window creation failed!", L"Error!", MB_ICONEXCLAMATION |
- MB_OK);
- return 0;
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while(GetMessage(&Msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- // shutdownd GDI+
- GdiplusShutdown(gdiplusToken);
- return Msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement