Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // nur für Win 2000 und später kompilieren
- #define WINVER 0x0500
- #include <windows.h>
- #include "main.h"
- //using namespace std;
- int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) {
- HWND hwnd; // Main-Window handle
- MSG messages; /* Here messages to the application are saved */
- WNDCLASSEX wincl; /* Data structure for the windowclass */
- Init();
- /* The Window structure */
- wincl.hInstance = hThisInstance;
- wincl.lpszClassName = szClassName;
- wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
- wincl.style = CS_DBLCLKS; /* Catch double-clicks */
- wincl.cbSize = sizeof (WNDCLASSEX);
- /* Use default icon and mouse-pointer */
- wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
- wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
- wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
- wincl.lpszMenuName = NULL; /* No menu */
- wincl.cbClsExtra = 0; /* No extra bytes after the window class */
- wincl.cbWndExtra = 0; /* structure or the window instance */
- /* Use Windows's default color as the background of the window */
- wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
- /* Register the window class, and if it fails quit the program */
- if (!RegisterClassEx (&wincl))
- return 0;
- hwnd = CreateWindowEx( // siehe http://msdn.microsoft.com/en-us/library/ms632680(v=vs.85).aspx
- 0,
- szClassName,
- "Test...", // Titel
- WS_SYSMENU|WS_POPUP, // Window-Long / Style
- 50, // position x (default: CW_USEDEFAULT)
- 200, // position y (default: CW_USEDEFAULT)
- WINDOW_WIDTH, // Breite
- WINDOW_HEIGHT, // Höhe
- HWND_DESKTOP, // Kind vom Desktop
- NULL, // Kein Menü
- hThisInstance, // Program Instance handler
- NULL
- );
- // Long des Fensters auf LAYER setzen, damit es transparent werden kann (WS_EX_TRANSPARENT macht das Fenster komplett transparent)
- SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
- // Alpha-Wert des Fensters setzen
- //SetLayeredWindowAttributes(hwnd, 0, (255 * 70) / 100, LWA_ALPHA);
- // Nur bestimmten Ausschnitt zeigen
- //SetWindowRgn(hwnd, CreateRectRgn(10,20,200,60), false);
- ShowWindow(hwnd, nFunsterStil); // Fenster sichtbar machen
- // Message-Loop (läuft solange wie GestMessage != 0 ist)
- while (GetMessage (&messages, NULL, 0, 0)) {
- TranslateMessage(&messages); // virtual-key messagse to character messages
- DispatchMessage(&messages); // Event behandeln
- }
- return messages.wParam;
- }
- void Init() {
- col = RGB(128,0,0);
- ColorRect.left = 10;
- ColorRect.top = 120;
- ColorRect.right = 290;
- ColorRect.bottom = 160;
- }
- LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- if (message == WM_PAINT) {
- PAINTSTRUCT ps;
- brush = CreateSolidBrush(col);
- HDC dc;
- dc = NULL;
- dc = BeginPaint(hwnd, &ps);
- SelectObject(dc, brush);
- FillRect(dc, &ColorRect, brush);
- EndPaint(hwnd, &ps);
- } else if (message == WM_DESTROY) {
- DeleteObject(brush);
- PostQuitMessage(0); // WM_QUIT zur message queue senden
- } else {
- return DefWindowProc(hwnd, message, wParam, lParam); // die message weitersenden damit evtl. andere Programme die message handeln können
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement