Advertisement
rhouland

Text Out custom Color Font Size & Transparent

May 15th, 2018
1,361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <sstream>
  3. #include <windows.h>
  4.  
  5. // Copyright rhouland@epastas.lt  &  evgeniistorozhev@mail.ru
  6.  
  7. HFONT hFont = CreateFont (43, 0, 0, 0, 700, FALSE, FALSE, FALSE, BALTIC_CHARSET,
  8. OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  9. DEFAULT_PITCH | FF_DONTCARE, TEXT("Comic Sans MS"));
  10.  
  11. // HFONT CreateFont(
  12.   //_In_ int     nHeight, AUKÐTIS
  13.   //_In_ int     nWidth,   PLOTIS
  14.   //_In_ int     nEscapement, PASVIRIMAS
  15.   //_In_ int     nOrientation,
  16.   //_In_ int     fnWeight, STORIS FW_BOLD, = 700 NUO 1 IKI  900
  17.   //_In_ DWORD   fdwItalic,
  18.   //_In_ DWORD   fdwUnderline,
  19.   //_In_ DWORD   fdwStrikeOut,
  20.   //_In_ DWORD   fdwCharSet,
  21.   //_In_ DWORD   fdwOutputPrecision,
  22.   //_In_ DWORD   fdwClipPrecision,
  23.   //_In_ DWORD   fdwQuality,
  24.   //_In_ DWORD   fdwPitchAndFamily,
  25.   //_In_ LPCTSTR lpszFace
  26.  
  27. LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
  28.     static HBITMAP hImageBitmap;
  29.     static HBITMAP hImageOldBitmap;
  30.     static HDC hImageDC;
  31.     static BITMAP bm;
  32.     static HWND HWNDStatic;
  33.          
  34.     switch(Message) {
  35.        
  36.         case WM_DESTROY: {
  37.             if (hImageBitmap)
  38.             {
  39.                 DeleteObject (SelectObject (hImageDC, hImageOldBitmap));
  40.                 DeleteDC (hImageDC);
  41.             }
  42.             PostQuitMessage(0);
  43.             break;
  44.         }
  45.        
  46.         case WM_CREATE: {
  47.  
  48.     HWNDStatic = CreateWindow(TEXT("STATIC"),TEXT(" ÐEÐKAS Á JÛRÀ ÞIÛRËJO "),
  49.     WS_VISIBLE | WS_CHILD | SS_CENTER | SS_CENTERIMAGE,
  50.     50,70,460,75,hwnd,(HMENU)1,NULL,NULL);
  51.     SendMessage (HWNDStatic, WM_SETFONT, WPARAM (hFont), TRUE);
  52.    
  53. hImageBitmap = (HBITMAP) LoadImage (NULL, "1.bmp", 0, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
  54.             if (hImageBitmap)
  55.             {
  56. GetObject (hImageBitmap, sizeof (BITMAP), &bm);
  57. HDC hDC = GetDC (hwnd);
  58. hImageDC = CreateCompatibleDC (hDC);
  59. hImageOldBitmap = (HBITMAP) SelectObject (hImageDC, hImageBitmap);
  60. ReleaseDC (hwnd, hDC);
  61.             }
  62.             break;
  63.         }
  64.        
  65.     case WM_CTLCOLORSTATIC:
  66.     {  
  67.     if((HWND)lParam == HWNDStatic)
  68.     {  
  69.     //SetBkColor((HDC)wParam, RGB(255,0,255));
  70.     SetTextColor((HDC)wParam, RGB(0, 255, 0));    
  71.     SetBkMode((HDC)wParam, TRANSPARENT);
  72.     return (INT_PTR)GetStockObject(NULL_BRUSH);
  73.     }
  74.     break;
  75. }
  76.        
  77.        
  78.         case WM_PAINT: {
  79.             PAINTSTRUCT ps;
  80.             HDC hDC = BeginPaint (hwnd, &ps);
  81.            
  82.             if (hImageBitmap)
  83. BitBlt (hDC, 0, 0, bm.bmWidth, bm.bmHeight, hImageDC, 0, 0, SRCCOPY);
  84.             EndPaint (hwnd, &ps);
  85.             break;
  86.         }
  87.        
  88.     default:
  89.             return DefWindowProc(hwnd, Message, wParam, lParam);
  90.     }
  91.     return 0;
  92. }
  93.  
  94. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  95.     WNDCLASSEX wc;
  96.     HWND hwnd;
  97.     MSG msg;
  98. setlocale(LC_ALL, "Lithuanian");
  99.  
  100.     memset(&wc,0,sizeof(wc));
  101.     wc.cbSize        = sizeof(WNDCLASSEX);
  102.     wc.lpfnWndProc   = WndProc;
  103.     wc.hInstance     = hInstance;
  104.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  105.    
  106.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  107.     wc.lpszClassName = "WindowClass";
  108.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  109.     wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  110.  
  111.     if(!RegisterClassEx(&wc)) {
  112.         MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  113.         return 0;
  114.     }
  115.  
  116.     hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass",
  117.     "Tekstas, permatomas, spalva. ðriftas",
  118.     WS_VISIBLE | WS_SYSMENU,
  119.     GetSystemMetrics(SM_CXSCREEN)/2-335,
  120.     GetSystemMetrics(SM_CYSCREEN)/2-233,
  121.     669,466,NULL,NULL,hInstance,NULL);
  122.  
  123.     if(hwnd == NULL) {
  124.         MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  125.         return 0;
  126.     }
  127.  
  128.     while(GetMessage(&msg, NULL, 0, 0) > 0) {
  129.         TranslateMessage(&msg);
  130.         DispatchMessage(&msg);
  131.     }
  132.     return msg.wParam;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement