Solved

Problems with own class name defined in PrecreateWindow()

Posted on 1998-11-10
10
373 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:atari
  • 5
  • 5
10 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
Comment Utility
Well, you have to change 'cs.lpszClass' instead of using a (BTW: _uninitialized_ !) WNDCLASS structure...
0
 
LVL 1

Author Comment

by:atari
Comment Utility
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 !!!
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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()'?
0
 
LVL 1

Author Comment

by:atari
Comment Utility
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
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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>
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:atari
Comment Utility
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.

0
 
LVL 1

Author Comment

by:atari
Comment Utility
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.

0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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?)
0
 
LVL 1

Author Comment

by:atari
Comment Utility
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
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Hey, i'm doing computer programming for about 15y now, and one _never_ (definitely NEVER!) finishes learning ;-)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Powershell based monitoring system 2 126
repeatSeparator  java  challenge 13 56
Window placement 17 64
EvenOdd challenge 10 81
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now