Thread: Coordinates of cursor

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    162

    Coordinates of cursor

    Have no idea why does this code return an erroe. In another project the same function OnWM_MOUSEMOVE() works with no errors...

    Code:
    #include <windows.h>
    #include "resource1.h"
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
        HWND hWnd;
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       PSTR szCmdLine, int iCmdShow)
    {
        TCHAR szAppName[] = TEXT("Default window");           // Header
        MSG msg;
        WNDCLASSEX wc;
        
        wc.cbSize = sizeof(wc);
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));            // Ico
        wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));          // Ico_sm
        wc.hCursor = (HCURSOR)LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR));
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+0);           // Background
        wc.lpszMenuName = NULL;
        wc.lpszClassName = szAppName;
        
        RegisterClassEx(&wc);
        
        hWnd = CreateWindowEx(0,szAppName,
                            szAppName,
                            WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT,                    // Margin from left
                            CW_USEDEFAULT,                    // Margin from top
                            CW_USEDEFAULT,                    // Widht
                            CW_USEDEFAULT,                    // Height
                            NULL,
                            NULL,
                            hInstance,NULL);
        ShowWindow(hWnd, iCmdShow);
        UpdateWindow(hWnd);
        
        while(GetMessage(&msg, NULL, 0, 0))
        {
              TranslateMessage(&msg);
              DispatchMessage(&msg);
        }
        return msg.wParam;
    }
    
    void OnWM_MOUSEMOVE(WPARAM wParam, LPARAM lParam)
    {
    	POINTS ptCursor;
    	TCHAR chText[30];
    	ptCursor = MAKEPOINTS(lParam);
    	_stprintf(chText, "x=%d, y=%d", ptCursor.x, ptCursor.y);
    	SetWindowText(hWnd, chText);
    }
    
    void Draw(HWND hWnd)
    {
      HDC   hDC;
      hDC = GetDC(hWnd);
      DrawIcon(hDC, 50, 50,
        (HICON)(WORD)GetClassLong(hWnd, GCL_HICON));
      ReleaseDC(hWnd, hDC); 
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
            switch(message)
            {
              case WM_DESTROY:
              PostQuitMessage(0);
              return 0;
    
    		  case WM_PAINT:
    			  Draw(hWnd);
    			  break;
    
    		  case WM_MOUSEMOVE:
    			  OnWM_MOUSEMOVE(wParam, lParam);
    			  break;
            }
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    error C2664: '_swprintf' : cannot convert parameter 2 from 'const char [11]' to 'const wchar_t *'


    MS Visual C++
    Thx for support

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    26
    you are working in unicode. Change that and it should work.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Quote Originally Posted by vrek View Post
    you are working in unicode. Change that and it should work.
    I am supposed to know it but how do I change it?

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    26
    Depends on your compiler as to the exact placement of the option. Just look around the options and you should see something like "Use UniCode: TRUE" or something to that effect.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Don't disable Unicode. It's a good thing.

    Rather, get rid of the error by wrapping the string literal in the TEXT macro:
    Code:
    TEXT("x=&#37;d, y=%d")
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Custom Animated Cursor
    By willc0de4food in forum Windows Programming
    Replies: 3
    Last Post: 05-13-2005, 10:05 PM
  2. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  3. cursor
    By Mr Learn in forum C Programming
    Replies: 1
    Last Post: 04-19-2002, 11:30 PM
  4. cursor remains in openGL fullscreen
    By Ken Fitlike in forum Game Programming
    Replies: 5
    Last Post: 03-14-2002, 08:52 PM
  5. Mouse in 800x600 24Bit Mode?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 11-11-2001, 01:38 AM