Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CStatic class varibales used for the create() function.

Posted on 2004-08-26
13
Medium Priority
?
407 Views
Last Modified: 2013-11-20
I made a class based upon CStatic and added a Create() function.
When I used the class like this:

CMyStatic* mS = (CMyStatic*)new CMyStatic;
DWORD dwStyle = WS_CHILD | WS_VISIBLE | SS_BITMAP | SS_CENTERIMAGE;
BOOL bRet =      mS->Create(      NULL,  // LPCTSTR lpszClassName
                                     str,
                                dwStyle,
              CRect(10,10,26,26),
                                       this,
                                1001,
                              NULL );      // CCreateContext* pContext
      
It compiles and runs, however the control is not visible.
I suspect the the problem is the variables  LPCTSTR lpszClassName and CCreateContext* pContext are the problem.

My questions:  what are these variables ?  
What is the lpszClassName and do I need a CCreateContext ?

Thanks.

class CMyStatic : public CStatic
{
// Construction
public:
      CMyStatic();

// Attributes
public:

// Operations
public:

// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CMyStatic)
      public:
      virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
      //}}AFX_VIRTUAL

// Implementation
public:
      virtual ~CMyStatic();

      // Generated message map functions
protected:
      //{{AFX_MSG(CMyStatic)
      //}}AFX_MSG

      DECLARE_MESSAGE_MAP()
};
0
Comment
Question by:hansw77041
[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
  • 4
  • 3
13 Comments
 
LVL 2

Accepted Solution

by:
carribus earned 2000 total points
ID: 11901760
Technically, if you are deriving a static class, you don't need to override the Create() function unless you want to handle the specifics of the creation of the window.

CCreateContext is used when MFC creates the view (and associated frame window) that are associated with a specific document - i.e. the MFC Document/View architecture. In your case, you must pass NULL (or 0) as the CCreateContext* parameter.

The lpszClassName is used when you register a new window type. Say for example you are creating a brand new window control, and wish it to be known as a MFC_YourcustomWndControl window class, when you call the non-specialised Create() function (which you are doing in the above code), you can specific the class name of "MFC_YourcustomwndControl" as the class name.

IMHO, you should just remove the Create() function your CMyStatic class and use the one provided in CStatic.

0
 
LVL 16

Expert Comment

by:nonubik
ID: 11901833
You need also to call

ms->ShowWindow(SW_SHOWNORMAL);
0
 

Author Comment

by:hansw77041
ID: 11901843
Thanks for the info.
H'mm well if I tried NOT using the Create() and the control is not visible.
I also tried adding the class name but that makes the code crash ...

Well you answered my questions, but I'm still not able to make the control visible... any ideas ?

0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 16

Expert Comment

by:nonubik
ID: 11901850
Well, I think you rushed to accept an answer :o)
0
 
LVL 2

Expert Comment

by:carribus
ID: 11901852
could you send the revised declaration of your CMyStatic class please... and the code that creates it...
0
 
LVL 2

Expert Comment

by:carribus
ID: 11901862
ShowWindow(SW_SHOWNORMAL); will have no effect, since he is already passing the WS_VISIBLE style to the creation of the window.
0
 

Author Comment

by:hansw77041
ID: 11901899
I tried using ShowWindow() a long time agi, and it does not work.

If I removed the create(), then calling ShowWindow() crashes the code...

this does not work..

CMyStatic* mS = (CMyStatic*)new CMyStatic;
 mS->ShowWindow(SW_NORMAL);


class CMyStatic : public CStatic
{
// Construction
public:
      CMyStatic();

// Attributes
public:

// Operations
public:

// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CMyStatic)
      public:
      //}}AFX_VIRTUAL

// Implementation
public:
      virtual ~CMyStatic();

      // Generated message map functions
protected:
      //{{AFX_MSG(CMyStatic)
      //}}AFX_MSG

      DECLARE_MESSAGE_MAP()
};



0
 
LVL 16

Expert Comment

by:nonubik
ID: 11901933
CMyStatic* mS = (CMyStatic*)new CMyStatic;
 mS->ShowWindow(SW_NORMAL);

of course it doesn't

ShowWindow requires that a HWND exists.

CMyStatic* mS = (CMyStatic*)new CMyStatic;
BOOL bCreate = mS->Create( str,
                           dwStyle,
            CRect(10,10,26,26), this, 1001
);
if(bCreate)
 mS->ShowWindow(SW_NORMAL);
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11901959
Oh, I just saw you have a bitmap (SS_BITMAP)
In this case you need to load a bitmap to be displayed

mS->SetBitmap(::LoadBitmap(GetModuleInstance(0), MAKEINTRESOURCE(IDB_MYBITMAP)));
0
 
LVL 2

Expert Comment

by:carribus
ID: 11901961
Ok, now that you've removed your own Create() definition, the CStatic::Create() function should be available to you again. If I remember correctly, it is prototyped as follows:

virtual BOOL Create(LPCTSTR lpszText, DWORD dwStyle, const RECT& rc, CWnd* pParent, UINT nID);

Ok, so in your code, your creation code should look something similar to:

CMyStatic* pMS = new CMyStatic;

// - the CRect parameter merely indicates position and dimensions
// - nSomeID should be a value between 1 and 0xFFFF
pMS->Create("Test Caption", WS_VISIBLE | WS_CHILD, CRect(0,0,100,20), this, nSomeID);

PS. you will only need to call pMS->ShowWindow(SW_SHOW) if you don't specific the WS_VISIBLE style.

Try that out...
0
 

Author Comment

by:hansw77041
ID: 11904719
carribus,
Thanks, that did the trick.
Best regards
Hans W
PS wish I has more point to offer...
0
 
LVL 2

Expert Comment

by:carribus
ID: 11910343
Thank you :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

722 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