Link to home
Start Free TrialLog in
Avatar of atari
atari

asked on

Problems with own class name defined in PrecreateWindow()

In procedure PrecreateWindow() of CMainFrame I changed the class name for my main frame window of my application something like this:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
WNDCLASS myclass;
myclass.lpszClassName = "MyApplication";
if (!(AfxRegisterClass(&myclass)))
AfxThrowResourceException();

and so on ...

What now happens is that the icon in the upper left corner of my main frame window disappeared. What can cause that and how can I repair it, that my icon is appearing again ?

Thanks,
bye,
atari
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of atari
atari

ASKER

Sorry, I have only written a code snippet, because I am working on it in our company and do not  have the whole source code at home, where I'm sitting now, what I do is this way:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT &cs)
{
if ( !CMDIFrameWnd::PreCreateWindow(cs) )
     return 0;

   // Register my new window class

   WNDCLASS wndcls;
   HINSTANCE hInst = AfxGetInstanceHandle();
   if(!(::GetClassInfo(hInst, CUSTOM_CLASSNAME, &wndcls)))
   {
      if(::GetClassInfo(hInst, cs.lpszClass, &wndcls))
     {
        wndcls.lpszClassName = CUSTOM_CLASSNAME;
        if (!AfxRegisterClass(&wndcls))
          AfxThrowResourceException();
     }
     else
       AfxThrowResourceException();
    }
    cs.lpszClass = CUSTOMMAINFRAMECLASSNAME;

    return 1;
}

That worked, but the icon of the main frame window is the default VC-Icon for a new window !!!
Ok, sorry for being suspicious ;-)
Hmm, MFC is a bit difficult concerning the resource IDs - what happens when you set 'wndcls.hIcon' manually using 'LoadIcon()'?
Avatar of atari

ASKER

Because I have not the originally code in my home office I typed the above code in another project and I now will try to type the LoadIcon()-lines in, maybe it will work, wait a little bit.

Bye,
atari
Ok, i'll call in later again - but as i'm currently at work and it's 9:20pm meanwhile here, don't expect that i can respond later than in about 1h <s>
Avatar of atari

ASKER

Got it work, something like this:

#define CUSTOM_CLASSNAME _T("MyClassName") // somewhere at the top of Mainframe.cpp

and now:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
  if (!CFrameWnd::PreCreateWindow(cs) )
        return 0;

   WNDCLASS wndcls;
   HINSTANCE hInst = AfxGetInstanceHandle();
   if (!(::GetClassInfo(hInst, CUSTOM_CLASSNAME, &wndcls)))
   {
     if(::GetClassInfo(hInst, cs.lpszClass, &wndcls))
     {
          wndcls.hIcon = LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
        wndcls.lpszClassName = CUSTOM_CLASSNAME;
        if (!AfxRegisterClass(&wndcls))
          AfxThrowResourceException();
     }
     else
       AfxThrowResourceException();
    }
    cs.lpszClass = CUSTOM_CLASSNAME;

    return 1;
}

In MFC everything is hard work, isn't it ???

You earned your points.

Avatar of atari

ASKER

Got it work, something like this:

#define CUSTOM_CLASSNAME _T("MyClassName") // somewhere at the top of Mainframe.cpp

and now:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
  if (!CFrameWnd::PreCreateWindow(cs) )
        return 0;

   WNDCLASS wndcls;
   HINSTANCE hInst = AfxGetInstanceHandle();
   if (!(::GetClassInfo(hInst, CUSTOM_CLASSNAME, &wndcls)))
   {
     if(::GetClassInfo(hInst, cs.lpszClass, &wndcls))
     {
          wndcls.hIcon = LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
        wndcls.lpszClassName = CUSTOM_CLASSNAME;
        if (!AfxRegisterClass(&wndcls))
          AfxThrowResourceException();
     }
     else
       AfxThrowResourceException();
    }
    cs.lpszClass = CUSTOM_CLASSNAME;

    return 1;
}

In MFC everything is hard work, isn't it ???

You earned your points.

Yep, MFC is cute when you have to do 'standard things' ... but it lacks supporting customization (ever tried parametrized CRecordsets that don't use a view?)
Avatar of atari

ASKER

You are a funny guy, I'm learning every day in MFC, but there are such a lot of classes that I have never used, ODBC, SDK, DAO and so on, that I will always have questions, and therefore this discussion board is very nice for solving small problems.

Thanks,
'til the next meeting,
bye jkr,
atari
Hey, i'm doing computer programming for about 15y now, and one _never_ (definitely NEVER!) finishes learning ;-)