Sign in to follow this  

Resources

This topic is 4839 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

Hi, im sorta new to programing for windows. While using the book "Sams teach yourself Game programing in 24 hours." I coded there basic window that says in the center "This is a skeleton app." Well I had to do the resources a little differently because of the way Visualy C++ 6.0 does things. Well the program compiles and starts but I don't see the icons I added. Probibly set them up wrong with Visual C++. I wish it would rather let me write the resource code my self ><

Share this post


Link to post
Share on other sites
Sorry I tend to jubber on.>< My icon resources don't show up when I run the program. Im wondering why?
My main (skeleton) .h file
#pragma once

//---------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------
#include <windows.h>
#include "resource.h"





My main (Skeleton) .cpp file
//---------------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------------
#include "Skeleton.h"

//---------------------------------------------------------------------------------
// Global Funtion Declations
//---------------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam);

//---------------------------------------------------------------------------------
// Global Functions
//---------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("Skeleton");
WNDCLASSEX wndclass;
HWND hWindow;
MSG msg;

// Create the window calss for the main window
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SKELETON));
wndclass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SKELETON_SM));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;

// Reegister the window class
if (!RegisterClassEx(&wndclass))
return 0;

// Create the window
hWindow = CreateWindow(szAppName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

// Show and update the window
ShowWindow(hWindow, iCmdShow);
UpdateWindow(hWindow);

// Enter the main message loop
while (GetMessage(&msg, NULL, 0, 0))
{
// Process the message
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
RECT rect;

switch (msg)
{
case WM_PAINT:
// Daw some text centerd in the client are of the main window
hDC = BeginPaint(hWindow, &ps);
GetClientRect(hWindow, &rect);
DrawText(hDC,
TEXT("This is a skeleton application!"),
-1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hWindow, &ps);
return 0;

case WM_DESTROY:
// Exit the application
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWindow, msg, wParam, lParam);
}






My resource.rc

//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END

3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_SKELETON ICON DISCARDABLE "Skeleton.ico"
IDI_SKELETON_SM ICON DISCARDABLE "Skeleton_sm.ico"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED






Finnaly the resource.h file.

//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Resource.rc
//
#define IDI_SKELETON 101
#define IDI_SKELETON_SM 104

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif



Share this post


Link to post
Share on other sites
Hello,

The icons are in the same directory as your source-code?
Well, I have started Windows programming less than a week, but I'm writing all resources files manually, because VC++ fills so many unnecessary code.

I suggest you using this:
resource.rc

#include "resource.h"

IDI_SKELETON ICON "Skeleton.ico"
IDI_SKELETON_SM ICON "Skeleton_sm.ico"




resource.h

#define IDI_SKELETON 101
#define IDI_SKELETON_SM 104




That's it. When you'll add new resources, try to do it manually.
IMHO, I think this is better.

Share this post


Link to post
Share on other sites
Hemm... Still nothing. I put the ico files in both the sorce code and the debug directory. Noting. Even manualy edited my resource rc/h files

Share this post


Link to post
Share on other sites
Iplayed around a little and now im getting these errors.

C:\My Documents\C++ programs\Skeleton\Resource.rc (20): error RC2144 : PRIMARY LANGUAGE ID not a number
C:\My Documents\C++ programs\Skeleton\Resource.rc (31): error RC2135 : file not found: 1000

EDIT: Got rid of these. But why the heck arn't my icons showing up? I see no reason what so ever that there not. The exe file uses them. But runing the program it self doesn't ><

Share this post


Link to post
Share on other sites
Well if I change
LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SKELETON));
LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SKELETON_SM));

to
LoadIcon(NULL, MAKEINTRESOURCE(IDI_SKELETON));
LoadIcon(NULL, MAKEINTRESOURCE(IDI_SKELETON_SM));

I get a green door for my icon. Not my skulls that I made. >< But its something


EDIT: FIgured out what was causing the problem. Not why though. If I took out ther resource for the small icon (16x16) and changed
LoadIcon(NULL, MAKEINTRESOURCE(IDI_SKELETON_SM));

to just
0;

Things work fine.

Share this post


Link to post
Share on other sites

This topic is 4839 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this