All pastes #393965 Raw Edit

sapero

public cpp v1 · immutable
·published 2007-03-13 23:15 UTC
rendered paste body
#include <windows.h>#include <commctrl.h>LRESULT __stdcall WindowProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);HBRUSH CreateTransparentBrush(HWND hwndParent, HWND hwndStatic);BOOL __stdcall KillBrush(HWND hwnd, LPARAM lParam);int main(){	HINSTANCE _hInstance = GetModuleHandle(0);	WNDCLASSEX winClass; 	MSG        uMsg;    ZeroMemory(&winClass, sizeof(WNDCLASSEX));    	winClass.lpszClassName = "MY_WINDOWS_CLASS";	winClass.cbSize        = sizeof(WNDCLASSEX);	winClass.lpfnWndProc   = (WNDPROC)WindowProc;	winClass.hInstance     = _hInstance;	winClass.hIcon	       = LoadIcon(0, IDI_APPLICATION);	winClass.hCursor       = LoadCursor(NULL, IDC_ARROW);	// bitmapa 1024*1 zrobiona z samej góry twojego screena (obszar klienta)	HBITMAP bm = (HBITMAP)LoadImage(0, "c:\\brush.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);	winClass.hbrBackground = CreatePatternBrush(bm);	RegisterClassEx(&winClass);	DeleteObject(bm);	HWND hwnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", "Transparent Trackbar", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 200, 200, 830, 70, NULL, NULL, _hInstance, NULL );    UpdateWindow( hwnd );	HWND hwnd2 = CreateWindowEx( NULL, TRACKBAR_CLASS, NULL, WS_CHILD | WS_VISIBLE,  10, 10, 380, 30, hwnd, (HMENU)1005, _hInstance, NULL );	HWND hwnd3 = CreateWindowEx( NULL, TRACKBAR_CLASS, NULL, WS_CHILD | WS_VISIBLE, 390, 10, 380, 30, hwnd, (HMENU)1000, _hInstance, NULL );	while (GetMessage(&uMsg,0,0,0))	{		TranslateMessage( &uMsg );		DispatchMessage( &uMsg );	}    return UnregisterClass( "MY_WINDOWS_CLASS", _hInstance );}LRESULT __stdcall WindowProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){	LRESULT result = 0;	switch( msg )	{		case WM_CLOSE:			EnumChildWindows(hwnd, KillBrush, 0);			DestroyWindow(hwnd);			PostQuitMessage(0);			break;		case WM_CTLCOLORSTATIC:			result = (LRESULT)CreateTransparentBrush(hwnd, (HWND)lParam);			break;		default:			result = DefWindowProc( hwnd, msg, wParam, lParam );	}	return result;}// stwórz bitmap&#281; o wielko&#347;ci hwndStatic.szeroko&#347;&#263; * 1// skopiuj do niej obraz okna hwndParent o 1 pixel wy&#380;ej ni&#380; hwndStatic// zrób brush z bitmapyHBRUSH CreateTransparentBrush(HWND hwndParent, HWND hwndStatic){	HBRUSH hbr = (HBRUSH)GetProp(hwndStatic, "BRUSH");	if (!hbr)	{		RECT rc;		GetWindowRect(hwndStatic, &rc);		ScreenToClient(hwndParent, (POINT*)&rc);		HDC dcParent = GetDC(hwndParent);		int w = rc.right - rc.left;		HDC dcMemory = CreateCompatibleDC(dcParent);		HBITMAP hbm = (HBITMAP)SelectObject(dcMemory, (HGDIOBJ)CreateCompatibleBitmap(dcParent, w, 1));		BitBlt(dcMemory, 0,0,w,2, dcParent, rc.left, rc.top-1, SRCCOPY);		hbm = (HBITMAP)SelectObject(dcMemory, hbm);		ReleaseDC(hwndParent, dcParent);		DeleteDC(dcMemory);		hbr = CreatePatternBrush(hbm);		SetProp(hwndStatic, "BRUSH", (HANDLE)hbr);	}	return hbr;}BOOL __stdcall KillBrush(HWND hwnd, LPARAM lParam){	HBRUSH hbr = (HBRUSH)GetProp(hwnd, "BRUSH");	if (hbr) DeleteObject(hbr);	return true;}