|
Well, you cannot use printf because there is no standard out in a Win32-based program. You can either use message boxes or change a static text item. You can start by replacing that printf statement with
MessageBox(_T("message box text in GUI MFC"), _T("test"), MB_OK);
|
|
|
|
|
Ah, it helps me a bit. Thank you.
But I have a long list of functions and few external c files.
For example:
my dlgfile.cpp in GUI has
void CButtonTestDlg::OnBnClickedButton()
{int num1 = 5; int num2 = 10; int result; int error =1;
result = sum(num1, num2); //error unresolve external symbol "int .."
result = extern sum(num1, num2); //remove above lin , extern error
//extern displayError(error, result); //erro internal compile
displayError(error, result); //error unresolve external symbol "int .."
}
my ExtFile.c has
int sum(int num1, int num2)
{int SUM;
SUM = num1 + num2;
return SUM;
}
void displayError(int error, int result)
{ printf(sum %d \n"result);
switch (error)
{case 1: printf("error 1"); break;
case 2: printf("error 2"); break;
default: printf("error unknown"); break;
}
}
... other function()
Any ideas thanks.
MilkyWay
|
|
|
|
|
Again, there is no standard out, you can't just printf characters to the console, there is no console. You can change displayError to look like this:
void displayError (int error, int result) {<br />
CString szMsg;<br />
switch (error) {<br />
case 1: { szMsg.Format ("sum %d\nerror 1", result); } break;<br />
case 2: { szMsg.Format ("sum %d\nerror 2", result); } break;<br />
default: { szMsg.Format ("sum %d\nunknown error", result); } break;<br />
}<br />
MessageBox ((LPCTSTR) szMsg, _T("Error"), MB_ICONSTOP);<br />
}
That creates a CString called szMsg. CString's have a member function called Format which you can fill the CString just as if you're using printf/sprintf. Depending on the error, it fills szMsg with the text you want. At the end, it calls MessageBox to display the text. I like to cast my CString's to regular null-terminated strings. The next item is the caption, or what's displayed in the title of the box. The last item is the icon or button style to use, I selected it to just show the traffic "STOP" sign. That will do just what you need.
|
|
|
|
|
hi everyone i'm new here and in programming too
so i have a question.
i assign char to a text field variable and on screen appear the text which i'd like to appear but after this text there are some symbols.
i think my function which converts int to char could cause this ...
here is my function :
char* CPro01Dlg::Convert(int *y, int num)
{
int i, a, b, k=0;
char *text;
text = new char [2*num];
for(i=0;i<num;i++) {
="" if(y[i]="">=0 && y[i]<10) { text[k]=y[i]+48; k++; }
else if(y[i]>=10) { a = y[i]/10; text[k]=a+48; k++; b=y[i]-a*10; text[k]=b+48; }
}
return text;
}
each y[i] is from 0 to 26
Programistebo saqartvelosi sheertdit
|
|
|
|
|
What exactly is the Convert() method supposed to do? If it is simply converting from int to char , you've got way too much code. It's not that complicated.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I am not sure what your code is realy supposed to be doing. But you can get rid of the extra simbols by simply appending a '\0' character to the end of 'text'.
I decided to rewrite your code so it makes a little more since:
char* CPro01Dlg::Convert(int *y, int num)
{
int i, a, b;
char *text;
text = new char [num+1];
for(i=0; i<num; ++i)
{
if( y[i] >= 10 )
{
a = y[i] / 10;
text[i] = a + 48;
b = y[i] - a * 10;
text[i] = b + 48;
}
else if( y[i] >= 0 )
text[i] = y[i] + 48;
}
test[i] = '\0';
return text;
}
INTP
Every thing is relative...
|
|
|
|
|
thanks a lot. . .
i only needed '\0' at the end of the char.
Programistebo saqartvelosi sheertdit
|
|
|
|
|
I need help on the coding for this project. Is there any examples or coding for this program...... Write a program in C++ to simulate the performance of the SSTF and the C-LOOK disk scheduling algorithms shown in class. We assume the disk system supports track numbers ranging from 0 (the outermost track) to 49 (the innermost track).
The following shows a scenario of running the program, where user’s inputs are in boldface.
>smi3456p3 {an executable program}
please enter a sequence of track numbers:4 40 11 35 7 14
where is the current position of the arm?15
what do you want to do?
1 = SSTF
2 = C-LOOK
3 = quit
1
the history of arm movement is: 15, 14, 11, 7, 4, 35, 40
what do you want to do?
1 = SSTF
2 = C-LOOK
3 = quit
2
what is the direction the arm is currently moving?
1 = toward the innermost track (i.e. 0)
2 = toward the outermost track (i.e. 49)
2
the history of arm movement is: 15, 35, 40, 4, 7, 11, 14
what do you want to do?
1 = SSTF
2 = C-LOOK
3 = quit
3
>
brandy smith
|
|
|
|
|
I don't think many people here want to do your homework for you. The best advice I can give you is to write down how to solve the problem on paper, then realize what you did to solve the problem and simulate that when you write code. I've studied the disk scheduling algorithms myself, they aren't too difficult and I think you can do it yourself.
|
|
|
|
|
Why does this code compile? It crashes at runtime
int test(LPCWSTR p)
{
return wcslen(p);
}
int test2()
{
return test(L'');
}
.
thanks!
|
|
|
|
|
Are there any warnings from the compiler?
It's tough to tell from the code listed but it looks like you are casting a character to a string pointer. It's pretty unlikely that the string is going to be null terminated. That's what I'd be looking at.
Chris Meech
I am Canadian. [heard in a local bar]
Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Chris Meech wrote: it looks like you are casting a character to a string pointer
I am not casting, L is the notation to indicate its a unicode string. To me this is a compiler bug. More over the following code gives an error when compiled:
<br />
int test3(LPCSTR p)<br />
{<br />
return strlen(p);<br />
}<br />
<br />
int test4()<br />
{<br />
return test3('');<br />
}<br />
<br />
I am using VS6. Can someone check if this compiles on VS2003 too?
thanks!
|
|
|
|
|
It compiles because it's a valid code.
why it crashes ? well, p is NULL so that why it crashes.
I assume the L macro ( is it a macro or a MS specific keyword ? ) cannot expand a single char into a wide char string.
are you certain you're not wanting to do this instead ?
int test2()
{
return test(L"");
}
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
You are right, I had typed single quotes by mistake, and that proved costly. If only the compiler had caught it life would have been little simpler.
I dont know what L'' resolves to? There can be an empty string, but empty character doesnt make any sense. It is not clear how this compiler thinks.
thanks!
|
|
|
|
|
First, the L prefix causes the complier to treat the following constant string or character as a wide-version. So, L"Test" creates a wide string, and L'3' yields a wide character.
The empty character constant '' yields a value of zero. Since the function was expecting a pointer, and a value of zero can be used for a pointer (it is the same as NULL in C++), that is what happened and why the code compiled correctly.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Today, we have an informational dialog where the information is displayed in
a RichText control. The only action for the user is to press the OK button
to dismiss the dialog.
My desire is to enhance this dialog by adding a 'Go To' button where the
user would select one of the informational items in the list, press the 'Go
To' button, the dialog would disappear, and then the 'go to' action occurs.
I still need to display the information using RichText.
Following an example, I attempted to create a custom CListBox control where
the items in the listbox would be displayed using the CRichTextCtrl. The
custom CListBox control contains owner methods of DrawItem and MeasureItem.
The first draft for DrawItem is included. This code appears to work but is
far from perfect. It lacks code for item selection and in my sample code I
can get it to write outside of the boundary of the control. Furthermore, I
am not sure what needs to be done for MeasureItem method.
void CRichEditListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC = CDC::FromHandle (lpDrawItemStruct->hDC);
if (lpDrawItemStruct->itemID != -1)
{
COLORREF TextBkClr = SysColor (COLOR_WINDOW);
CString Text;
GetText (lpDrawItemStruct->itemID, Text);
CRect rect;
GetItemRect (lpDrawItemStruct->itemID, rect);
// Format the text and render it
UINT Left = ::MulDiv (rect.left, 1440, pDC->GetDeviceCaps (LOGPIXELSX));
UINT Top = ::MulDiv (rect.top, 1440, pDC->GetDeviceCaps (LOGPIXELSY));
UINT Right = ::MulDiv (rect.right, 1440, pDC->GetDeviceCaps (LOGPIXELSX));
UINT Bottom = ::MulDiv (rect.bottom, 1440, pDC->GetDeviceCaps (LOGPIXELSY));
CRect Rect (Left, Top, Right, Bottom);
FORMATRANGE fr;
fr.hdc = pDC->m_hDC;
fr.hdcTarget = pDC->m_hDC;
fr.rc = Rect;
fr.rcPage = Rect;
fr.chrg.cpMin = 0;
fr.chrg.cpMax = -1;
UINT StreamType;
if (Text.Left (6) == "{\\rtf1")
StreamType = SF_RTF;
else
StreamType = SF_TEXT;
EDITSTREAM es =
{
(DWORD)&Text, 0, EditStreamCallBack
};
m_pRichEditTemp->SetSel (0,-1);
m_pRichEditTemp->SetBackgroundColor (FALSE, TextBkClr);
m_pRichEditTemp->Clear ();
m_pRichEditTemp->StreamIn (StreamType, es);
m_pRichEditTemp->FormatRange (&fr, TRUE);
// Update the display with the new formatting
CRect rcClient;
m_pRichEditTemp->GetClientRect (&rcClient);
m_pRichEditTemp->DisplayBand (&rcClient);
}
}
I have examined the internet and information is scarce. My hope is that
some one can point me in the correct direction or can suggest another
approach.
Thank you for your support.
Dan
|
|
|
|
|
Hy.My problem is i dont know how to make gif animation in dynamic way with CxImage.
I found a static solution in the MFC demo program,but i need a dynamic one,
to allocate the memory dynamic.
thanx the help
|
|
|
|
|
Hi All,
I have a small app that is designed to open an Access database file (.mdb) from a normal CFileDialog. Each database has one table and has the exact same fields in it. My question is how can I open a CDatabase and connect to the CRecordset with any of the database files I select? When I created the new CRecordView and CRecordset a blank default .mdb file was used via ClassWizard.
If the default sql string is empty the "Select Database" dialog appears, but I want to select a database from my apps menu handler.
I have a CRecordView derived class (CEditorView) that will edit (add, delete, etc) the records. Unfortunately, most of the tutorials are for "reading" records only.
Hope this make sense. Thanks.
Mark
|
|
|
|
|
Take a look at this for classes to allow you to read and write to databases. There are also examples on how to edit records.
|
|
|
|
|
Thanks, but I am using ODBC:CRecordset/CDatabase for this app.
Mark
|
|
|
|
|
Mark F. wrote: My question is how can I open a CDatabase and connect to the CRecordset with any of the database files I select?
You'll want to use a DSN-less connection. This article shows a brief example.
Mark F. wrote: I have a CRecordView derived class (CEditorView) that will edit (add, delete, etc) the records. Unfortunately, most of the tutorials are for "reading" records only.
Editing/adding/deleting is no big deal. Just use CRecordset 's methods. For example:
rs.m_pDatabase->BeginTrans();
TRY
{
rs.Open();
rs.AddNew();
rs.var1 = 123;
rs.var2 = "Name";
...
rs.Update();
rs.m_pDatabase->CommitTrans();
}
CATCH(CDBException, pDBException)
{
rs.m_pDatabase->Rollback();
}
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
David,
I will read the article you posted. Thanks for the help!
Mark
|
|
|
|
|
Hi,
I need a virtual 'Video Capture Source'. I could make use of DirectX Filter to create a video capture source. But i am not getting how it is implemented in VC++. Can any example or link provide way to Register Filter created in VC++ as 'Video Capture Sources'
Thanks,
Jariwala Vishal
-- modified at 23:28 Thursday 10th November, 2005
|
|
|
|
|
Hi everybody. I stumbled today on a rather intriguing issue. I got a DLL which is loaded via a hook in Explorer.exe. In that DLL I got the following HFONT array.
#pragma bss_seg("Share")<br />
<br />
HFONT *hfntarrLabels;<br />
<br />
#pragma bss_seg()
I need it in a #pragma 'cause I use another application to set its elements. Anyway... the problem is that when I try to clean it up, free the memory, explorer.exe crashes. This is how I create it, before hooking:
hfntarrLabels = new HFONT[10];<br />
hfntarrLabels[0] = CreateFont(...)
And this is how I free it, during the hooking:
delete []hfntarrLabels; // <-- crashes
And this, also crashes:
SelectObject(hdcMem, hfntarrLabels[0]);
Even though as far as I can see, the hfntarrLabels[0] has a non zero value.
Ideas anybody?
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Axonn Echysttas wrote: hfntarrLabels = new HFONT[10];
hfntarrLabels[0] = CreateFont(...)
From the code, it looks like you are allocating memory in one process and trying to access it from another. If that's the case, it's not going to work, since each process has its own virtual address space and an address in one is meaningless to another.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|