Icon error in Vis C++ 6 after writing splash class into app? *** Updated: 28/09/03 ***

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
Thanks for the sarcastic reply.

Code guru site will not load for me, ive searched on google, and i already have the google image ;)

Can anyone help?

Thanks
Dan
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: DannyBoy
Thanks for the sarcastic reply.

Code guru site will not load for me, ive searched on google, and i already have the google image ;)

Can anyone help?

Thanks
Dan

The first several links in his Google search have examples on how to make a "splash" Window.
 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
When I try to insert a Splash screen I get the error "Cannot find a CWinAPP-derived class. This component will not be inserted."

I have the appropriate classes setup but do not see what im doing wrong?

Anyone capable of helping me with this, I would really appreciate it..

Thanks
Dan
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
If you did something "different" to create your MFC app (i.e. didn't use the appwizard), the easiest thing to do may be to create a second junk MFC app in another folder, copy the folder, add the splash component to the junk app, then use windiff to compare the junk app folder to the copy you made. This will show you exactly which files were added and changed.

Or use one of the other splash windows from CTho9305's links.
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Originally posted by: DaveSimmons
If you did something "different" to create your MFC app (i.e. didn't use the appwizard), the easiest thing to do may be to create a second junk MFC app in another folder, copy the folder, add the splash component to the junk app, then use windiff to compare the junk app folder to the copy you made. This will show you exactly which files were added and changed.

Or use one of the other splash windows from CTho9305's links.

That, or try it in VB and once you get it working, compare your API calls with the ones you made in your C app. DaveSimmons' approach is probably easier.
 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
I didnt use the app wizard dave, I re-wrote it from scratch without plans to introduce a splash screen.

Note im using a bare Win32 API not MFC.

What is Windiff? :confused:

Thanks for your help so far :)
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: DannyBoy
I didnt use the app wizard dave, I re-wrote it from scratch without plans to introduce a splash screen.

Note im using a bare Win32 API not MFC.

What is Windiff? :confused:

Thanks for your help so far :)
Well that's probably why you're getting an error for the lack of a CWinApp class, since you don't have one.

I believe the CSplashWnd component needs to be in an MFC app, so you can't use it -- look at the other splash window components linked to above and find one that says Win32 rather than MFC.

visual studio > tools > windiff is a file-differencing tool can can also be fed 2 folders and will then "diff" all the files inside those two foldders. Try it, it's very very useful if you ever make a bad change and are not sure exactly which files have changed or how.
 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
Originally posted by: DaveSimmons
Originally posted by: DannyBoy
I didnt use the app wizard dave, I re-wrote it from scratch without plans to introduce a splash screen.

Note im using a bare Win32 API not MFC.

What is Windiff? :confused:

Thanks for your help so far :)
Well that's probably why you're getting an error for the lack of a CWinApp class, since you don't have one.

I believe the CSplashWnd component needs to be in an MFC app, so you can't use it -- look at the other splash window components linked to above and find one that says Win32 rather than MFC.

visual studio > tools > windiff is a file-differencing tool can can also be fed 2 folders and will then "diff" all the files inside those two foldders. Try it, it's very very useful if you ever make a bad change and are not sure exactly which files have changed or how.

OK cool ill give this a go and see what I need to do.

My problems arise purely because my knowledge of VC++ has always revolved around what I need to do. I am relatively aware of C++ for like i said, what i need to do, but its a constant learning process as I try to figure out how to do stuff I would of never needed to do in the past, if that makes sense...

Double checked the CSplashWnd component, yes it does need to be in an MFC app, the codeguru link supplied by CTho has a basic Win32, so I will give that a go and get back to you with my problems ;)

Thanks again,
Dan :)
 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
Ok, ive attempted the splash screen described here.

Ive included the header file, imported the cpp splash file, and have worked my way through 30 odd errors, down to 1 tho, which i cannot figure out.

The code im using is as follows:

My includes are set as follows:

#include "stdafx.h"
#include "resource.h"
#include "SPLASH.h"
//
SPLASH mysplash;

#include "SPLASH.cpp"
#include <io.h>

As far as i can see thats ok, am i wrong?

Then theres what ive introduced into the exception handler:

VOID ExceptionHandler(LPEXCEPTION_POINTERS p_Ex, ULONG ulEx )
{
OutputDebugString("Exception Handler\n");
}

LRESULT CALLBACK KyxCasterWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
P_KYXWINDOWDATA p_KyxWindowData;
POINT ptMouse;
int nUdpConnections;
int nTcpLiveConn;
int nTcpFileConn;


