Advertisement
rhouland

WinApi static text transparent working

May 15th, 2018
1,495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //#include <fstream>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <windows.h>
  5. //#include <cstdio>
  6. //#include <string>
  7. //#include <cstring>
  8. //#include <tchar.h>
  9. //#include <stdlib.h>
  10. #include <conio.h>
  11. #include <stdio.h>
  12.  
  13. HFONT hFont = CreateFont (33, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
  14. OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  15. DEFAULT_PITCH | FF_DONTCARE, TEXT("Tahoma"));
  16.  
  17. LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
  18.     static HBITMAP hImageBitmap;
  19.     static HBITMAP hImageOldBitmap;
  20.     static HDC hImageDC;
  21.     static BITMAP bm;
  22.     static HWND HWNDStatic;
  23.          
  24.     switch(Message) {
  25.        
  26.         case WM_DESTROY: {
  27.             if (hImageBitmap)
  28.             {
  29.                 DeleteObject (SelectObject (hImageDC, hImageOldBitmap));
  30.                 DeleteDC (hImageDC);
  31.             }
  32.             PostQuitMessage(0);
  33.             break;
  34.         }
  35.        
  36.         case WM_CREATE: {
  37.  
  38.     HWNDStatic = CreateWindow(TEXT("STATIC"),TEXT(" NEED a BIG TEXT! "),
  39.     WS_VISIBLE | WS_CHILD | SS_CENTER | SS_CENTERIMAGE,
  40.     20,30,260,35,hwnd,(HMENU)1,NULL,NULL);
  41.    
  42. hImageBitmap = (HBITMAP) LoadImage (NULL, "1.bmp", 0, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
  43.             if (hImageBitmap)
  44.             {
  45. GetObject (hImageBitmap, sizeof (BITMAP), &bm);
  46. HDC hDC = GetDC (hwnd);
  47. hImageDC = CreateCompatibleDC (hDC);
  48. hImageOldBitmap = (HBITMAP) SelectObject (hImageDC, hImageBitmap);
  49. ReleaseDC (hwnd, hDC);
  50.             }
  51.             break;
  52.         }
  53.        
  54.     case WM_CTLCOLORSTATIC:
  55.     {  
  56.     if((HWND)lParam == HWNDStatic)
  57.     {  
  58.     //SetBkColor((HDC)wParam, RGB(255,0,255));
  59.     SetTextColor((HDC)wParam, RGB(0, 255, 0));    
  60.     SetBkMode((HDC)wParam, TRANSPARENT);
  61.  
  62.     return (INT_PTR)GetStockObject(NULL_BRUSH);
  63.     }
  64.     break;
  65. }
  66.        
  67.        
  68.         case WM_PAINT: {
  69.             PAINTSTRUCT ps;
  70.             HDC hDC = BeginPaint (hwnd, &ps);
  71.            
  72.             if (hImageBitmap)
  73. BitBlt (hDC, 0, 0, bm.bmWidth, bm.bmHeight, hImageDC, 0, 0, SRCCOPY);
  74.             EndPaint (hwnd, &ps);
  75.             break;
  76.         }
  77.        
  78.     default:
  79.             return DefWindowProc(hwnd, Message, wParam, lParam);
  80.     }
  81.     return 0;
  82. }
  83.  
  84. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  85.     WNDCLASSEX wc;
  86.     HWND hwnd;
  87.     MSG msg;
  88. setlocale(LC_ALL, "Lithuanian");
  89.  
  90.     memset(&wc,0,sizeof(wc));
  91.     wc.cbSize        = sizeof(WNDCLASSEX);
  92.     wc.lpfnWndProc   = WndProc;
  93.     wc.hInstance     = hInstance;
  94.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  95.    
  96.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  97.     wc.lpszClassName = "WindowClass";
  98.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  99.     wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  100.  
  101.     if(!RegisterClassEx(&wc)) {
  102.         MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  103.         return 0;
  104.     }
  105.  
  106.     hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass",
  107.     "Tekstas, permatomas, spalva. рriftas",
  108.     WS_VISIBLE | WS_SYSMENU,
  109.     GetSystemMetrics(SM_CXSCREEN)/2-335,
  110.     GetSystemMetrics(SM_CYSCREEN)/2-233,
  111.     669,466,NULL,NULL,hInstance,NULL);
  112.  
  113.     if(hwnd == NULL) {
  114.         MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  115.         return 0;
  116.     }
  117.  
  118.     while(GetMessage(&msg, NULL, 0, 0) > 0) {
  119.         TranslateMessage(&msg);
  120.         DispatchMessage(&msg);
  121.     }
  122.     return msg.wParam;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement