Archived

This topic is now archived and is closed to further replies.

Please help me so i can stop banging my head against the wall.....

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been going thru the resource tutorial on this site Here... I dont know if it is this tutorial or me.. or what... cuase ne thing i do with this tutorial DONT WORK!!!!.... My resource file here:
#include "resource.h"

ICON_MAIN     ICON    myicon.ico
CURSOR_ARROW  CURSOR  arrow.cur


my header file here:      
#define ICON_MAIN        1000
#define CURSOR_ARROW     2000
My load icon/cursor statements
  
HICON LoadIcon(
    HINSTANCE hInstance,  // handle to application instance

    LPCTSTR lpIconName    // icon-name string or icon resource identifier

);

HCURSOR LoadCursor(
    HINSTANCE hInstance,   // handle to application instance

    LPCTSTR lpCursorName   // name string or cursor resource identifier

);
my main file(non edited ):
   #define WIN32_LEAN_AND_MEAN
#include <windows.h>
const char className[] = "Sample Class";
const char windowName[] = "Sample Window";

LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
int WINAPI WinMain(	HINSTANCE hinstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
               {
WNDCLASSEX sampleClass;
                MSG msg;	HWND hwnd;
               	sampleClass.cbSize        = sizeof(WNDCLASSEX);
               	sampleClass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
               	sampleClass.lpfnWndProc   = MsgHandler;
                sampleClass.cbClsExtra    = 0;
                sampleClass.cbWndExtra    = 0;
                sampleClass.hInstance     = hinstance;
                sampleClass.hIcon         = LoadIcon(NULL, IDI_WINLOGO);
                sampleClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
                sampleClass.hbrBackground = (HBRUSH)(GRAY_BRUSH);
                sampleClass.lpszMenuName  = NULL;
                sampleClass.lpszClassName = className;
                sampleClass.hIconSm       = LoadIcon(NULL, IDI_WINLOGO);
                  if(!RegisterClassEx(&sampleClass))
                  {
                  MessageBox(NULL, "Could not register window class.", "ERROR", MB_OK);
                  		return 0;
                    	}
 hwnd = CreateWindowEx(	0,
	            className,
               windowName,
    WS_POPUP | WS_VISIBLE,
           0, 0, 800, 600,
	                 NULL,
                     NULL,
                hinstance,
                     NULL);
 if(hwnd == NULL)
 {
 MessageBox(NULL, "Could not create window.", "ERROR", MB_OK);
 return 0;
 }
 ShowWindow(hwnd, nCmdShow);
 UpdateWindow(hwnd);
	while(1)
 {
	if(PeekMessage(&msg,
                   NULL,
                   0,
                   0,
 PM_REMOVE))
 {
 TranslateMessage(&msg);
	DispatchMessage(&msg);
}
else if(msg.message == WM_QUIT)
{
break;
}
}
UnregisterClass(className, hinstance);
return msg.wParam;
}
LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
}
break;
default:
{
return DefWindowProc(hwnd, msg, wparam, lparam);
}
}
return 0;}
WTF is my problem... where do i put sum of this stuff.. cuase this dont tell me much(no i am not just a noob that copies and pastes code i read through it).... when i add all of it together:i get this:
 #define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "rsrc.rc"
const char className[] = "new class";
const char windowName[] = "new Window";

LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
int WINAPI WinMain(	HINSTANCE hinstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
               {
WNDCLASSEX sampleClass;
                MSG msg;	HWND hwnd;
               	sampleClass.cbSize        = sizeof(WNDCLASSEX);
               	sampleClass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
sampleClass.lpfnWndProc   = MsgHandler;
sampleClass.cbClsExtra    = 0;
sampleClass.cbWndExtra    = 0;
sampleClass.hInstance     = hinstance;
sampleClass.hIcon = LoadIcon(hinstance, "ICON_MAIN");      
sampleClass.hCursor = LoadIcon(hinstance, "CUSOR_ARROW");
sampleClass.hbrBackground = (HBRUSH)(GRAY_BRUSH);
sampleClass.lpszMenuName  = NULL;
sampleClass.lpszClassName = className;
sampleClass.hIcon = LoadIcon(hinstance, "ICON_MAIN");

HICON LoadIcon(
HINSTANCE hInstance, // handle to application instance

LPCTSTR lpIconName // icon-name string or icon resource identifier

);

HCURSOR LoadCursor(
HINSTANCE hInstance, // handle to application instance

LPCTSTR lpCursorName // name string or cursor resource identifier

);

                  if(!RegisterClassEx(&sampleClass))
                  {
                  MessageBox(NULL, "Could not register window class.", "ERROR", MB_OK);
                  		return 0;
                    	}
 hwnd = CreateWindowEx(	0,
	            className,
               windowName,
    WS_POPUP | WS_VISIBLE,
           0, 0, 800, 600,
	                 NULL,
                     NULL,
                hinstance,
                     NULL);
 if(hwnd == NULL)
 {
 MessageBox(NULL, "Could not create window.", "ERROR", MB_OK);
 return 0;
 }
 ShowWindow(hwnd, nCmdShow);
 UpdateWindow(hwnd);
	while(1)
 {
	if(PeekMessage(&msg,
                   NULL,
                   0,
                   0,
 PM_REMOVE))
 {
 TranslateMessage(&msg);
	DispatchMessage(&msg);
}
else if(msg.message == WM_QUIT)
{
break;
}
}
UnregisterClass(className, hinstance);
return msg.wParam;
}
LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
}
break;
default:
{
return DefWindowProc(hwnd, msg, wparam, lparam);
}
}
return 0;
}
[edited by - TheNerd Tk421 on August 13, 2003 4:35:19 PM]

Share this post


Link to post
Share on other sites
"It don't work" is pretty vague. What errors are you getting? I assume you are using Visual Studio. Do you have your project set up correctly for a Win32 app? More info please.

Edit: Another thing, you don't need to make prototypes for LoadIcon and LoadCursor. Those functions are provided for you with the Win32 API and are already defined in windows.h

[edited by - CodeMunkie on August 13, 2003 4:29:29 PM]

Share this post


Link to post
Share on other sites
3 new.cpp rsrc.rc:1: parse error before `500''
22 new.cpp `className'' undeclared (first use this function)
22 new.cpp (Each undeclared identifier is reported only once
22 new.cpp for each function it appears in.)
these are my errors
and my linker erros are:
g++: new.o: No such file or directory
g++: file path prefix `C:\DEV-C_~1\Bin\'' never used
.................
i am using Dev-C++ 4.0


Share this post


Link to post
Share on other sites
I dont understand it... what ever i do dealing with C++... it doesnt work... i can bearly make VERY basic C++ console apps!...
i have been trying to learn for about a year now...

[edited by - TheNerd Tk421 on August 13, 2003 4:48:57 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
don''t #include a .rc file. that is a separate type of file which must be compiled using the resource compiler. if you''re using an IDE which supports projects, you should just have to add the .rc file to the project.

replace the #include "rsrc.rc" in your main.cpp with #include "resource.h"

the places where you have LoadIcon(hinstance, "ICON_MAIN". you need to replace the quoted string with the #define constant equivalent that was set up in the resource.h file. e.g., replace "ICON_MAIN" with ICON_MAIN and replace "CURSOR_ARROW" with CURSOR_ARROW.

as previously stated, get rid of those HICON LoadIcon( ... ) statements that are in the main.cpp. those are not executable statements but function prototypes and those prototypes have already been defined via the windows include headers.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
oops, missed one. get rid of that HCURSOR LoadCursor( statement as well.

Share this post


Link to post
Share on other sites
To reiterate much of what has already been said:

1) the Windows API is not C++

2) the problem you''re having is related to C concepts, not C++

3) the "load icon/cursor statements" are actually function declarations - these are already Windows API functions, you should not be declaring these functions.

4) you cannot declare functions in the middle of a function

Regards,
Jeff

Share this post


Link to post
Share on other sites
I just looked over that tutorial and I guess I can see how it would be a little bit hard to follow (kinda wordy). Here is a guide straight from MSDN that I think is very clear:

Clickage


[edited by - CodeMunkie on August 13, 2003 5:01:00 PM]

Share this post


Link to post
Share on other sites
in the tutorial... the one i posted above... this is in there:
typedef struct _WNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HANDLE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX;

is it needed?...

Share this post


Link to post
Share on other sites