Hilfe bei WinApi Strechblt() friert immer ein!



  • Ich versuche es mal zu komprimieren!

    #include <windows.h>
    #include <windows.h>
    #include <stdio.h>
    #include <iostream> 
    #include <fstream>
    #include <string>
    #include <cstdio>
    #include "res.h"
    
    //process the window messages
    LRESULT CALLBACK windowProc(HWND, UINT, WPARAM, LPARAM);
    //extract RGB values from COLORREF
    
    void toRGB(COLORREF color, unsigned char *rgb);
    unsigned int iLupeFaktor= 1; 
    
    //timer id
    unsigned int timer = 1;
    //interval in ms to get the color
    unsigned int interval = 1;
    //color of the pixel under mouse pointer
    //colorref has form: 0x00bbggrr
    COLORREF SetTextColor(HDC hdc, COLORREF crColor);
    COLORREF pixelColor = 0;
    COLORREF pixelColorLast = 0;
    //color rectangle for visualization
    
    RECT colorRect;
    RECT colorRect1;
    HFONT font;
    //main function
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        LPSTR lpCmdLine, int nCmdShow)
    {
       //program and class name
        const char *progName = "Colorcatcher ;)";
    
        //create window class
        WNDCLASS windowClass;
    
        //message function
        windowClass.lpfnWndProc = windowProc;
        //enable redrawing
        windowClass.style       = CS_HREDRAW | CS_VREDRAW;
        //program instance
        windowClass.hInstance   = hInstance;
        //standard cursor
        windowClass.hCursor     = LoadCursor(NULL, IDC_CROSS);
        //standard icon
         windowClass.hIcon       = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
        //gray background
        windowClass.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
        //extra buffer
        windowClass.cbClsExtra  = 0;
    
        windowClass.cbWndExtra  = 0;
        //name to represent our window class
        windowClass.lpszClassName = progName;
        //we don't need menu
        windowClass.lpszMenuName  = NULL;
    
        //register our class to windows
        if(!RegisterClass(&windowClass))
                return 0;
    
        //create window
        HWND window;
        window = CreateWindowEx(WS_EX_TOPMOST/*TRANSPARENT*/, //allways on top of others
                                progName, //name of window class
                                progName, //text in the titlebar
                                //no resizable window without minimize option
                                WS_OVERLAPPEDWINDOW^WS_MAXIMIZEBOX^WS_THICKFRAME,
                                //default window position
                                CW_USEDEFAULT, CW_USEDEFAULT,
                                //window width and height
                                640, 330,//330,
                                //no parent window
                                NULL,
                                //no menu //49,62,71 101,83
                                NULL,
                                hInstance,
                                //no extra parameters
                                NULL);
    
        //quit if we can't create a window
    if(!window)
            return 0;
    
        ShowWindow(window, nCmdShow);
        UpdateWindow(window);
    
        //process messages
        MSG message;
        while(GetMessage(&message, NULL, 0, 0))
        {
            TranslateMessage(&message);
            DispatchMessage(&message);
        }
    
        return message.wParam;
    }
     HDC screen;
     LRESULT CALLBACK windowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         // Initialisierung     
    long way1,way2;
    int i1,i2,i3;
    
        switch(message)
        {  
            case WM_CREATE:
            {
    
                //get the whole display context
                screen = CreateDC("DISPLAY",NULL,NULL,NULL);
                if(!screen)
                    return 0;
        if(!SetTimer(hwnd, timer, interval, NULL))
                    return 0;
    
                //rectangle for color visualisation
                colorRect.left   = 452;
                colorRect.top    = 44;
                colorRect.right  = 597;
                colorRect.bottom = 101;
    
                //rectangle for color visualisation
                colorRect1.left   = 44;
                colorRect1.top    = 199;
                colorRect1.right  = 190;
                colorRect1.bottom = 260;
    
            }break;
    
               case WM_MOUSEWHEEL: 
         { 
         long fwKeys = LOWORD(wParam);    // key flags 
    long xPos = (short) LOWORD(lParam);    // horizontal position of pointer 
    long yPos = (short) HIWORD(lParam);
    long zDelta = (short) HIWORD(wParam);
           if(zDelta>0) { 
             iLupeFaktor+=1; 
           } 
           if(zDelta<0) { 
             iLupeFaktor-=1; 
           } 
          if(iLupeFaktor>=30) { 
            iLupeFaktor=30; 
           } 
    
          if(iLupeFaktor<=1) { 
            iLupeFaktor=1; 
           } 
         }  //window creation
    
            //timer
            case WM_TIMER:
            { 
              POINT mPos;
    
            GetCursorPos(&mPos);
    
                pixelColor = GetPixel(screen, mPos.x, mPos.y);
    
              //  if(pixelColor!=pixelColorLast || GetKeyState(0x31) || GetKeyState(0x32) )//||hDC!=hDCold)
                InvalidateRect(hwnd, NULL, FALSE);//mouse_event(MOUSEEVENTF_LEFTDOWN, x, y,0,0)
                 if(GetKeyState(0x01))
                   {
                   keybd_event(0x01, 0, 0, 0);
                   keybd_event(0x01,0, KEYEVENTF_KEYUP,0);
                   Sleep(100);
                   i1++;
                   }
    
               if(i1==1)
               {
               way1=pixelColor;
               i1=0;
               }
               //////////////////////////////////////////////Startet Windowslupe///////////////////////////////////////////
               if(GetKeyState(0x31))
               {
               keybd_event(0x31, 0, 0, 0);
               keybd_event(0x31,0, KEYEVENTF_KEYUP,0);
               //Sleep(1000);
               iLupeFaktor++;
    
               //ShellExecute(NULL, "open","Magnify.exe", NULL, NULL, SW_SHOW);
               }
               if(GetKeyState(0x32))
               {
               keybd_event(0x32, 0, 0, 0);
               keybd_event(0x32,0, KEYEVENTF_KEYUP,0);
               //Sleep(1000);
               iLupeFaktor-=1;
    
               //ShellExecute(NULL, "open","Magnify.exe", NULL, NULL, SW_SHOW);
               }
               pixelColorLast = pixelColor;   
            }break;
    
            case WM_PAINT:
            {
    
    POINT mPos;
    
     COLORREF clrhintergrund1 = RGB(230, 154, 0);
     COLORREF clrhintergrund2 = RGB(234, 120, 3);
     COLORREF clrhintergrund3 = RGB(232, 111, 11);
     COLORREF clrhintergrund4 = RGB(251, 130, 3);
     COLORREF clrhintergrund5 = RGB(254, 200, 18);
    
     COLORREF clrRed  = RGB(255, 25, 5);
     COLORREF clrAqua = RGB(0, 255, 255);
     COLORREF clrNavy = RGB(193, 193, 194); 
     COLORREF clrRED = RGB(255, 0, 0); 
    
     COLORREF clrtextgrun = RGB(62, 160, 19); 
     COLORREF clrtextblue = RGB(24, 24, 229);
     COLORREF clrtextgelb = RGB(255, 255, 0); 
    
     HINSTANCE hTestInstance; 
     HBITMAP hBitMap; 
     BITMAP bitmap;     
    
    char text[50]="";
          int xVektorFaktor,yVektorFaktor;
    HDC windowDC,MemDC,TestDC,TestDC1,TestDC2,VariDC;
          long int  es1,ess1,e2,es2,ess2,e3,e4;
    
    int cxScreen;
    int cyScreen;
    
            cxScreen = GetSystemMetrics(SM_CXSCREEN); 
            cyScreen = GetSystemMetrics(SM_CYSCREEN);
    
    int long  WinSizeX=cxScreen;
    long int WinSizeY = cyScreen;              
    GetCursorPos(&mPos); 
    RECT r; 
    GetWindowRect( hwnd, &r ); 
    PAINTSTRUCT ps;
    windowDC = BeginPaint(hwnd, &ps);
    HBITMAP hbmp,hbmp1,hbmp2,hbmp3,switchmode; 
    
    MemDC = CreateCompatibleDC(windowDC);
    TestDC =  CreateCompatibleDC(windowDC);
    TestDC1 =  CreateCompatibleDC(windowDC);
    TestDC2 =  CreateCompatibleDC(windowDC);
    VariDC =  CreateCompatibleDC(windowDC);
    switchmode = hbmp;
    int iLupe;
    iLupe=iLupeFaktor;
    if(iLupe<=1)
    iLupe=1;
    HWND hDesktop = GetDesktopWindow();  // DesktopWindow-Handle 
    HDC hDC = GetDC(hDesktop); 
    HDC *andreas12;
    andreas12 = &hDC;
    hbmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 640, 103,LR_SHARED); // Lädt Image-BMP von pcBmp
    hbmp1 = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP2), IMAGE_BITMAP, 640, 100,LR_SHARED);
    hbmp2 = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP3), IMAGE_BITMAP, 248, 97,LR_SHARED);   
    hbmp3 = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP4), IMAGE_BITMAP, 251, 97,LR_SHARED);
    SelectObject(MemDC, hbmp);
    SelectObject(TestDC, hbmp1);
    SelectObject(TestDC1, hbmp2);
    SelectObject(TestDC2, hbmp3);
    BitBlt(windowDC,0, 0, r.right, r.bottom,MemDC, 0, 0, SRCCOPY);//OBEN 103
    BitBlt(windowDC,0, 200, r.right, r.bottom,TestDC, 0, 0, SRCCOPY);//UNTEN 206
    BitBlt(windowDC,0, 103, r.right, r.bottom,TestDC1, 0, 0, SRCCOPY);//UNTEN 206
    BitBlt(windowDC,389, 103, r.right, r.bottom,TestDC2, 0, 0, SRCCOPY);//UNTEN 206 
    
    ess1=(-WinSizeX+mPos.x)+(WinSizeX/2);
    ess2=(-WinSizeY+mPos.y)+(WinSizeY/2);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////             
    Rectangle(windowDC, colorRect.left-1,  colorRect.top-1,
                            colorRect.right+1, colorRect.bottom+1);
    Rectangle(windowDC, colorRect1.left-1,  colorRect1.top-1,
                            colorRect1.right+1, colorRect1.bottom+1);
    long int *andreas;
    andreas = &ess1;
    int einstxDC,einstyDC;
    einstxDC=145;
    einstyDC=109;
    
    unsigned char rgbColors[3];
    unsigned char rgbColors1[3];
    unsigned char Colorsave[3];
    
                if(i1==1 || i1==3)
                {
                toRGB(way1, rgbColors1);
                way2=way1;
                toRGB(way2, Colorsave);
                toRGB(way1, rgbColors1);
                i1++;
                }
    
                if(i1=3)
                i1=0;
    
                //extract RGB values from COLORREF
                toRGB(pixelColor, rgbColors);
          //      FILE * pFile;
    
                //draw the rectangle in pixel color for more visuualization
                HBRUSH color = CreateSolidBrush(pixelColor);
                FillRect(windowDC, &colorRect, color);
                HBRUSH color1 = CreateSolidBrush(way1);
                FillRect(windowDC, &colorRect1, color1);
                /*HBRUSH color2 = CreateSolidBrush(way2);
                FillRect(windowDC, &colorRect2, color2);*/
    
                if(GetKeyState(0x78))
                exit(0);
    
                //{ShellExecute(NULL, "open","life.wav", NULL, NULL, SW_HIDE);
                //keybd_event(0x37, 0, 0, 0);
                //keybd_event(0x37,0, KEYEVENTF_KEYUP,0);
               //}
                //Output of information
    
                {
                 font = CreateFont(18,// nHeight 
                         0,// nWidth 
                         0,// nEscapement 
                         0,// nOrientation 
                         FW_NORMAL,// nWeight 
                         FALSE,// bItalic 
                         FALSE,// bUnderline 
                         0,// cStrikeOut 
                         ANSI_CHARSET,// nCharSet 
                         OUT_DEFAULT_PRECIS,// nOutPrecision 
                         CLIP_DEFAULT_PRECIS,// nClipPrecision 
                         DEFAULT_QUALITY,// nQuality 
                         DEFAULT_PITCH | FF_SWISS,// nPitchAndFamily 
                         "Arial Bold");// lpszFacename        
    
                SetBkColor(windowDC,clrhintergrund1 );     // Background eingestellt
                SetTextColor(windowDC, clrRED); // Farbe eingestellt
                SelectObject(windowDC, font);          
    
                sprintf(text, "%d",rgbColors[0],cxScreen);
                TextOut(windowDC, 120,46, text, strlen(text));
    
                SetTextColor(windowDC, clrtextgrun);
                SetBkColor(windowDC, clrhintergrund2);
                sprintf(text, "%d", rgbColors[1], cyScreen);
                TextOut(windowDC, 244, 46, text, strlen(text));
    
               // sprintf(text, "Aktivedata:", rgbColors[1], rgbColors[1]);
               // TextOut(windowDC, 10, 35, text, strlen(text));
                SetTextColor(windowDC, clrtextblue);
                SetBkColor(windowDC, clrhintergrund3);
                sprintf(text, "%d",rgbColors[2], ess2);
                TextOut(windowDC, 360, 46, text, strlen(text));
    
       SetBkColor(windowDC, clrhintergrund4);
        SetTextColor(windowDC, clrtextblue);
        sprintf(text, "%i", mPos.x, mPos.y);
        TextOut(windowDC, 378, 237, text, strlen(text));
        SetBkColor(windowDC, clrhintergrund5);
        SetTextColor(windowDC, clrtextblue);
        sprintf(text, "%i", mPos.y, mPos.x);
        TextOut(windowDC, 545, 237, text, strlen(text));
        SetBkColor(windowDC, clrhintergrund5);
        SetTextColor(windowDC, clrRED);
    
     StretchBlt(windowDC, 
                      248, 
                      103, 
                      141, 
                      97, 
                      *andreas12, 
                      *andreas+(WinSizeX/2)-(einstxDC/(2*iLupeFaktor)), 
                      (int)((double)ess2+(WinSizeY/2)-(einstyDC/(2.5*iLupeFaktor))), 
                      WinSizeX/(9*iLupeFaktor), 
                      WinSizeY/(9*iLupeFaktor), 
                      SRCCOPY); 
    
                }
    
             EndPaint(hwnd, &ps);
    
           }break;
            case WM_DESTROY:
            {
    
                //clean up
                DeleteDC(screen);
               KillTimer(hwnd, timer);
                PostQuitMessage(0);
                return 0;
            }break;
    
        }
    
        return DefWindowProc(hwnd, message, wParam, lParam);
    }
    
    //rgb[0] = red
    //rgb[1] = green
    //rgb[2] = blue
    void toRGB(COLORREF color, unsigned char *rgb)
    {
        rgb[0] = (color & 0x000000FF);
        rgb[1] = (color & 0x0000FF00)>>8;
        rgb[2] = (color & 0x00FF0000)>>16;
    }
    

    So besser?
    Ich habe alles erst mal herausgefiltert!!!



  • Nicht wirklich. Aber jetzt bin ich mir zumindest sicher, daß ich die DeleteObject()-Aufrufe nicht übersehen habe - die sind wirklich nicht da.



  • Omfg. Dein Zimmer sieht auch so chaotisch aus, stimmts?

    Such dir ne andere Beschäftigung 🤡



    • Du solltest dein Problem bzw. mögliche Ursachen genauer beschreiben (z.B. passiert das bei Betätigung des MouseWheel).
    • Du hättest auch die WinMain rausfiltern können.
    • CreateDC benötigt DeleteDC
    • Auch CreateCompatibleDC braucht DeleteDC (oder DeleteObjekt)
    • Ist dir eigentlich klar, was du mit if(!SetTimer(hwnd, timer, interval, NULL)) machst?? Das wird höchstwahrscheinlich die Ursache sein. interval ist in Milisekunden anzugeben!
    • Memory leaks sind auch dabei (durch GDI-Objekte)
    • Verwende die C++-Tags und rücke den Code ordentlich ein, damit man das überhaupt lesen kann!


  • Tja jeder fängt mal klein an und beim dem Versuch die Daten zu manipulieren um den Code besser zu gestalten sind wohl eins zwei Variabeln zuviel dazu gekommen.
    Ist ja auch eigendlich nicht so schlimm das Ergebniss sollte nur nicht sich selbst einfrieren. Ich werde den Code nochmal überarbeiten. DeleteDC habe ich jetzt zu jedem Fall eingefügt das Ergebniss war aber nicht da! Der Speicher füllt
    sich bei mir bis 2780kb und dann frieren die HDC ein. Die Ausgaben der Variablen
    funktionieren nur also di X- und die Y-Achse sowie die Farbwerte!Sorry muss schluss machen...Bis später... 😉



  • Ich habe das Problem mit eurer Hilfe verstanden und habe es auch behoben!!!
    Ich stelle den Code rein sobald ich herausgefunden habe wie ich hier akurat formatieren kann damit die Seite etwas Übersichtlicher wird! Bis dann...

    Der funktioniert endlich ist aber noch in der Beta-Version lol

    #define STRICT
    #include <windows.h>
    #include <stdio.h>
    #include <iostream> 
    #include <fstream>
    #include <string>
    #include <cstdio>
    #include "res.h"
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    ////////////////////////////////////////Durch Mauspositon die Fenstergröße festlegen///////////////////////////
    int cxScreen1()
    { 
         int cxScreen1;
         mouse_event(MOUSEEVENTF_MOVE,10000,10000,0,0);
         POINT mPos;
         GetCursorPos(&mPos); 
         cxScreen1=mPos.x;
         DeleteObject(&mPos);
    
         return(cxScreen1);
    
    }
    int cyScreen1()
    { 
         int cyScreen1;
         mouse_event(MOUSEEVENTF_MOVE,10000,10000,0,0);
         POINT mPos;
         GetCursorPos(&mPos); 
         cyScreen1=mPos.y;
         DeleteObject(&mPos);
    
         return(cyScreen1);
    
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    void toRGB(COLORREF color, unsigned char *rgb);
    COLORREF SetTextColor(HDC hdc, COLORREF crColor);
    
    const UINT TimerSec = 1;
    const UINT SizeX    = 640;
    const UINT SizeY    = 330;
    
    int iLupeFaktor=2;
    COLORREF pixelColor = 0;
    COLORREF pixelColor1;
    RECT colorRect,colorRect1;
    HWND hwndButton;
    HWND hwndButtonexit;
    HWND hwndButtoninfo; 
    unsigned char rgbColors1[3];
    FILE *pFile;
    int cxScreen,cyScreen;
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       PSTR szCmdLine, int iCmdShow)
    {
       MSG         msg;
       HWND        hWnd;
       WNDCLASS    wc;
    
       const char szAppName[] = "Colorcatcher 3.0.1 Beta";
    
       wc.cbClsExtra          = 0;
       wc.cbWndExtra          = 0;
       wc.hbrBackground       = (HBRUSH) GetStockObject(WHITE_BRUSH);
       wc.hCursor             = LoadCursor(NULL, IDC_ARROW);
       wc.hIcon               = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
       wc.hInstance           = hInstance;
       wc.lpfnWndProc         = WndProc;
       wc.lpszClassName       = szAppName;
       wc.lpszMenuName        = NULL;
       wc.style               = CS_HREDRAW | CS_VREDRAW;
    
       RegisterClass(&wc);
    
       hWnd = CreateWindowEx(WS_EX_TOPMOST/*TRANSPARENT*/, //allways on top of others
                                szAppName, //name of window class
                                szAppName, //text in the titlebar
                                //no resizable window without minimize option
                                WS_OVERLAPPEDWINDOW^WS_MAXIMIZEBOX^WS_THICKFRAME,
                                //default window position
                                CW_USEDEFAULT, CW_USEDEFAULT,
                                //window width and height
                                640, 468,//330,
                                //no parent window
                                NULL,
                                //no menu //49,62,71 101,83
                                NULL,
                                hInstance,
                                //no extra parameters
                                NULL);
    
       ShowWindow(hWnd, iCmdShow);
       UpdateWindow(hWnd);
    
       while (GetMessage(&msg, NULL, 0, 0))
       {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
       }
    
       return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
       HDC           hDC;
       static RECT     rect;
       static BOOL     isActive;
       static int      iSec;
       static int      iMin;
       static HWND hButton;
    
       switch (message)
       { 
     case WM_MOUSEWHEEL: 
         { 
         long fwKeys = LOWORD(wParam);    // key flags 
         long xPos = (short) LOWORD(lParam);    // horizontal position of pointer 
         long yPos = (short) HIWORD(lParam);
         long zDelta = (short) HIWORD(wParam);
           if(zDelta>0) { 
             iLupeFaktor+=1; 
           } 
           if(zDelta<0) { 
             iLupeFaktor-=1; 
           } 
          if(iLupeFaktor>=30) { 
            iLupeFaktor=30; 
           } 
    
          if(iLupeFaktor<=2) { 
            iLupeFaktor=2; 
           } 
          return 0;
         }  //window creation
    
      case WM_CREATE:
            {   
                RECT rc;
                GetWindowRect (GetDesktopWindow (), &rc);  
                cxScreen=rc.right; 
                cyScreen=rc.bottom;
               //cxScreen=GetSystemMetrics(SM_CXVIRTUALSCREEN);//cxScreen1();
               //cyScreen=GetSystemMetrics(SM_CYVIRTUALSCREEN);//cyScreen1();
    
                //get the whole display context
                hDC= CreateDC("DISPLAY",NULL,NULL,NULL);
    
                if(!hDC)
                    return 0;
    
                !SetTimer(hWnd, TimerSec,20, NULL);
    
                colorRect.left   = 452;
                colorRect.top    = 44;
                colorRect.right  = 597;
                colorRect.bottom = 101;
    
                colorRect1.left   = 44;
                colorRect1.top    = 199;
                colorRect1.right  = 190;
                colorRect1.bottom = 260;
    
            hwndButton = CreateWindow("button",
                                      "Save Color",
                                      WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
                                      0, 300, 220, 40,
                                      hWnd,
                                      (HMENU)1,
                                      GetModuleHandle(NULL),
                                      0); 
    
             hwndButtonexit = CreateWindow("button",
                                      "Close",
                                      WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
                                      420, 300, 220, 40,
                                      hWnd,
                                      (HMENU)2,
                                      GetModuleHandle(NULL),
                                      0);                    
    
             hwndButtoninfo = CreateWindow("button",
                                      "Help",
                                      WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
                                      220, 300, 200, 40,
                                      hWnd,
                                      (HMENU)3,
                                      GetModuleHandle(NULL),
                                      0);       
    
              return 0;
    
            }
    
     case WM_COMMAND:
          switch(wParam)
          {
          case 1:
          { 
           toRGB(pixelColor1, rgbColors1);
    
           int n;
           int name;
           POINT mPos;      
           pFile = fopen ("Showdata.txt","a+");
                   fprintf (pFile, "X: %i Y: %d  ", mPos.x, mPos.y);
                   fprintf(pFile, "Red: %i ", rgbColors1[0]);
                   fprintf(pFile, "Green: %i ", rgbColors1[1]);
                   fprintf(pFile, "Blue: %i ", rgbColors1[2]);
                   fprintf(pFile, "RGB Color:  0x%02X%02X%02X\n", rgbColors1[0],rgbColors1[1],  rgbColors1[2]);
                   fclose (pFile);
            break;
            }
    
           case 2:
                {
                SendMessage(hWnd, WM_CLOSE, 0, 0);
                break;
                }
    
            case 3:
                {
                MessageBox(hWnd,"Anleitung!\nDie Rechte Maustaste fängt die Farbe ein.\nMit dem Mausrad kann man zoomen.\nWenn man auf Speichern klickt wird die Position und die Farbe des Pixels in der Datei Showdata.txt gespeichert!","Help",MB_OK);
                break;
                } 
    
          return 0;  
    
         }
    
       case WM_TIMER:
          {
    
           InvalidateRect(hWnd, NULL, FALSE);
    
             return 0;
          }
    
       case WM_PAINT:
          {
    
             RECT r; 
             GetWindowRect( hWnd, &r );          
             PAINTSTRUCT   ps;
    
             SIZE          size;
             char          sTime[6];
             int           iLength;
             char          text[50]="";
    
    HDC MemDC,TestDC,TestDC1,TestDC2,VariDC;
    HBITMAP hbmp,hbmp1,hbmp2,hbmp3,switchmode; 
    
    /////////////////////////////Hiermit kann man die Desktopgröße ermitteln/////////////////////////////////////     
    
         //cxScreen = GetDeviceCaps(whDC,HORZRES);//= GetSystemMetrics(SM_CXSCREEN); 
         //cyScreen = GetDeviceCaps(whDC,VERTRES);//= GetSystemMetrics(SM_CYSCREEN);
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
    
     int  WinSizeX=cxScreen;
     int  WinSizeY=cyScreen;              
    
     POINT mPos;
     GetCursorPos(&mPos);  
    
     int ess1,ess2; 
     int einstxDC,einstyDC;
    
     einstxDC=145;
     einstyDC=109;
     ess1=(-WinSizeX+mPos.x)+(WinSizeX/2);
     ess2=(-WinSizeY+mPos.y)+(WinSizeY/2);
    
     COLORREF clrhintergrund1 = RGB(230, 154, 0);
     COLORREF clrhintergrund2 = RGB(234, 120, 3);
     COLORREF clrhintergrund3 = RGB(232, 111, 11);
     COLORREF clrhintergrund4 = RGB(251, 130, 3);
     COLORREF clrhintergrund5 = RGB(254, 200, 18);
    
     COLORREF clrRed  = RGB(255, 25, 5);
     COLORREF clrAqua = RGB(0, 255, 255);
     COLORREF clrNavy = RGB(193, 193, 194); 
     COLORREF clrRED = RGB(255, 0, 0); 
    
     COLORREF clrtextgrun = RGB(62, 160, 19); 
     COLORREF clrtextblue = RGB(24, 24, 229);
     COLORREF clrtextgelb = RGB(255, 255, 0); 
    
    hDC = BeginPaint(hWnd, &ps);
    {
     if(GetAsyncKeyState(0x02))
           {
           pixelColor1=pixelColor;
           }
    HWND hDesktop = GetDesktopWindow();  // DesktopWindow-Handle 
    HDC whDC = GetDC(hDesktop); 
    
    ///////////////////////////////////Hintergrund geladen////////////////////////////////////////77
    
    MemDC = CreateCompatibleDC(hDC);
    TestDC =  CreateCompatibleDC(hDC);
    TestDC1 =  CreateCompatibleDC(hDC);
    TestDC2 =  CreateCompatibleDC(hDC);
    
    hbmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 640, 103,LR_SHARED); // Lädt Image-BMP von pcBmp
    hbmp1 = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP2), IMAGE_BITMAP, 640, 100,LR_SHARED);
    hbmp2 = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP3), IMAGE_BITMAP, 248, 97,LR_SHARED);   
    hbmp3 = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP4), IMAGE_BITMAP, 251, 97,LR_SHARED);
    
    SelectObject(MemDC, hbmp);
    SelectObject(TestDC, hbmp1);
    SelectObject(TestDC1, hbmp2);
    SelectObject(TestDC2, hbmp3);       
    
    BitBlt(hDC,0, 0, r.right, r.bottom,MemDC, 0, 0, SRCCOPY);//OBEN 103
    BitBlt(hDC,0, 200, r.right, r.bottom,TestDC, 0, 0, SRCCOPY);//UNTEN 206
    BitBlt(hDC,0, 103, r.right, r.bottom,TestDC1, 0, 0, SRCCOPY);//UNTEN 206
    BitBlt(hDC,389, 103, r.right, r.bottom,TestDC2, 0, 0, SRCCOPY);//UNTEN 206 
    
    //////////////////////////////////Farbe anzeigen lassen////////////////////////////////////////////////7
    
    unsigned char rgbColors[3];
    toRGB(pixelColor, rgbColors);
    Rectangle(hDC, colorRect.left-1,  colorRect.top-1,colorRect.right+1, colorRect.bottom+1);
    HBRUSH color = CreateSolidBrush(pixelColor);
    FillRect(hDC, &colorRect, color);
    
    Rectangle(hDC, colorRect1.left-1,  colorRect1.top-1,colorRect1.right+1, colorRect1.bottom+1);
    HBRUSH color1 = CreateSolidBrush(pixelColor1);
    FillRect(hDC, &colorRect1, color1);
    
    //////////////////////////////////////////TextVariabeln einfügen/////////////////////////////////////    
    
    SetBkMode(hDC, TRANSPARENT);
    SetTextColor(hDC, clrtextblue);
    sprintf(text, "%i", mPos.x, mPos.y);
    TextOut(hDC, 378, 237, text, strlen(text));
    sprintf(text, "%i", mPos.y, mPos.x);
    TextOut(hDC, 545, 237, text, strlen(text));
    SetTextColor(hDC, clrtextblue);
    sprintf(text, "%i",rgbColors[1], ess2);
    TextOut(hDC, 360, 46, text, strlen(text));
    SetTextColor(hDC, clrRED); // Farbe eingestellt
    sprintf(text, "%i",rgbColors[0],cxScreen);
    TextOut(hDC, 120,46, text, strlen(text));
    SetTextColor(hDC, clrtextgrun);
    sprintf(text, "%i", rgbColors[1], cyScreen);
    TextOut(hDC, 244, 46, text, strlen(text));
    
    ////////////////////////////////////////Controlhelp///////////////////////////////////////////////////////
    sprintf(text, "%i", cxScreen);
    TextOut(hDC, 200, 346, text, strlen(text));
    sprintf(text, "%i", cyScreen);
    TextOut(hDC, 244, 346, text, strlen(text));
    
     /////////////////////////////////////////////Desktop holen und Farbe speichern////////////////////////////////////////      
    
    pixelColor = GetPixel(whDC, mPos.x, mPos.y);
    
    ///////////////////////////////////////////Lupe einfügen///////////////////////////////////////////////////777
    
            StretchBlt(hDC, 
                      248, 
                      103, 
                      141, 
                      97, 
                      whDC, 
                      ess1+(WinSizeX/2)-(einstxDC/(2*iLupeFaktor)), 
                      (int)((double)ess2+(WinSizeY/2)-(einstyDC/(2.5*iLupeFaktor))), 
                      WinSizeX/(9*iLupeFaktor), 
                      WinSizeY/(9*iLupeFaktor), 
                      SRCCOPY); 
    
     ///////////////////////////////////////DeleteDC////////////////////////////////////////////
    
               DeleteDC(MemDC);
               DeleteDC(TestDC1);
               DeleteDC(TestDC2);
               DeleteDC(TestDC); 
               DeleteDC(hDC);
               DeleteDC(whDC);
               DeleteObject(hDesktop);
               DeleteObject(&mPos);
               DeleteObject(sTime);
               DeleteObject(color);
               DeleteObject(color1);
    
             }
             EndPaint(hWnd, &ps); 
                   DeleteDC(hDC);   
             return 0;
          }
       case WM_DESTROY:
          {
             if (isActive)
             {
                KillTimer(hWnd, TimerSec);
             }
             PostQuitMessage(0);
             return 0;
          }
       }
       return DefWindowProc(hWnd, message, wParam, lParam);
    }
    
    void toRGB(COLORREF color, unsigned char *rgb)
    {
        rgb[0] = (color & 0x000000FF);
        rgb[1] = (color & 0x0000FF00)>>8;
        rgb[2] = (color & 0x00FF0000)>>16;
    }
    


  • masterslavemaster schrieb:

    ////////////////////////////////////////Durch Mauspositon die Fenstergröße festlegen///////////////////////////
    int cxScreen1()
    { 
         int cxScreen1;
         mouse_event(MOUSEEVENTF_MOVE,10000,10000,0,0);
         POINT mPos;
         GetCursorPos(&mPos); 
         cxScreen1=mPos.x;
         DeleteObject(&mPos);
         
         return(cxScreen1);
        
    }
    

    Ich kann ja verstehen, daß du wirklich alles wieder freigeben willst was du angefordert hast, aber an dieser Stelle ist der DeleteObject()-Aufruf definitiv fehl am Platz (un ich weiß auch nicht, was herauskommen würde, wenn du ihm etwas übergibst, was kein Grafik-Handle ist).
    Un welchen Sinn es hat, die Maus vor der Positionsmessung erst ins Nirvana zu schicken, erschließt sich mir auch nicht. (Wenn du die Bildschirmgröße ermitteln willst, bist du mit GetSystemMetrics() besser aufgehoben)



  • Tja bei mir auf meinem Laptop funktioniert es wunderbar mit GetSystemMetrics(), aber mein zweiter PC ist mit meinem LED-Fernseher via HDMI verbunden und diese Verbindung macht mir Probleme. Die Ausgabe der GetSystemMetrics() stimmt dort nicht und das Prog läuft nicht richtig! Er zeigt mit in der whDC nur die Hälfte der wirklichen Anzeige an und ich weiß leider noch nicht wie ich dazu einer Constanten finde.



  • [ cpp ] statt [ code ] - Tags wärn halt a Hit...



  • Ich werde es mir merken! 😉


Anmelden zum Antworten