Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,557 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,920 people online right now. Registration is fast and FREE... Join Now!




Windows resources

 
Reply to this topicStart new topic

Windows resources

chickenkid11
18 May, 2008 - 11:39 PM
Post #1

New D.I.C Head
*

Joined: 28 Nov, 2007
Posts: 13


My Contributions
So I am trying to teach myself windows programming through a book. I got to the chapter on resources, and I can't get my cursor resource to work. I am using Visual Studio 2008. If someone could explain to me how to put a cursor resource into a basic windows program, that would be awesome.

My resource file just looks like:

CROSSHAIR CURSOR crosshair.cur
----------------------------------------------
The error I am getting is "Undeclared Identifier" on the winclass.hCursor line
Thanks in advance,
Ryan

CODE
// INCLUDES /////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN // just say no to MFC

#include <windows.h> // include all the windows headers
#include <windowsx.h> // include useful macros
#include <stdio.h>
#include <math.h>
// DEFINES //////////////////////////////////////////////

// defines for windows
#define WINDOW_CLASS_NAME "WINCLASS1"

// GLOBALS //////////////////////////////////////////////

// FUNCTIONS ////////////////////////////////////////////


LRESULT CALLBACK WindowProc(HWND hwnd,
                            UINT msg,
                            WPARAM wparam,
                            LPARAM lparam)
{
    // this is the main message handler of the system
    PAINTSTRUCT    ps;    //used in WM_Paint
    HDC                hdc;    //handle to a device context

    // what is the message
    switch(msg)
    {
    case WM_CREATE:
        {
            // do initialization stuff here

            // return success
            return (0);
        } break;

    case WM_PAINT:
        {
            // simplay validate the window
            hdc = BeginPaint(hwnd, &ps);
            
            

            EndPaint(hwnd, &ps);

            // return success
            return (0);
        } break;
    
    case WM_DESTROY:
        {
            // kill the application, this sends a WM_QUIT message
            PostQuitMessage(0);

            //return success
            return (0);
        } break;

    default: break;

    } // end switch

//process any messages that we didn't take care of
return (DefWindowProc(hwnd, msg, wparam, lparam));

} //end WinProc

// WINMAIN //////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hinstance,
                   HINSTANCE hprevinstance,
                   LPSTR lpcmdline, int ncmdshow)
{
    WNDCLASSEX winclass; // this will hold the class we create
    HWND hwnd; // generic window handle
    MSG msg; // generic message

    // first fill in the window class structure
    winclass.cbSize            = sizeof(WNDCLASSEX);
    winclass.style            = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc    = WindowProc;
    winclass.cbClsExtra        = 0;
    winclass.cbWndExtra        = 0;
    winclass.hInstance        = hinstance;
    winclass.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
    winclass.hCursor        = LoadCursor(hinstance, CROSSHAIR);
    winclass.hbrBackground    = (HBRUSH)GetStockObject(WHITE_BRUSH);
    winclass.lpszMenuName    = NULL;
    winclass.lpszClassName    = WINDOW_CLASS_NAME;
    winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

    // register the window class
    if (!RegisterClassEx(&winclass))
        return (0);

    // create the window
    if (!(hwnd = CreateWindowEx(NULL,                // extended style
                    WINDOW_CLASS_NAME,                // class
                    "FACE",            // title
                    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                    0,0,                            // initial x,y
                    400,400,                        // initial width, height
                    NULL,                            // handle to parent
                    NULL,                            // handle to menu
                    hinstance,                        // instance of this application
                    NULL)))                            // extra creation parms
    return (0);

    // enter main event loop
    while(GetMessage(&msg,NULL,0,0))
    {
        // translate any accelerator keys
        TranslateMessage(&msg);

        // send the message to the window proc
        DispatchMessage(&msg);
    } // end while

    //return to Windows like this
    return(msg.wParam);

} // end WinMain

/////////////////////////////////////////////////////////



This post has been edited by chickenkid11: 18 May, 2008 - 11:42 PM
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Windows Resources
18 May, 2008 - 11:46 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
The cross hair cursor is defined as IDC_CROSS. You are using CROSSHAIR, which is not defined.

Please check MSDN for full details.
User is offlineProfile CardPM
+Quote Post

chickenkid11
RE: Windows Resources
18 May, 2008 - 11:49 PM
Post #3

New D.I.C Head
*

Joined: 28 Nov, 2007
Posts: 13


My Contributions
I drew my own crosshair, not using one already supplied
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Windows Resources
18 May, 2008 - 11:58 PM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(chickenkid11 @ 19 May, 2008 - 03:49 AM) *

I drew my own crosshair, not using one already supplied

Then it's not exactly a Windows resource, now is it? You'll need to define it & load it through your rc file. If your compiler doesn't use rc (Resource Compiler Script), then I don't have the experience with your IDE to help you, sorry.
User is offlineProfile CardPM
+Quote Post

chickenkid11
RE: Windows Resources
19 May, 2008 - 09:09 AM
Post #5

New D.I.C Head
*

Joined: 28 Nov, 2007
Posts: 13


My Contributions
I did define it. At least I think I did.

CROSSHAIR CURSOR crosshair.cur

That's what it looks like. Is that all I need? Or am I missing something?
It's being done in visual studio 2008 which does use .rc files.

This post has been edited by chickenkid11: 19 May, 2008 - 05:44 PM
User is offlineProfile CardPM
+Quote Post

chickenkid11
RE: Windows Resources
21 May, 2008 - 03:58 AM
Post #6

New D.I.C Head
*

Joined: 28 Nov, 2007
Posts: 13


My Contributions
Anyone?
User is offlineProfile CardPM
+Quote Post

mikeblas
RE: Windows Resources
21 May, 2008 - 05:30 AM
Post #7

D.I.C Head
**

Joined: 8 Feb, 2008
Posts: 155



Thanked: 1 times
My Contributions
[quote name='no2pencil' date='19 May, 2008 - 12:58 AM' post='357360']
Then it's not exactly a Windows resource, now is it?[/QUOTE]It is, in fact, a Windows resource. You're confusing "Windows resources" with "stock Windows resources".[/quote]

[quote name='chickenkid11' date='19 May, 2008 - 10:09 AM' post='357535']
I did define it. At least I think I did.

CROSSHAIR CURSOR crosshair.cur

That's what it looks like. Is that all I need? Or am I missing something?
It's being done in visual studio 2008 which does use .rc files.
[/quote]



The problem is simply that you haven't defined "CROSSHAIR" for the compiler in this file. If your *.RC file has the definition you quote in your post, then you must have a declaration for "CROSSHAIR" someplace that the resource compiler sees.

If you're using Visual Studio, then I'd guess you have a RESOURCE.H file which was produced by the resource editor which includes a definition for "CROSSHAIR". If so, you should #include that resource.h file in your C++ code.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:25PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month