|
You cannot use typedef and static that way. "static" defines a storage type for an instance (of whatever) and is not related to the type itself.
By
typedef A* (*CreateInstance)();
you have defined a type alias for a type "function taking no parameters and returning pointer to A". The name of the alias is CreateInstance and it is compatible with anything which satisfies this type definition. You can use your new alias as follows:
class AProvider {
public:
static A* Create() {
return new A();
}
};
A* StandAloneCreate() {
return new A();
}
...
CreateInstance Creator1 = StandaloneCreate;
CreateInstance Creator2 = AProvider::Create;
A* tA1Instance = Creator1();
A* tA2Instance = Creator2();
...
|
|
|
|
|
Hi!
I've an array of strings called playerLst.It has many single space strings(e.g "SR Tendulkar"),three two space strings(e.g "AB de villiers") and one three space string(e.g "RE van der Merwe"). I've to split the strings into parts by the space as delimeter. I've split it like this:
vector<stringc> players;
for(int j = 0; j<playerLst.size(); j++)
{
playerLst[j].split(players, " ",1);
}
Now the vector "players" has strings split by the space. I've printed and verified this. I've to rearrange the last part in every string in the vector. The following code works correct for strings which contain single space in them.
array<stringc> nameFirstPart,nameSecondPart;
for(int i = 0; i<players.size(); i++)
{
srand(t);
nameSecondPart.push_back(swapChars(players[++i]).c_str());
t++;
}
What modification has to be done in the function call, to rearrange the last part of every string in the vector?
Also I've to re stitch the rearranged string to the first part if the string originally has two parts(e.g "SR Tendulkar"), second part if it has three parts(e.g "AB de villiers") and third part if it has four parts(e.g "RE van der Merwe"). How to do this?
|
|
|
|
|
I will give you an answer here that is maybe not what you are looking for, but nevertheless I think important.
You have been asking roughly the same thing I don't know how many times by now, and you still have issues with your code. I think you need to step back and try to understand the fundamentals.
One way to get a grasp of what you are doing is to use (named) temporary variables. Try to break down your statements into smaller pieces, and store intermediate results. Be careful when naming things.
Most importantly, if you put your mind into solving each of your microproblems yourself, you will learn a lot more, and ultimately become a better programmer. In some respect, the easy access to a community like this can make you less productive in the long run.
I hope you find the solution to your problem, or that someone helps you. Good luck!
|
|
|
|
|
I would echo Niklas's good advice. I have been watching these questions for some time and it seems to me you are trying to write rather more complex code without the understanding of some of the basics. The problem you are trying to solve here with strings is really a fairly simple one; or it would be if you spent some time looking at the STL classes and string[^] in particular. I will also give you a hint, in this question the only item you really need to split out is the very last portion, regardless of how many items precede it.
It's time for a new signature.
|
|
|
|
|
|
Hi All,
I am exporting set of functions from an exe using DLLExport , and i want to call these in another dll . Can you please tell me what i need to do in the place where i am calling them..
Thanks,
Hari
|
|
|
|
|
Include the header file that contains the function declarations of the exported functions.
This header usually has the __declspec(dllimport) statement, either as it is or hidden behind a macro.
Add the name of the LIB file corresponding to the DLL in Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies .
This is one way of doing it.
Another way is to call LoadLibrary on the DLL and then use GetProcAddress to load the exported function address to call.
|
|
|
|
|
the LoadLibrary and GetProcAddress way has the advantage that the start of the calling dll always is working and you can check the for failures.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Hi sir,
I have origin axis(500,300) and x1,x2,y1,y2.
I want to draw a rectangle and rotate it with the given
I am able to draw a rectangle.
But how can i rotate a rectangle with given degree
Any idea will be helpful
Here is my code
center origin(center.x,center.y);
x1=50,2=50,y1=50,y2=50;
MoveToEx(pCellInfo->hDC,center.x-x1,center.y-y2,NULL);
Rectangle(pCellInfo->hDC,center.x-x1,center.y-y2,center.x+x2,center.y+y1);
Thanks in advance
Raj
|
|
|
|
|
Well, you just need to rotate the four vertices around the origin
xr = x * cos(alpha) + y * sin(alpha);
yr = -x * sin(alpha) + y * cos(alpha);
and then draw the lines connecting them.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Is their a way to hook a program that could check the program which is going to be executed before execution. I haven't found a way to implement such a process trap.
I stumbled upon User/Kernel Mode Drivers for the NT Kernel.
|
|
|
|
|
Hello again,
I have three class and one mainframe for my project.
one class(calculator) holds bunch of functions and commands and button that works fine(formview class with mfc) in the same class i defined tabcontrol called mytabcontrol and in each tab i have one common class called tab_one. now tab_one gets data from calculator and displays graph of those values and when i switch tab it suppose to read data again from calculator and redraw graph. I tried invalidate() and invalidateRect functions but it shows m_hWnd has not been used and 0X000000.
if anyone got clue how to solve this. Please reply.
I will post details of program and problem later.
|
|
|
|
|
Assuming it's the tab_one instances you are trying to repaint:
Have you created the instances of your tab_one class by using one of the various Create functions? From the error description it looks like you are trying to use a window object that was never created (or was created, but then destroyed)
Either you create all instances when you create the tab control, or you create the required instance when a tab is activated the first time.
|
|
|
|
|
tab_one is child dialog and it is under mytabcontrol so if i switch tabs in tab control it calls method of my tab_one class.
Creation of tab_one.h :
class CTab_one : public CDialog
{
DECLARE_DYNAMIC(CTab_one)
private:
//variables
public:
CTab_one(CWnd * pParent=NULL); // standard constructor
virtual ~CTab_one();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
// Dialog Data
public:
enum { IDD = IDD_TAB_ONE };
public:
//variables declaration
public:
//methods
virtual BOOL OnInitDialog();
protected:
virtual void OnPrint(CDC *pDC, CPrintInfo *pInfo);
virtual void OnDraw( CDC * pDC);
protected:
virtual void DoDataExchange(CDataExchange* pDX);
afx_msg void OnFileSave();
afx_msg void OnPaint();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
};
#endif
tab_one.cpp
// CTab_one.cpp : implementation file
//
#include "stdafx.h"
#include "Tab_one.h"
#include "afxwin.h"
IMPLEMENT_DYNAMIC(CTab_one, CDialog)
CTab_one::CTab_one(CWnd* pParent /*=NULL*/)
: CDialog(CTab_one::IDD, pParent)
{
}
CTab_one::~CTab_one()
{
}
void CTab_one::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BOOL CTab_one::OnInitDialog( void)
{
CDialog::OnInitDialog();
CTab_one::GetSafeHwnd();
CString cstring = " It exists";
if(::IsWindow(m_hWnd)) {
AfxMessageBox(cstring); // it does have value here
// - m_hWnd 0x000f0c30 {unused=??? } HWND__ *
unused CXX0030: Error: expression cannot be evaluated
}
GetParentFrame()->RecalcLayout();
CDialog *ctab; // to check m_hWnd value
GetDefaultValues();//method in tab_one
return true;
}
BOOL CTab_one::CreateModelessDlg(void)
{
// TODO: Add your specialized code here and/or call the base class
return (CDialog::Create(CTab_one::IDD, this)!=0);
}
int CTab_one::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
BEGIN_MESSAGE_MAP(CTab_one, CDialog)
ON_WM_PAINT()
ON_WM_CREATE()
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
END_MESSAGE_MAP()
void CTab_one::OnPrint( CDC * pDC, CPrintInfo * pInfo)
{
// TODO: add customized printing code here
this->OnDraw(pDC);
}
void CTab_one::OnPaint()
{
CPaintDC dc(this);
OnDraw( &dc );
}
#ifdef _DEBUG
void CTab_one::AssertValid() const
{
CDialog::AssertValid();
}
void CTab_one::Dump(CDumpContext& dc) const
{
CDialog::Dump(dc);
}
#endif //_DEBUG
// method that i am trying to access from mytab control
void ongraph1()....
calls updategraph()
void CTab_one::OnDraw(CDC * pDC)
{
CString szTitle;
(void)szTitle.LoadString(AFX_IDS_APP_TITLE);
AfxGetApp()->m_pMainWnd->SetWindowText(szTitle);
this->DrawCoordinates( pDC);// this draws lines in graph for all diffrent graphs
//draw graphics
DisplayTm_vs_Rb_Graph( pDC); // method that draws graph
} // end CGphView::OnDraw
void __stdcall CTab_one::DrawCoordinates( CDC * pDC)
{
}
finally :
void __stdcall CTab_one::UpdateGraph( )
{
InvalidateRect(NULL,false); // m_hwnd never used no value
}
|
|
|
|
|
Hey,
Yes I Do have instance created in mytabcontrol of tab_one but when i tell tab_one to call that method which actully draws graph and then repaint that in tab_one ..it gets confused with m_hWnd it shows m_hWnd is 0X00000 means there is no window because that method got called by mytabcontrol.
|
|
|
|
|
Having an instance of the tab_one class is not enough to get this right. I think you might be taking construction for creation. You construct a window wrapper object in the constructor, but that does not create the underlying window. It will however set m_hWnd to NULL. You have to call one of the Create methods in order to get a valid window handle, m_hWnd.
If you do this when your entire tab control is created, or better yet, when a tab is inserted into your tab control, you will not run into this problem.
|
|
|
|
|
ok so you trying to say when i am trying to call anymethod from outside of tab_one class i will have to recreate the tabs? or i call method create inside the tab_one. I have mytabcontrol which controls all tabs and tab_one which draw something inside each tab(dialog box) could you please try to reply me practically maybe in code would help..
thanks a lot.
|
|
|
|
|
I assume you have something like the following:
1. A form view or dialog that contains your tab control, say FormDlg.
2. A tab control class, either a CTabCtrl or a class derived from that.
3. This tab control contains a few tabs, where each should display a child dialog of type tab_one or derived from tab_one.
First, you either add a tab control in the resource editor and hook it up to a member variable of your FormDlg class, m_tabs. Or you create a tab control dynamically in FormDlg using CTabCtrl::Create().
Now every time you insert a new tab using CTabCtrl::InsetItem(), you also create a child dialog of type tab_one, using tab_one::Create(). You can also chose to create all these child dialogs when the tab control is first created, if the control has a fixed set of tabs. Make sure you position the child dialog relative your tab controls client area. It's a bit tricky, since the client area also includes the actual tabs at the top (stupid design I know) but you can get the hight if the tabs and adjust your display rectangle.
If the tab control is self contained, you keep those dialogs as members of your tab control derived class, otherwise they can be members of your FormDlg.
Now, displaying the proper child dialog is just a matter of responding the the TCN_SELCHANGE message and call tab_one::ShowWindow(SW_SHOW) for the activated tab, and ShowWindow(SW_HIDE) for the others.
|
|
|
|
|
Hey, thx for your reply
ok let me explain what i have done brifley,
I Have 3 classes.
First one is gphview which is formview based class which contains mytabctrl and on half window it contains some function of calculater(adding,multiply,subtract)
Second one is mytabcontrol which holds 9 different tabs and create dialog for each tab
Lastone is tab_one class which is dialog based class which draws the graphs according to tab selected.
In first gphView class :
void GphView::OnInitialUpdate( void)
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
m_tabMyTabCtrl.InsertItem(0, _T("Graph1"));
m_tabMyTabCtrl.InsertItem(1, _T("Graph1"));
m_tabMyTabCtrl.InsertItem(2, _T("Graph1"));
m_tabMyTabCtrl.InsertItem(3, _T("Graph1"));
m_tabMyTabCtrl.InsertItem(4, _T("Graph1"));
m_tabMyTabCtrl.InsertItem(5, _T("Graph1"));
m_tabMyTabCtrl.InsertItem(6, _T("Graph1"));
m_tabMyTabCtrl.InsertItem(7, _T("Graph1(occupied)"));
m_tabMyTabCtrl.Init();
}
In mytabctrl class:
CMyTabCtrl::CMyTabCtrl()
{
pTab = new CTab_one(this); // instance of tab_one class declared in header file CTab_one *pTab;
}
CMyTabCtrl::~CMyTabCtrl()
{
}
void CMyTabCtrl::Init()
{
m_tabPages[0]=new CTab_one; // m_tabpages declared in header like this CDialog *m_tabPages[8];
m_tabPages[1]=new CTab_one;
m_tabPages[2]=new CTab_one;
m_tabPages[3]=new CTab_one;
m_tabPages[4]=new CTab_one;
m_tabPages[5]=new CTab_one;
m_tabPages[6]=new CTab_one;
m_tabPages[7]=new CTab_one;
m_nNumberOfPages=8;
m_tabCurrent=0;
m_tabPages[0]->Create(IDD_TAB_ONE,this);
m_tabPages[0]->ShowWindow(SW_SHOW);
m_tabPages[1]->Create(IDD_TAB_ONE,this);
m_tabPages[1]->ShowWindow(SW_HIDE);
m_tabPages[2]->Create(IDD_TAB_ONE, this);
m_tabPages[2]->ShowWindow(SW_HIDE);
m_tabPages[3]->Create(IDD_TAB_ONE, this);
m_tabPages[3]->ShowWindow(SW_HIDE);
m_tabPages[4]->Create(IDD_TAB_ONE, this);
m_tabPages[4]->ShowWindow(SW_HIDE);
m_tabPages[5]->Create(IDD_TAB_ONE, this);
m_tabPages[5]->ShowWindow(SW_HIDE);
m_tabPages[6]->Create(IDD_TAB_ONE, this);
m_tabPages[6]->ShowWindow(SW_HIDE);
m_tabPages[7]->Create(IDD_TAB_ONE, this);
m_tabPages[7]->ShowWindow(SW_HIDE);
SetRectangle();
}
void CMyTabCtrl::SetRectangle()
{
CRect tabRect, itemRect;
int nX, nY, nXc, nYc;
GetClientRect(&tabRect);
GetItemRect(0, &itemRect);
nX=itemRect.left;
nY=itemRect.bottom+1;
nXc=tabRect.right-itemRect.left-1;
nYc=tabRect.bottom-nY-1;
m_tabPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
for(int nCount=1; nCount < m_nNumberOfPages; nCount++){
m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
}
}
BEGIN_MESSAGE_MAP(CMyTabCtrl, CTabCtrl)
//{{AFX_MSG_MAP(CMyTabCtrl)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyTabCtrl message handlers
void CMyTabCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
CTabCtrl::OnLButtonDown(nFlags, point);
if(m_tabCurrent != GetCurFocus())
{
if(m_tabCurrent<=8){ m_tabPages[m_tabCurrent]->ShowWindow(SW_HIDE);}
m_tabCurrent=GetCurFocus();
m_tabPages[m_tabCurrent]->ShowWindow(SW_SHOW);
m_tabPages[m_tabCurrent]->SetFocus();
}
if(m_tabCurrent==0){
pTab->OnGraph4();}
}
And I have mentioned tab_one class in previous post..
thx..
|
|
|
|
|
Please use the code block button when pasting code. It will make it readable.
The code is roughly what I suggested. But I don't understand what
pTab = new CTab_one(this);
is doing i the contructor? What do you need that page for? And also it has to be deleted in the destructor. I suggest you declare it as CTab_one m_tab; in the class declaration instead.
Also, there is a message for when the active tab is changed as per my last message. Relying on WM_LBUTTONDOWN is not enough, since one can navigate using keyboard.
Was there a question in your last post?
|
|
|
|
|
Hey,
Thx a lot for your replies. I have already solved my problem for redrawing graph it was just small stupid pointer mistake i wasn't passing correct value and yeah thx for TCN_SELCHANGE message i was wondering about it but didn't have time to look at it. I will have to google how that works. Could you let me know how that works like what method it will call. and wat's exact message for that.
Thx again,
cheers from CANADA
|
|
|
|
|
The message description is here[^].
You can create a message handler for it in the resource editor, or using the properties->message window.
|
|
|
|
|
|
Is there anyway i can resize my tabcontrol. like i wana have some feature like when you double click graph inside tab it will resize to mainwindow and when you double click again it will be back as normal window.
I had couple of thoughts like creating frame for tabcontrol and another for rest of the form and then just deal with frame but didn't work.
thx
|
|
|
|
|
Well, you could just resize it using SetWindowPos(), and then temporarily change the parent window to your CMainFrame I suppose.
Another way might be to mimic the behavior of print preview, but without the printing so to speak.
|
|
|
|
|