if (message == WM_CREATE)
mysplash.Init(hwnd,hInst,IDB_SPLASH); << This is line 388 for error's
mysplash.Show();
//simulate lengthy window initialization
Sleep(4000);
//hide the splash screen as the main window appears
mysplash.Hide();
<<This italic paragraph.

{

BOOL bMenuResult;

SetTimer(hwnd,ID_TIMER, 1000, NULL);

p_KyxWindowData = (P_KYXWINDOWDATA)MemAlloc(sizeof(KYXWINDOWDATA));
p_KyxWindowData->usState = 0;
p_KyxWindowData->bFrameShowing = true;
p_KyxWindowData->usStart = 0;



Now im getting the error kyxcaster.cpp(388) : error C2065: 'hInst' : undeclared identifier when i try to compile?

Im not sure what im doing wrong here...

Hope you can help with this one Dave, or anyone else....

Thanks,
Dan :)
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
(a) you should not be # including one CPP file into another, you just include the H file. To make the CPP code part of the project makefile you go to Project > Add to project > files and add both the CPP and H

(b) the error makes perfect sense: the function takes 3 parameters:
(hwnd, hInst, IDB_SPLASH)
hwnd was passed to KyxCasterWndProc by its caller, IDB_SPLASH is an id defined in resource.h, but you have not defined hinst anywhere in the function and have also not made it a global / external variable somewhere else in your code.

If you used the standard winmain, here is the HINSTANCE you are looking for:
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
Hey dave cheers for your support so far.

Im still having difficulties defining the hInst, if possible is there some way you could overlook the source for me?

Do you have MSN Messenger or anything I could use remote assitance with etc?

Thanks again,
Dan
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
try this:

at the top of your file, add a global variable

HINSTANCE hinst;

then find your WinMain line (ift HAS to be there somewhere since this is a Win32 app)

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)

...and add a line after it:

hinst = hInstance;

(if the variable name after HINSTANCE is something else, set the global hinst = to that something else.)
 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
Ok after doing what i said ive entered this into my global variables:

//globals
CHAR chKyxclass[] = "KYXCLASS";
CHAR chIniFile[] = "kyxcast.ini";
INT tabs[] = {75,140,300};
INT tabs2[] = {260,400,710};

SPLASH mysplash;
HINSTANCE hinst;


etc etc

and right from my winmain through to my exception handler ive now got this:



//--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
// Func: WinMain
// Desc: GUI entry win32 program
//--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
hinst = hInstance;
MainInit();
MainServer();
MainGui();
MainCleanup();
return(FALSE);
}
//--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
// Func: ExceptionHandler
// Desc: This routine is called when a __try fails to complete
//--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
VOID ExceptionHandler(LPEXCEPTION_POINTERS p_Ex, ULONG ulEx )
{
OutputDebugString("Exception Handler\n");
}

LRESULT CALLBACK KyxCasterWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
P_KYXWINDOWDATA p_KyxWindowData;
POINT ptMouse;
int nUdpConnections;
int nTcpLiveConn;
int nTcpFileConn;


if (message == WM_CREATE)
mysplash.Init(hwnd,hInst,IDB_SPLASH);
mysplash.Show();
//simulate lengthy window initialization
Sleep(4000);
//hide the splash screen as the main window appears
mysplash.Hide();

{

etc etc

im still receiving the following 1 error: error C2065: 'hInst' : undeclared identifier

I have not edited the the splash.h and splash.cpp files in anyway, they are how i got them. For reference here is exactly whats in mine:

Splash.h has the following -
// SPLASH.h: interface for the SPLASH class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SPLASH_H__41182F11_BB6F_11D6_B0F5_00B0D01AD687__INCLUDED_)
#define AFX_SPLASH_H__41182F11_BB6F_11D6_B0F5_00B0D01AD687__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000



class SPLASH
{
public:
void Hide();
void Show();
void Init(HWND hWnd,HINSTANCE hInst,int resid);
BOOL SHOWING;
SPLASH();
virtual ~SPLASH();
private:
UINT TimerID;
HWND hParentWindow;
HWND hSplashWnd;

};

#endif // !defined(AFX_SPLASH_H__41182F11_BB6F_11D6_B0F5_00B0D01AD687__INCLUDED_)

Splash.cpp the following -
// SPLASH.cpp: implementation of the SPLASH class.
//
//////////////////////////////////////////////////////////////////////

#include "stdAfx.h"
#include "SPLASH.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SPLASH::SPLASH()
{

}

SPLASH::~SPLASH()
{
DestroyWindow(hSplashWnd);
}

void SPLASH::Init(HWND hWnd,HINSTANCE hInst,int resid)
{
hParentWindow=hWnd;
hSplashWnd=CreateWindowEx(WS_EX_CLIENTEDGE,"STATIC","",
WS_POPUP|WS_DLGFRAME|SS_BITMAP,300,300,300,300,hWnd,NULL,hInst,NULL);
SendMessage(hSplashWnd,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)LoadBitmap(hInst,MAKEINTRESOURCE(resid)));
this->SHOWING = FALSE;
}

