|
Only way to avoid using va-arg, is to avoid variable number of arguments.
If you have some specific setups, you could say
XSprintf(char * output, char * format, int I1, int I2){
sprintf(output, format, I1, I2);
}
and
XSprintf(char * output, char * format, int I1, int I2, int I3){
sprintf(output, format, I1, I2, I3);
}
but this is not very flexible. For every kind of argument, you need new Xsprintf definition. May be good enough, tho.
|
|
|
|
|
Create an ovcerload for sprintf in your project.
In stdio.h sprintf has only one prototype so
int CYourAppSDI::sprintf(CString str)
{
}
would work or
int CYourAppSDI::sprintf(int nVar)
{
}
would work or
int CYourAppSDI::sprintf(CString str,int nVar)
{
}
would work right?
Now their are some good replacements for sprintf on this site and others.
So all you have to do is write or copy the code inside your overload.
Best Wishes and Happy Holiday's,
ez_way
|
|
|
|
|
This was talked about (unsuccessfully) here.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Review your design constraints. By excluding the use of va_arg, you are making the problem very hard if not impossible (excluding the use of hacks and kludges).
Don't shoot yourself in the foot by using silly design constraints.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi All,
Does anyone know why I would get a first chance exception occur when I try to get the current Username in a COM object I have? the error message is as follows:
First-chance exception in app.exe (SECUR32.DLL): 0xC0000005: Access Violation.
The program 'C:\app.exe' has exited with code 0 (0x0).
when all I am trying to do is
LPTSTR username;
DWORD cchBuff = 1024;
BOOL result = GetUserName(username, &cchBuff);
thanks for your help
cheers
Bryce
|
|
|
|
|
|
Hi Michael,
Thanks, you are indeed correct.
below is what is needed to be done:
<br />
LPTSTR username;<br />
DWORD cchBuff = 1024;<br />
TCHAR tchBuffer[1024]; <br />
<br />
username = tchBuffer;
BOOL result = GetUserName(username, &cchBuff);<br />
cheers
Bryce
|
|
|
|
|
#define MAX_LEN 255
CString str;
char ch[MAX_LEN];
DWORD dwNameSize = MAX_LEN;
GetUserName(ch, &dwNameSize);
Best Wishes and Happy Holiday's,
ez_way
|
|
|
|
|
Hi Guys
I have made my custom resizable combo box. I want to display a gripper in top right corner but windows don't has any in built style for that.
Can anyone guide me how to bring a gripper in top right corner.
can we rotate it some how using the funtion : SetWorldTransform
or is there some other possible way out
|
|
|
|
|
First of all I am new to C++ and in particular MFC, but I am making some minor changes to a project that I downloaded from here and the final change I need to make is to ask the user a question right after the dialog has loaded. In Visual FoxPro I would put this in the Activate of the Dialog, but in MFC this causes a multitude of issues such as:
1. The dialog doesn't actually display, so there is just a MessageBox in the middle of the screen. - The dialog displays after I click OK on the message which is understandable.
2. The Activate runs many times while the dialog is loading which causes any code I put in there to run many times (I put a flag in there to make it run only once.)
My OnActivate is shown bellow:
<br />
afx_msg void CdotNetInstallerDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimised)<br />
{<br />
CDialog::OnActivate(nState, pWndOther, bMinimised);<br />
<br />
if (m_bRunFromReboot)<br />
{<br />
m_bRunFromReboot = false;<br />
if (MessageBox("Continue with installation?", "Requirements Checker", MB_YESNO | MB_ICONQUESTION) == IDYES)<br />
ResumeInstall();<br />
}<br />
return;<br />
}<br />
Can somebody please tell me where I should put this code? I have figured that putting it in OnActivate is probably wrong.
Thanks,
Chris Ormerod
|
|
|
|
|
Thanks to GeMe_Hendrix about 10 posts below this one I have the answer (I should look before I post):
Try creating your own custom message ad handler for it first therefore at the top of your dialog CPP file...
#define WM_MYOWNMESSAGE WM_USER + 1001;
... Then in the header file put...
afx_msg LRESULT OnMyOwnMessage(WPARAM wParam, LPARAM lParam);
...Then the appropriate body for it...
LRESULT CMyDialog::OnMyOwnMessage(WPARAM wParam, LPARAM lParam)
{
... Show the file dialog box (I know it has to be modal)
return 0;
};
... And finally in the body put...
ON_MESSAGE(WM_MYOWNMESSAGE, OnMyOwnMessage)
... in the BEGIN_MESSAGE_MAP section...
... To call the message handler put this in the OnInitDialog function just before it returns...
PostMessage(WM_MYOWNMESSAGE, 0, 0);
And as a bonus I got an explanation of the message queue.
Chris.
|
|
|
|
|
Hi All,
I have a question on the following code.
class ClassA<br />
{<br />
virtual void TestA()=0;<br />
};<br />
<br />
class ClassB: public ClassA<br />
{<br />
virtual void TestA();<br />
ClassB();<br />
virtual ~ClassB();<br />
void PrintB();<br />
};<br />
<br />
void ClassB::TestA()<br />
{<br />
cout << "TestA is Called from ClassB"<<endl;<br />
return;<br />
}<br />
<br />
void ClassB::PrintB()<br />
{<br />
cout << "PrintB is called" << endl;<br />
return;<br />
}<br />
<br />
class ClassC: public ClassA<br />
{<br />
virtual void TestA();<br />
ClassC();<br />
virtual ~ClassC();<br />
void PrintC();<br />
};<br />
<br />
void ClassC::TestA()<br />
{<br />
cout << "TestA is Called from ClassC" << endl;<br />
return;<br />
}<br />
<br />
void ClassC::PrintC()<br />
{<br />
cout << "PrintC is called" << endl;<br />
return;<br />
}<br />
<br />
ClassA *pB;<br />
ClassA *pC;<br />
<br />
pB = new ClassB();<br />
pC = new ClassC();<br />
<br />
pB->TestA();
pC->TestC();
<br />
pB->PrintB();<br />
pC->PrintC();
In the above code, I am getting compilation errors as commented in the code. Is there anyway of calling methods of inherited class with a pointer to the base class?
My requirement is to call appropriate inherited class at runtime basing upon the user input with a single pointer to a base class. i.e
ClassA *pGeneric;<br />
if(user_input == 1)<br />
pGeneric = new ClassB()<br />
else<br />
pGeneric = new ClassC();
This works when the both inherited classes have the same methods but fails if inherited class an extra method. Is there any way to call one of the inherited classes during runtime with a SINGLE pointer to base class?
First of all, I want to know is it possible to do in C++? If it is possible, please suggest me the approach to take.
Please help me out. Please suggest me any other methods that provide the same functionality.
Thanks in Advance,
Anil
|
|
|
|
|
you can use dynamic_cast to see if the class is indeed of a particular derived type, then cast it to make the call. If you want the functionality to be available from a base class instance, the method needs to be in the base class.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hi Chris, Thank you for your email. Could you please tell me how to declare the pointer variable for dynamic cast?
Thanks,
Anil
|
|
|
|
|
Hi Chris,
I found information about dynamic cast in MSDN. Thank you very much!!
Anil
|
|
|
|
|
Hello,
Has anyone figured out how to make a CScrollView (or better yet a CFormView) work with a CHeaderCtrl? When I try it, the header scrolls with the view, instead of staying put like a good header should.
In my application, each row is a dynamically created child window, a bit like a modeless dialog, containing child controls. With CFormView, I just attach my child windows to the view, using SetParent, and they become part of the form; when I scroll the view, the child windows automatically scroll too. It's magic.
You may be wondering, why don't I use an ownder-drawn CListView? The header would be easy then. All of my rows are the same height, so it makes sense, but it doesn't work: when I scroll the list, my child windows don't get painted, no matter what I do. I tried attaching my child windows directly to the view's CListCtrl, instead of to the view, but it didn't help.
Any advice would be greatly appreciated!
~CK
|
|
|
|
|
The Header should not be the child of CFormview , make it child of mainframe and handle onsize event in mainframe to size header and formview so that they are both visible.
it works
|
|
|
|
|
Thank you! The fix almost works, but there's one serious problem. About half the time, when I press Alt-N to create a new document, the view overwrites my header. Would it help if I sent you my test project? At this point it's just a few lines really.
Also I don't understand why my CHeaderCtrl's captions displaying in bold instead of the usual system font? I assume CListCtrl does something that I'm not doing, but I can't figure out what.
~CK
PS here's my OnCreate and OnSize code:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// create header control
CRect r;
GetClientRect(r);
r.bottom = HEADER_HEIGHT;
m_Hdr.Create(WS_CHILD | WS_VISIBLE, r, this, 0);
HDITEM hdi;
const cols = 3;
LPCSTR str[cols] = {"Volume", "Pan", "Pitch"};
int wid[cols] = {172, 172, 172};
hdi.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
hdi.fmt = HDF_LEFT | HDF_STRING;
for (int i = 0; i < cols; i++) {
hdi.pszText = (char *)str[i];
hdi.cchTextMax = strlen(str[i]);
hdi.cxy = wid[i];
m_Hdr.InsertItem(i, &hdi);
}
return 0;
}
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
// shrink view vertically to make room for header
CView *vp = GetActiveView();
if (vp != NULL) { // need this or it crashes
CRect r;
vp->GetWindowRect(r);
ScreenToClient(r);
r.top += HEADER_HEIGHT;
vp->MoveWindow(r);
}
// stretch header horizontally to fill our client area
if (IsWindowVisible()) { // need this or it crashes
CRect r, cr;
GetClientRect(cr);
m_Hdr.GetWindowRect(r);
ScreenToClient(r);
r.right = cr.right;
m_Hdr.MoveWindow(r);
}
}
|
|
|
|
|
try to create a brand new font via LOGFONT and the set it using setfont and keep cfont a member of mainframe
should work
regarding ctrl-N ,
i would create two new windows in CView as the cviews child
one the header and other the window that you want and the ndo the scrolling in window not in cview this would be safe against ctrl-n
but you can modify onNewDocument to suit ur needs
|
|
|
|
|
Hi,
Are the arrows keys added automatically by a CTabCtrl ?
If so, how can I handle arrows keys added by MFC when I have multiple tabs ?
Thanks,
Claude
|
|
|
|
|
No, they are not. The number keys can be automatically added to the tab control, though..
When the tab control has focus and you press an arrow key, an event message WM_KEYDOWN is sent to the parent window.
Handle this message to interpret the pressed key, and if it is an arrow key, determine the correct tab to show, and order the tab control to show it. It is much like handling a user's mouse click on a tab of the tab control. You just do it programmatically.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
now I'm working on a project like voice chat ,I have finished voice chat when the two chatters
are both online. if one is not online what shoudl I do? so I want to record voice to a wave file
and transmite it to the other,so he can play sound.fortunately I have realized. then I think the
idea that transmiting and recording voice to a wave file at the same time when a chatter speaks
to all whether they are online or not is practical? please help me!!!!!
record and transmite voice
|
|
|
|
|
|
i created an SDI with several dialogs within for my project. Each time user input data into certain dialog, my Onpaint() in view class will show the image in the main window. It is more of like reading in user inputs and visualizing images at every dialog stage. Problem is, how do i control when to show the image? ie, i only want the Onpaint() to draw when dialog is receiving inputs instead of at beginning of program where of course my dialog is not activated yet. Also, i intend to put my drawing code in the various dialog.cpp files and call my those drawing fucntions in the onpaint(), is it the right approach? will appreciate if anyone can help
|
|
|
|
|
Within your OnPaint handler, you can test for the existence of the dialog boxes before executing your drawing code.
|
|
|
|
|