Public Group

# Problems for something so simple!!!

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I tried using both the MSDN and Jim Adams example in his book to create a window. But both times I get errors, more or less the same ones too...

#include <windows.h>
#include <stdio.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_CLASSDC, WindowProc, 0L, 0L, hInstance, NULL,
NULL, NULL, NULL, "MyClass", NULL } ;

RegisterClassEx(&wcex);

return 0;
}


But I get these 4 errors (7) : error C2065: 'WindowProc' : undeclared identifier (7) : error C2440: 'initializing' : cannot convert from 'int' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast (7) : error C2440: 'initializing' : cannot convert from 'struct HINSTANCE__ *' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast (8) : error C2440: 'initializing' : cannot convert from 'char [8]' to 'struct HBRUSH__ *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe. Both Examples are pretty much exactly the same, except a few variations in variable name... I cannot figure out why it really seems to hate me. They "should" work, seeing as how both did it same way. If anyone is interested... I am using Visual Studio 6, and yes my project is set to Windows Application. I've actually used the example given to me before... and now it decideds it doesn't want to work anymore... really confusing. Anyone able to tell me what I somehow must be overlooking?
Edit: Yes I understand that this doesn't actually create the window, but this should at least compile... I think Oh and what are the tags to get my code in a nice little box?

##### Share on other sites
Quote:
 Original post by XelenEdit: Yes I understand that this doesn't actually create the window, but this should at least compile... I think

I'll give you one hint about your thinking right now, WindowProc is a function that you are supposed to define [wink]. That's why it doesn't compile. Here's a quick version of it for you to throw in and it should fix that (7) : error C2065: 'WindowProc' : undeclared identifier error.

LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){    switch (message)                  /* handle the messages */    {        case WM_DESTROY:            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */            break;        default:                      /* for messages that we don't deal with */            return DefWindowProc (hwnd, message, wParam, lParam);    }    return 0;}

I added that and threw your code into DevCpp and it compiled fine.

##### Share on other sites
That code just creates and initializes an extended window class structure (the details of a window class that is passed to the RegisterClassEx function). You need to register a window class with that structure (to do that you need to first create a window procedure (WindowProc), a callback function that accepts windows messages for all the windows of the class you're trying to create) then create the window with CreateWindowEx. MSDN should explain the above in more detail. Just look for RegisterClassEx, CreateWindowEx and Window Procedures.

Here's a little page on window procedures, MSDN will provide you with more information though.

EDIT: sorry, I didn't see your edit

##### Share on other sites
Bah, no wonder... he gave us the "full" example so far, I guess it was my mistake to assume it would compile since its "complete". I was flipping back, seeing if somehow missed something... After seeing your reply, I realised he starts talking about it in another page or two after the example. Kind of wish he would have pointed out that wouldn't compile, really confusing for us beginners to kind of leave that info out...

Well ok enough ranting, thanks a lot man. I guess thats how I got it to work last time, I must have saw that last time when I was looking for why it wouldn't compile. Yah, but thanks again, that saved me from getting fustrated and stopping and just going to sleep, probably never willing to want to open it for months to come. Which is a bad thing, since I really want to make this game :D

EDIT: Oh and so I don't have to make a thread or anything... can someone tell me what makes tha nice pretty box? I tried [ code] [ /code] tags, but that just made mine all italic...

##### Share on other sites
You can find it in the faq (http://www.gamedev.net/community/forums/faq.asp).
The tag is [ source] and not [ code] :)
Happy posting!
Nathan

1. 1
2. 2
3. 3
Rutin
22
4. 4
khawk
14
5. 5

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633654
• Total Posts
3013170
×