Solved

Problems with own class name defined in PrecreateWindow()

Posted on 1998-11-10
10
409 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 56
lucky13 challenge 11 168
java ^ examples 8 75
sumHeights2  challenge 7 140
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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