|
Hello,
I created a character array as you have above. I assigned it to each of my input statements with no trouble at all. It works perfectly. I am curious as to the purpose of the memset function. I would assume it re-initializes buffer to 0.
Thanks
HRW
|
|
|
|
|
Harold_Wishes wrote: I am curious as to the purpose of the memset function. I would assume it re-initializes buffer to 0.
Yes. Calling it just goes through and makes sure that every character in the buffer is set to 0 before pulling in more input.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hello again,
I did run my program and caught a runtime error with the cin.getline(buffer, 500, '\n'); I have a condensed working version below of the program compiled using Visual C++. One of my cin input streams is not being read in. It is skipped automatically and just goes to the next input prompt. I have not been able to figure out why this is happening.
I have 2 functions in main(). The problem seems to be when I move from function 1 to function 2 (the runtime error occurs in function 2). Oddly enough, the problem disappears when I comment out function 1 and only execute function 2. If you have a complier and execute the program (at least with Visual C++), you may see what I mean.
Regards
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cctype>
#include <iomanip>
#include "unsortedlist.h"
#include "sortedlist.h"
using std::string;
using namespace std;
struct node
{
string Length;
string Sequence;
string N_Terminal;
string C_Terminal;
node *nxt;
};
node *start_ptr = NULL;
node *current;
void add_Part_one (string& data1, int& data2)
{
string selection = "A";
cout << "Please Select the sequence type: " << endl;
cout << endl;
cout << "A) Complete B) Partial C) UNKNOWN" << endl;
cin >> selection;
while (selection != "A" && selection != "a" && selection != "B" && selection != "b"
&& selection != "C" && selection != "c")
{
cout << "Invalid Entry. Please Try Again: " << endl;
cin >> selection;
}
if ( selection == "A" || selection == "a" )
{
data1 = "Complete";
}
else
if ( selection == "B" || selection == "b" )
{
data1 = "Partial";
}
else
if ( selection == "C" || selection == "c" )
{
data1 = "UNKNOWN";
}
cout << "Please enter the number of subunits: ";
cin >> data2;
}
void add_node_at_end()
{
node *temp, *temp2;
temp = new node;
char buffer[501] = {0};
cout << "Please enter the length of the protein sequence: ";
cin.getline(buffer, 500, '\n');
temp->Length = buffer;
memset(buffer, 0, 501);
cout << "Please enter the protein sequence : ";
cin.getline(buffer, 500, '\n');
temp->Sequence = buffer;
memset(buffer, 0, 501);
cout << "Enter brief status on the presence of a modified N_Terminal: ";
cin.getline(buffer, 500, '\n');
temp->N_Terminal = buffer;
memset(buffer, 0, 501);
cout << "Enter brief status on the presence of a modified C_Terminal: ";
cin.getline(buffer, 500, '\n');
temp->C_Terminal = buffer;
memset(buffer, 0, 501);
temp->nxt = NULL;
if (start_ptr == NULL)
{ start_ptr = temp;
current = start_ptr;
}
else
{ temp2 = start_ptr;
while (temp2->nxt != NULL)
{ temp2 = temp2->nxt;
}
temp2->nxt = temp;
}
cout << endl;
}
int main()
{
int number_of_subunits = 1;
string SEQUENCE_TYPE;
add_Part_one(SEQUENCE_TYPE, number_of_subunits);
for (int counter = 0; counter < number_of_subunits; counter++)
{
add_node_at_end();
}
return 0;
}
HRW
|
|
|
|
|
Try this:
#include <string>
#include <list>
#include <iostream>
using namespace std;
struct data
{
string Length;
string Sequence;
string N_Terminal;
string C_Terminal;
};
list<data> g_DataList;
char selectionMenu()
{
char selection = 0;
cout << "Please Select the sequence type: " << endl;
cout << endl;
cout << "A) Complete B) Partial C) UNKNOWN" << endl;
cin >> selection;
return selection;
}
bool isValidSelection(char selection)
{
switch (selection)
{
case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c':
return true;
default:
return false;
}
}
string getSelectionString(char selection)
{
string result = "UNKNOWN";
switch (selection)
{
case 'A':
case 'a':
result = "Complete";
break;
case 'B':
case 'b':
result = "Partial";
break;
}
return result;
}
void add_Part_one (string& data1, int& data2)
{
char selection = 0;
do
{
selection = selectionMenu();
} while (!isValidSelection(selection));
data1 = getSelectionString(selection);
char buffer[100] = {0};
cout << "Please enter the number of subunits: ";
cin >> data2;
cin.getline(buffer, 99, '\n');
}
void add_node_at_end()
{
data temp;
char buffer[501] = {0};
cout << "Please enter the length of the protein sequence: ";
cin.getline(buffer, 500, '\n');
temp.Length = buffer;
memset(buffer, 0, 501);
cout << "Please enter the protein sequence : ";
cin.getline(buffer, 500, '\n');
temp.Sequence = buffer;
memset(buffer, 0, 501);
cout << "Enter brief status on the presence of a modified N_Terminal: ";
cin.getline(buffer, 500, '\n');
temp.N_Terminal = buffer;
memset(buffer, 0, 501);
cout << "Enter brief status on the presence of a modified C_Terminal: ";
cin.getline(buffer, 500, '\n');
temp.C_Terminal = buffer;
memset(buffer, 0, 501);
g_DataList.push_back(temp);
cout << endl;
}
int main()
{
int number_of_subunits = 1;
string sequenceType;
add_Part_one(sequenceType, number_of_subunits);
for (int counter = 0; counter < number_of_subunits; counter++)
{
add_node_at_end();
}
return 0;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
-- modified at 16:36 Friday 7th July, 2006
|
|
|
|
|
Thanks for the assistance.
One last question:
Will I need to overload the << operator to output each element of the data object to the screen?
I am having trouble using the iterator function for the <list> class when I attempt to print the Length, Sequence, N_Terminal and C_Terminal.
Regards
HRW
-- modified at 23:37 Saturday 8th July, 2006
|
|
|
|
|
Harold_Wishes wrote: Will I need to overload the << operator to output each element of the data object to the screen?
You don't need to per se, but you could. Either way, you should create a print method that looks like either of the following:
ostream& operator<<(ostream& os, const data& dta)
{
os << dta.Length.c_str() << endl
<< dta.Sequence.c_str() << endl
<< dta.N_Terminal.c_str() << endl
<< dta.C_Terminal.c_str() << endl;
return os;
}
void print(const data& dta)
{
cout << dta.Length.c_str() << endl
<< dta.Sequence.c_str() << endl
<< dta.N_Terminal.c_str() << endl
<< dta.C_Terminal.c_str() << endl << endl;
}
void print(const data& dta)
{
cout << dta << endl;
}
for_each(g_DataList.begin(), g_DataList.end(), print);
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
my email sending with Simple MAPI works, sort of.
But send mail is stuck in the outlook outbox
and has to be mailed from there..
I have looked the examples in here, haven't
found a clue for this problem.
I have also tried the trick, where I send the
mail in first session and then make a second
session with MAPI_FORCE_DOWNLOAD on, but that
doesn't help either.
Any ideas?
|
|
|
|
|
Hy, I have this code and this error which I don't understand. Any help will be very apreciated. Thank you.
this is test1.cpp:
#include <iostream.h>
class Address
{
private:
int house;
int block;
public:
Address(int i, int j) {
house=i;
block=j;
}
friend ostream& operator << (ostream&, const Address&);
};
ostream& operator << (ostream& a, const Address& b)
{
a<<"House No "<
|
|
|
|
|
I suppose you have to move your implementation of operator << to test1.cpp (or other *.cpp) file.
I hope it helps.
-- modified at 10:56 Friday 7th July, 2006
|
|
|
|
|
mosu` wrote: this is test1.cpp:
The following code should be moved to a header file (you should not be including *.cpp files!):
In test1.h
#pragma once
#include <ostream>
class Address
{
private:
int house;
int block;
public:
Address(int i, int j) : house(i), block(j)
{ }
int GetHouseNumber() const { return house; }
int GetBlockNumber() const { return block; }
};
inline ostream& operator<<(ostream& a, const Address& b)
{
a << "House No " << b.GetHouseNumber() << endl;
a << "Block Number " << b.GetBlockNumber() << endl;
return a;
};
And in main.cpp
#include "test1.h"
int main()
{
Address a(10,113);
cout << a;
return 0;
}
The error is due to the fact that test1.cpp is being compiled twice in your code and thus has multiple definitions in the object code.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hello
How to run an application within an application : inside a dialog-based application, I want to run another one inside a rectangle ?
Thank you
|
|
|
|
|
Hi,
You can create a process using CreateProcess and can set it size in STARTUP_INFO parameter.
see msdn for more details.
AFAIK it is not possible to show that exe insde your appliaction, unless it's a COM control (ActiveX or DLL). I'm not sure about this.
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|
Sarath.<fon wrote:<="" div="">AFAIK it is not possible to show that exe insde your appliaction, unless it's a COM control (ActiveX or DLL). I'm not sure about this.
If the application is simple enough, you can wrap it in an ActiveX control and have it run inside that. Also, if the application exposes itself via COM (like the office components), you can have it appear on a dialog, but it won't look like the full application in most cases.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
In the case of a notepad or wordpad what? what we can do with that?
Office system is completely developed as COM Components and many applications using it very well. that is what I said, we can't make inside as our control or part of our application unless it is an attachable manner.
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|
Do you mean to embed one dialog in another? You could (probably should) do so in the same application. In fact, you can glue the two dialogs together forever. To do it properly:
In the client area of your container dialog, create a child window (rectangle). Pass this child window as the paranet of your embeded dialog.
Best,
Jun
|
|
|
|
|
Hello,
I'm using a CListCtrl in a CListView to show my data and now I want my data to be shown in a grphical form (with rectangles, circles, lines and so on). For testing, I decided to do this on a right mouse double-click an I implemented the following:
void kstkoardwView::OnRButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Code für die Behandlungsroutine für Nachrichten hier einfügen und/oder Standard aufrufen
//Test for Graphik
CClientDC dc(this);
CListCtrl &listCtrl = GetListCtrl();
RECT rect;
for (int i = 0; i <= 6; i++)
{
listCtrl.DeleteColumn(0);
}
GetClientRect(&rect);
dc.Rectangle(rect.left, rect.bottom, rect.right, rect.top);
int b = (int) (100.0 * rand() / RAND_MAX);
dc.TextOut(point.x-100, point.y-100, "Hugo");
dc.Ellipse(point.x-b, point.y-b, point.x+b, point.y+b);
dc.Rectangle(point.x-b+100, point.y-b+100, point.x+b, point.y+b);
dc.Rectangle(10, rect.bottom, 20, rect.bottom-100);
dc.Rectangle(20, rect.bottom, 30, rect.bottom-75);
dc.Pie(100, 100, 150, 150, 300, 300, 250, 250);
dc.Draw3dRect(200,200,300,300,0,0);
CListView::OnRButtonDblClk(nFlags, point);
}
But following happens: First double-click = Columns are deleted - the gray header-row is still visible. Second doble-click = the rest is done and I see my drawing.
Can anyone tell me why and a solution? Or has anyone a better solution to make graphics from CListView-data?
Thanks, Gerhard
|
|
|
|
|
If I understand what you are trying to do correctly, you have some data displayed in a ListView and the user can select an option to display it in a different way?
That being the case, you are going about it the wrong way. You should be creating another view that displays the data the way you want it. When the user turns on that view, you display it. This article should help get you started after you write the code for your new view.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks for your answer,
I'm using MDI and till now (at the beginning) I have already about 10 DocTemplates. So I hoped, I can make the graphic (for each of this templates) without making a new one.
But regardless of this your answer helped me. I recogniced, that I have only to make a new View (and use the old Doc).
Thanks, Gerhard
|
|
|
|
|
Hello all,
i'm trying to display a Bitmap in a Picture Control. The picture is captured by a CMOS camera (gray), and all i have is a pointer to the image in the Framegrabber buffer. The problem is that i don't have a real bitmap in that buffer, just an array with pixel values. The technical support of the Framgrabber producer couldn't help me till now and i'm still waiting for thier reply . I was trying to create a Bitmap manualy and fill in all the needed structures like BITMAPINFO and so on but nothing worked. Can you tell me how to construct a bitmap from an pixelarray, just knowing the lenght, width and that's it is gray scale picture.
I would be very greatfull for any kind of help!
I wish you a nice Weekend
im79
|
|
|
|
|
Gray as in 8-bits per pixel? Did you set up the color table? Show how you're calling CreateDIBitmap and your input values (BITMAPINFO).
|
|
|
|
|
Hello all, hello hrfy and thanks for your answer
Yes it is 8-bits per pixel. I didn't set the color table. I just called CreateBitmap or DIBitmap passing width, length, the pointer to the pixel array and so on. I as i explaind in my first posting, i don't have a BITMAPINFO, can make one manualy?
I tried manythings but nothing worked. I'm new to windows programming and MFC.
I'm not at work now, so i don't have the source code here right now.
Eventhough i cann't provide enough info, i hope u can still help me on this one
Kind regards and thanks again ,
im79
|
|
|
|
|
im79 wrote: i don't have a BITMAPINFO, can make one manualy?
If you know what kind of data is in the pixel array, you should have no problem populating the header.
I've just written and tested this by generating a grayscale gradient and it works.
HBITMAP CreateGrayscaleBitmap(int nWidth, int nHeight, LPBYTE pData)
{
BITMAPINFO *pbmi = (BITMAPINFO*) new BYTE[sizeof(BITMAPINFO) + (sizeof(RGBQUAD) * 256)];
ZeroMemory(pbmi, sizeof(BITMAPINFO));
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = nWidth;
pbmi->bmiHeader.biHeight = -nHeight;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = 8;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = nWidth * nHeight;
RGBQUAD *pColors = pbmi->bmiColors;
for(int i = 0; i < 256; i++)
{
pColors->rgbBlue = i;
pColors->rgbGreen = i;
pColors->rgbRed = i;
pColors->rgbReserved = 0;
pColors++;
}
CWindowDC dc(NULL);
HBITMAP hBitmap = CreateDIBitmap(dc, &pbmi->bmiHeader, CBM_INIT, pData, pbmi, DIB_RGB_COLORS);
delete pbmi;
return hBitmap;
}
This is for a top-down bitmap. If your image is flipped, remove the negative sign in front of the height.
|
|
|
|
|
Hi, i've tried your code in my appicaltion and have another problem now . I need a CBitmap object, so i tried the following:
<br />
CDC *pDC = GetDC();<br />
CBitmap* myBitmap;<br />
<br />
myBitmap = CBitmap::FromHandle(hBitmap);<br />
myBitmap->CreateCompatibleBitmap(pDC, m_iWidth, m_iHeight);<br />
myBitmap->LoadBitmap(IDC_STATIC_PICTURE);
I get an Unhandled exception in wingdi.cpp line 1102:
<br />
BOOL CGdiObject::Attach(HGDIOBJ hObject)<br />
{<br />
ASSERT(m_hObject == NULL);
if (hObject == NULL)<br />
return FALSE;<br />
CHandleMap* pMap = afxMapHGDIOBJ(TRUE);<br />
ASSERT(pMap != NULL);<br />
pMap->SetPermanent(m_hObject = hObject, this);<br />
return TRUE;<br />
}<br />
This is the call stack:
>mfc71d.dll!CGdiObject::Attach(void * hObject=0x0305061d) Line 1102 + 0x1c C++
mfc71d.dll!CBitmap::CreateCompatibleBitmap(CDC * pDC=0x00816af4, int nWidth=400, int nHeight=400) Line 217 + 0x25 C++
I hope you can help me again here
im79
|
|
|
|
|
im79 wrote: myBitmap->CreateCompatibleBitmap(pDC, m_iWidth, m_iHeight);
What are you trying to do here?
im79 wrote: myBitmap->LoadBitmap(IDC_STATIC_PICTURE);//picture control in my dialog
The CBitmap::LoadBitmap function is used to load an image into the bitmap, not set an image into a picture control...
|
|
|
|
|
hfry wrote: im79 wrote:
myBitmap->CreateCompatibleBitmap(pDC, m_iWidth, m_iHeight);
What are you trying to do here?
I thought that i have to convert the DIB to a DDB Bitmap, so i guess that's wrong
I just want to display the Bitmap in a picture control, but it's not as easy as i thought
hfry wrote: The CBitmap::LoadBitmap function is used to load an image into the bitmap, not set an image into a picture control...
Yes that's stupid, I should have read the MSDN manuals
|
|
|
|
|