Thread: cursor

  1. #1
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    cursor

    how do i do a cursor... simple question
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You draw the cursor in your resource editor (or import it...whatever)...then load the icon with LoadIcon()....use the returned handle either with the hIcon member of your Windows Class structure (WNDCLASSEX) or call SetCursor()

  3. #3
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    what about the part

    Code:
    	wc.hCursor		 = LoadCursor(NULL, IDC_ARROw);
    don't i put something there?

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Typo on my part,..when I said "the hIcon member of your Windows Class structure" I meant " the hCursor member of your Windows Class structure"

    Sorry

  5. #5
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    so first i got to load the cursor? how do i do that....

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    OK, you need to load or draw a cursor in your resource editor....then you load the cursor with the LoadCursor() function. This takes 2 params....first the handle to your HINSTANCE (passed to WinMain) and also a string identifying the cursor name (VC++ and some other compilers store this as an int, so you use the MAKEINTRESOURCE macro to convert it)....then you assign the returned handle to the hCursor member of your WNDCLASSEX structure....Now any window you create from this class will use the cursor you specified as its default cursor.....

    Code:
    #include <windows.h>
    #include <tchar.h>
    #include "resource.h"
    
    LRESULT CALLBACK WndProc(HWND hWnd, 
    						 UINT msg, 
    						 WPARAM wParam, 
    						 LPARAM lParam)
    {
     	switch(msg){
    		case WM_CLOSE:
    			PostQuitMessage(0);
    			break;
    		default:
    			return DefWindowProc(hWnd, msg, wParam, lParam);
    	}
    
    	return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInst,
    				   HINSTANCE,LPSTR,int nShow){
    
    	TCHAR szWindowName[]= _T("Bitmap");
    	WNDCLASSEX wc= {0};
    	HWND hWnd;
    	MSG msg;
    
    	HCURSOR hCur = LoadCursor(hInst,MAKEINTRESOURCE(IDC_CURSOR1));
    	if(hCur == NULL)return EXIT_FAILURE;
    
    	wc.cbSize= sizeof(WNDCLASSEX);
    	wc.style= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
    	wc.lpfnWndProc= WndProc;
    	wc.hInstance= hInst;
    	wc.hIcon= LoadIcon(NULL, IDI_WINLOGO);
    	wc.hCursor= hCur;
    	wc.lpszClassName= szWindowName;
    	wc.hbrBackground= CreateSolidBrush(RGB(255, 255, 255));
    	wc.hIconSm= LoadIcon(NULL, IDI_WINLOGO);
    
    	if(!RegisterClassEx(&wc))return EXIT_FAILURE;
    
    	hWnd= CreateWindowEx(WS_EX_CLIENTEDGE,
    						   szWindowName, 
    						   szWindowName, 
    						   WS_OVERLAPPEDWINDOW,
    						   CW_USEDEFAULT, 
    						   CW_USEDEFAULT, 
    						   400, 
    						   400, 
    						   HWND_DESKTOP, 
    						   NULL, 
    						   hInst, 
    						   NULL);
    	if(!hWnd) {
    		return EXIT_FAILURE; 
    	}
    
    	ShowWindow(hWnd, nShow);
    	UpdateWindow(hWnd);
    
    	while(GetMessage(&msg, NULL, 0, 0) > 0)
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	
    	return msg.wParam;
    		
    	return 0;
    }

  7. #7
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    ok

    do u know any good windows tutorials (besides winprog cus i went through that already)

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by bluehead
    ok

    do u know any good windows tutorials (besides winprog cus i went through that already)
    Yup...try Ken Fitlike's place here

    It's the "foolest" place on the web

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. Questions about cursor functionality
    By kantze in forum Windows Programming
    Replies: 4
    Last Post: 08-22-2008, 06:42 AM
  3. Custom Animated Cursor
    By willc0de4food in forum Windows Programming
    Replies: 3
    Last Post: 05-13-2005, 10:05 PM
  4. cursor
    By Mr Learn in forum C Programming
    Replies: 1
    Last Post: 04-19-2002, 11:30 PM
  5. cursor remains in openGL fullscreen
    By Ken Fitlike in forum Game Programming
    Replies: 5
    Last Post: 03-14-2002, 08:52 PM