void SPLASH::Show()
{
//get size of hSplashWnd (width and height)
int x,y;
int pwidth,pheight;
int tx,ty;
HDWP windefer;
RECT rect,prect;
GetClientRect(hSplashWnd,&rect);
x=rect.right;y=rect.bottom;
//get parent screen coordinates
GetWindowRect(this->hParentWindow,&prect);

//center splash window on parent window
pwidth=prect.right-prect.left;
pheight=prect.bottom - prect.top;



tx=(pwidth/2) - (x/2);
ty=(pheight/2) - (y/2);

tx+=prect.left;
ty+=prect.top;


windefer=BeginDeferWindowPos(1);
DeferWindowPos(windefer,hSplashWnd,HWND_NOTOPMOST,tx,ty,50,50,SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOZORDER);
EndDeferWindowPos(windefer);

ShowWindow(hSplashWnd,SW_SHOWNORMAL);
UpdateWindow(hSplashWnd);
this->SHOWING = TRUE;
}

void SPLASH::Hide()
{
ShowWindow(hSplashWnd,SW_HIDE);
this->SHOWING = FALSE;
}
.

Thanks again,
Dan
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
spelling and capitalization both count in c++ :)

hinst != Hinst != hInst != h1n5t != HINST

look carefully, and no I didn't intentionally give you the wrong capitalization, even though it's a good learning experience for you.
 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
Thanks Dave, got it to work :D

wooooooooohpieeee dooooooooooo :D

Looks good as well.

Ill make sure you get to see the final product :)

Ill be back with my next error im sure ;)

Thanks again mate I owe you one, two, or three :)

Dan
 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
OK, upon getting the splash to work, im now faced with the window recource icon displaying a question mark icon in a speech bubble when i execute the program?

I think it links into the hInstance in some way because I remember including something but I cannot see why the splash screen would affect it?

Any ideas dave?

Thanks again
 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
OK, upon getting the splash to work, im now faced with the window recource icon displaying a question mark icon in a speech bubble when i execute the program?

I think it links into the hInstance in some way because I remember including something but I cannot see why the splash screen would affect it?

Any ideas dave?

Thanks again

Please help,
Dan :(
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
> I think it links into the hInstance in some way because I remember including something but I cannot see why the splash screen would affect it?

This is where windiff and backups become useful. You are at least using something like WinZip to back up your main and \res folders daily and before major changes like this aren't you? If not, learn this now.

Aside from solving change issues, someone in Off-Topic lost a week's work at the office because they weren't doing backups on their own and the server backup was down because of worm/virus emails.

If you've made your backups you would:
(a) do a fresh backup of your current code just in case you make a mistake with the restore
(b) restore a backup from before the splash screen, to a different folder
(c) run windiff in its folder-compare mode, and look at the changed CPP and H files.

You might want to copy / paste this into a "how to fix things" document along with other debugging / problem-solving tips you run across.

By the way, here is the line that sets the icon for the main window in one of my Win32 apps:
wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1)) ;

How could this change? By any one of these:
(a) if the resource ID number were changed to a different one from IDI_ICON1, say to IDI_SPLASH
(b) if I used the resource editor to change the bitmap(s) for IDI_ICON1
(c) if I replaced the .ico file in the \res folder with a different one
 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
My source for my GUI is as follows:

wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wcex.lpfnWndProc = KyxCasterWndProc;
wcex.cbClsExtra = 0;
// wcex.cbWndExtra = 1 * sizeof(LONG_PTR);
wcex.cbWndExtra = 1 * sizeof(LONG);
wcex.hInstance = g_hinst;
wcex.hIcon = LoadIcon (g_hinst, MAKEINTRESOURCE(IDI_KYXCASTER));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = CreateSolidBrush(RGB(0,0,0));
wcex.lpszMenuName = (LPCSTR)KYXCASTER;
wcex.lpszClassName = chKyxclass;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_KYXCASTER));
RegisterClassEx(&wcex);

I cant for the life of me figure out what has changed in relation to the icon?
Nothing has changed regarding the icon. Yes I backup everytime i change something, and windiff is only pointing out the obvious changes of the source I have placed for the splash, nothing relating to any hInst's relating to the icon, has changed.

Im so confused :confused: :(
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Hmm, in your place I'd try Edit > Find in Files using keywords
icon
IDI_
...and see if any other code is doing "icon stuff."

I'd also check with the resource editor that IDI_KYXCASTER still looks the way it should.