Solved

Problems with own class name defined in PrecreateWindow()

Posted on 1998-11-10
10
391 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
ID: 1324480
Well, you have to change 'cs.lpszClass' instead of using a (BTW: _uninitialized_ !) WNDCLASS structure...
0
 
LVL 1

Author Comment

by:atari
ID: 1324481
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
ID: 1324482
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:atari
ID: 1324483
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
ID: 1324484
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
 
LVL 1

Author Comment

by:atari
ID: 1324485
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
ID: 1324486
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
ID: 1324487
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
ID: 1324488
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
ID: 1324489
Hey, i'm doing computer programming for about 15y now, and one _never_ (definitely NEVER!) finishes learning ;-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Doc'in system (example?) BA 7 105
tripleUp challenge 7 78
how to split multiple lines delimiter : 8 97
x-bar in Google Sheets 2 50
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

815 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

9 Experts available now in Live!

Get 1:1 Help Now