Thread: Weird mouse cursor

  1. #1
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    Weird mouse cursor

    Just started to write my little freecell game and came across a weird glitch. Whenever I start the app I get a busy cursor (the hourglass) until I move my mouse outside the window. Any idea what's causing this so I can nerf it?

    Code:
    #include <windows.h>
    #include "card.h"
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
        int deck[MAXCOL][MAXPOS];
        HINSTANCE card_dll;
        MSG msg;
        HWND hwnd;
        WNDCLASSEX wc;
        pfcdtInit    cdtInit;
        pfcdtInit    cdtDraw;
        pfcdtAnimate cdtDrawEx;
        pfcdtTerm    cdtTerm; 
    
        /*load cards.dll*/
        if((card_dll = LoadLibrary("cards.dll")) == 0){
             MessageBox(NULL, "Unable to load cards.dll", "Error", MB_OK | MB_ICONERROR);
             return -1;
        }
    
        /*fill in the function pointers with valid addresses*/
        cdtInit   = GetProcAddress(card_dll, "cdtInit");
        cdtDraw   = GetProcAddress(card_dll, "cdtDraw");
        cdtDrawEx = GetProcAddress(card_dll, "cdtAnimate");
        cdtTerm   = (pfcdtTerm)GetProcAddress(card_dll, "cdtTerm");
        
        shuffle(deck, 1337);
    
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = CS_DBLCLKS;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon  (hInstance, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(hInstance, IDC_ARROW);
        wc.hbrBackground = CreateSolidBrush(RGB(0,255,0));
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = "Freecell";
        wc.hIconSm       = NULL;
    
        if(RegisterClassEx(&wc) == 0){
            MessageBox(NULL, "Failed to register window", "Error", MB_OK | MB_ICONERROR);
            return -1;
        }
        /*if all goes well we have a window on-screen after this*/
        hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "Freecell", "........Cell", WS_VISIBLE | WS_SYSMENU | WS_CAPTION, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL);
        
        if(hwnd == NULL){
            MessageBox(NULL, "Unable to create window", "Error", MB_OK | MB_ICONERROR);
            return -1;
        }
        ShowWindow(hwnd, SW_SHOW);
        /*message loop*/    
        while(GetMessage(&msg, hwnd, 0, 0) > 0){
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    
        /*clean up time*/
        cdtTerm();
        FreeLibrary(card_dll);
        return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
        HDC hdc;
        PAINTSTRUCT ps;
            switch(uMsg){
    
    /*                     case WM_CREATE:
                            hdc = BeginPaint(hwnd, &ps);
                            EndPaint(hwnd, &ps);   
                         break;      
    */
                         case WM_DESTROY:
                              PostQuitMessage(0);
                         break;
                         default:
                              return DefWindowProc(hwnd, uMsg, wParam, lParam);
                         break;        
            }
        return 0;
    }

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    It means your app is busy. If the cursor is moved outside it is no longer considered busy. Does the cursor eventually switch back?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    hInstance must be NULL for the LoadIcon and LoadCursor calls if you want to retrieve system icons/cursors.

  4. #4
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154
    Thanks SMurf, that got it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get visible mouse cursor height
    By eXistenZ in forum Windows Programming
    Replies: 10
    Last Post: 09-05-2008, 09:46 PM
  2. Getting the position of the mouse cursor
    By Mavix in forum Game Programming
    Replies: 5
    Last Post: 12-27-2007, 04:02 PM
  3. Weird mouse problem in XP
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 06-16-2004, 11:47 AM
  4. changing mouse cursor
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 12-25-2001, 09:39 PM