GetCursorPos!!!



  • Moin!!
    Ich habe folgenden Code geschrieben:

    #include <windows.h>
    #include "resource.h"
    
    LRESULT CALLBACK WndProc      (HWND, UINT, WPARAM, LPARAM) ;
    BOOL    CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         static TCHAR szAppName[] = TEXT ("About1") ;
         MSG          msg ;
         HWND         hwnd ;
         WNDCLASS     wndclass ;
    
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = szAppName ;
         wndclass.lpszClassName = szAppName ;
    
         if (!RegisterClass (&wndclass))
         {    // UNICODE-Compilierung ist die einzige realistische Fehlermöglichkeit 
              MessageBox (NULL, TEXT ("Programm arbeitet mit Unicode und setzt Windows NT voraus!"), 
                          szAppName, MB_ICONERROR) ;
              return 0 ;
         }
    
         hwnd = CreateWindow (szAppName, TEXT ("Info über... (Version 1)"),
                              WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              NULL, NULL, hInstance, 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)
    {
        PAINTSTRUCT ps;
    	HDC hdc;
    
    	static HINSTANCE hInstance ;
         POINT point;
    	 int cx,cy;
         switch (message)
         {
         case WM_CREATE :
              hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
    
    		  SetTimer(hwnd,1,10,NULL);
    		  return 0 ;
    	 case WM_PAINT:
              hdc=BeginPaint(hwnd,&ps);
              GetCursorPos(&point);
    
    		  SetPixel(hdc,point.x,point.y,RGB(255,0,0));
    		  SetPixel(hdc,point.x+1,point.y,RGB(255,0,0));
    		  SetPixel(hdc,point.x,point.y+1,RGB(255,0,0));
    		  SetPixel(hdc,point.x+1,point.y+1,RGB(255,0,0));
    
    		  EndPaint(hwnd,&ps);
    		  return 0;
         case WM_TIMER :
             InvalidateRect(hwnd,NULL,FALSE);
    		  return 0 ;
    
         case WM_DESTROY :
             KillTimer(hwnd,1); 
    		 PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    

    mein Programm soll eigentlich an der Cursorstelle die vier Pixel zeichen, aber es zeichnet sie etwa 100 Pixel zu tief und etwas nach rechts verschoben. Weiß einer warum??
    DANKE



  • Setze mal ein ScreenToClient() nach dem GetCursorPos() ein.

    .
    .
    .hdc=BeginPaint(hwnd,&ps); 
    GetCursorPos(&point); 
    
    ScreenToClient(&point);
    
    SetPixel(hdc,point.x,point.y,RGB(255,0,0));
    

    Gruß
    :: NoName ::



  • ah funktioniert. DANKE


Anmelden zum Antworten