WIN32 Crazy acting mouse pointer!

Started by
3 comments, last by Lambi 17 years, 6 months ago
I'm make a perfectly normal window, but my cursor act's weird. for example: wC.hCursor = LoadIcon(NULL, IDC_CROSS); make the cursor an exclamation mark (IDI_EXCLAMATION)... and wC.hCursor = LoadIcon(NULL, IDC_ARROW); make the cursor an application icon (IDI_APPLICATION)... here is the source:

//trim down the libraries
#define WIN32_LEAN_AND_MEAN
//the normal windows header
#include <windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT paintStruct;
    HDC hDC;
    char string[] = "Hello, world!";

    switch(message)
    {
        case WM_CREATE:
            return 0;
            break;

        case WM_CLOSE:
            PostQuitMessage(0);
            return 0;
            break;

        case WM_PAINT:
            hDC = BeginPaint(hwnd, &paintStruct);
            SetTextColor(hDC, COLORREF(0x00FF0000));
            TextOut(hDC, 150, 150, string, sizeof(string)-1);
            EndPaint(hwnd, &paintStruct);
            return 0;
            break;

        default:
            break;
    }
    //pass all unhandled messages to Defwindowproc
    return (DefWindowProc(hwnd, message, wParam, lParam));
}

//main entry point of the program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmdd)
{
    WNDCLASSEX wC;
    HWND hwnd;
    MSG msg;
    bool done;

    ///////////////////////////
    //defining my window class:
    wC.cbSize = sizeof(WNDCLASSEX);
    wC.style = CS_VREDRAW | CS_HREDRAW;
    wC.lpfnWndProc = (WNDPROC)WndProc;
    wC.cbClsExtra = 0;
    wC.cbWndExtra = 0;
    wC.hInstance = hInstance;
    wC.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wC.hCursor = LoadIcon(NULL, IDC_CROSS); //bug!!!
    wC.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wC.lpszMenuName = NULL;
    wC.lpszClassName = "MyClass";
    wC.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

    if(!RegisterClassEx(&wC)) return 0;
    //end windowclass
    ///////////////////////////
    //creating the window
    hwnd = CreateWindowEx(NULL,
                        "MyClass",
                        "First Windows app. v1.0",
                        WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU,
                        100, 100,
                        680, 480,
                        NULL,
                        NULL,
                        hInstance,
                        NULL);

    if(!hwnd) return 0;
    //end creating window
    ///////////////////////////
    //message loop
    done = false;
    while(!done)
    {
        PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);

        if(msg.message == WM_QUIT) done = true;
        else
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return msg.wParam;
    //end message loop
    ///////////////////////////
    /*
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow();
    */
    return 0;
}



[Edited by - Lambi on October 16, 2006 9:31:34 AM]
Advertisement
Quote:Original post by Lambi
PS: How do I put my code in its own little window? :)

Use source instead of code: FAQ
EDIT: Also, might help if you describe the problem a little better. What do you mean by "acts weird"?
Tadd- WarbleWare
As I said :P

Quote:
for example:
wC.hCursor = LoadIcon(NULL, IDC_CROSS);
make the cursor an exclamation mark (IDI_EXCLAMATION)...

and
wC.hCursor = LoadIcon(NULL, IDC_ARROW);
make the cursor an application icon (IDI_APPLICATION)...


when defining the windows class (wC in my case) and I set the hCursor equal to LoadIcon(NULL, IDC_ARROW) the mouse pointer look like the IDI_APPLICATION icon.

^_^
Oops, I skimmed over that too quick I guess and thought CROSS and EXCLAMATION were the same somehow. Anyhow, I think it should be LoadCursor right (instead of LoadIcon)?
Tadd- WarbleWare
I can't believe I missed that O_O
Thanks alot!!!
:D

This topic is closed to new replies.

Advertisement