|
thank's a lot, it works perfect now
regards,
patrick
|
|
|
|
|
I'm pretty new to C++, but this seems weird.
I have written a program just to practice working with CListCtrl. All it does is load the list with a few lines
of stuff (in 3 columns). Then I set some extended styles (select whole line and track select). Then when
the column header is clicked, it sorts the list on that column and puts a little bitmap in the header
to show which column is sorted and whether ascending or descending.
The weird part is this: in one version of the program, it works perfectly in the Release version, but in
the Debug version everytime it gets to the .GetItem line for the CHeaderCtrl it gives me an
"Unhandled exception... Access violation..." error. I couldn't figure out how to fix that, so I started
from scratch on a new project and made the same program (cut and paste some code that seems OK).
In that version of the program the Debug compile works perfectly, but the Release version does not. In the
Release version of the second try, when I click on the column header, the headers actually disappear,
the column widths are screwed up (very wide) and the line items are all jumbled and some parts missing.
The "sort" seems to work OK in all versions, so I don't think that is the snag. It seems to be in the
"getting" and "setting" of the CHeaderCtrl items.
I know this is pretty vague, but any ideas? What the heck is going on? More to the point, what can
I do to figure it out and fix it?
Thanks for any suggestions. David.
|
|
|
|
|
Check that your zero-initializing your structures (LVITEM, etc.).
--Mike--
http://home.inreach.com/mdunn/
The Signature, back by popular demand: Buffy. Pajamas.
|
|
|
|
|
Ahhh, ha ha haaaa! I feel like an idiot.
Actually, it turns out that what makes it work correctly is to set the .mask, .fmt, and .iImage members
before calling GetItem.
I completely forgot that the .mask tells the function which parameters to get. It just seems to me that
the GetItem should get all of the parameters, but that is just me. It still seems odd that I have to
set the .fmt and .iImage parameters as well BEFORE calling GetItem. If I don't, then both of those
parameters get set to weird and useless values by GetItem.
I do still have a problem though. Even if I set the .mask to include the HDI_TEXT flag, the pszText
parameter still does not contain a string after the GetItem call (I set a watch in debug to monitor
that). I have yet to see a valid string in the pszText after the GetItem call. So how do I find out
what the text is in that item of the CHeaderCtrl? Let's say for sake of argument that I wanted to
change the text of the header when the user clicks, but I want different headers to have different
text based on existing text (for example, so say "ascending" or "descending" for the sort order).
I would have to be able to read the existing text to know what I want to changed to. I can't seem
to get at the existing text (without storing in a separate variable which just seems stupid to me).
Thank you SO MUCH for your answer. It put me on the right track.
David.
|
|
|
|
|
It just seems to me that the GetItem should get all of the parameters, but that is just me.
The reason there's a mask is so that the control doesn't return info that you don't want or care about.
Even if I set the .mask to include the HDI_TEXT flag, the pszText parameter still does not contain a string after the GetItem call.
Are you setting the cchTextMax member too? You need to set this to tell the control how big of a buffer you have.
--Mike--
http://home.inreach.com/mdunn/
The Signature, back by popular demand: Buffy. Pajamas.
|
|
|
|
|
Aaarghh! I don't think I'm an idiot, but I'll reserve judgement on that.
First off, thank you very much for you input. I appreciate it.
However, it still isn't working out for me. Therefore, I will include the code and you can tell me where I
am going wrong. Here's the code:
void CLVTest3Dlg::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
////Try to retrieve the Text in the column header
//Need pointer to the CHeaderCtrl.
CHeaderCtrl* pHeader = m_LV.GetHeaderCtrl();
//Find out which column header was clicked
int nDx = pNMListView->iSubItem;
//Set up the HDITEM struc
HDITEM hdi; //passes info to/from HeaderCtrl
hdi.pszText = " ";
hdi.cchTextMax = 255;
hdi.mask |= HDI_TEXT;
hdi.fmt |= HDF_STRING;
//Get info from the Header
pHeader->GetItem(nDx, &hdi);
*pResult = 0;
}
It's a Dialog-based MFC program. I have included OLE Automation (because I thought I read somewhere
that if you are going to use the CListCtrl::SetBkImage function it had to enabled (yes? no?)).
Anyway, I've tried just about every permutation of hdi settings I can think of. I keep getting an
unhandled access violation. What is the trick I'm missing here?
Many thanks in advance. David.
|
|
|
|
|
hdi.pszText = " ";
You're passing in a 2-character buffer here. You need to declare a char array and pass that.
char szText[255];
hdi.pszText = szText;
--Mike--
http://home.inreach.com/mdunn/
Tables, ladders, chairs, OH MY!
|
|
|
|
|
AAH!
Obviously, it never occurred to me. Thanks a bunch.
BTW, I personally really appreciate that there are guys who clearly know what they are doing
out there willing to answer assinine questions like this, and without even being insulting
or condescending. That's really excellent. So thank you (and that goes for several other
of the names I see so often on these boards).
Thanks. David.
|
|
|
|
|
|
How make CBitmap from CLongBinary?
|
|
|
|
|
I use ActiveX componet microsoft winsock ver 6
Mycode is
Server:
VARIANT NewMemberPackage;
NewMemberPackage.vt = VT_BSTR;
NewMemberPackage.bstrVal = MyPacked.AllocSysString();
m_winsockmember.SendData(NewMemberPackage);
----------------------------------------------------------------
Client:
VARIANT mPackage;
VARIANT menumType;
VARIANT mmaxLength;
mPackage.vt = VT_BYREF|VT_BSTR;
menumType.vt = VT_UI1;
menumType.bVal = VT_BSTR;
mmaxLength.vt = VT_I4;
mmaxLength.iVal = 512;
m_WinsockConnect.GetData(&mPackage, menumType, mmaxLength);
---------------------------------------------------------------------
In client is wrong but I can't found information about this Component in my country. How I Programming VC++ Code In Client. Helpme Please
|
|
|
|
|
Hi. I am trying to finish this code for an address book using a struct. Can someone please correct my code. If anyone wishes to help please run the program and you will see what my problem is.
After the user makes an entry (with choice 1), it should be able to display (with choice 2). My display function is not working. I am not doing something right. I need help with that, please, anyone ! Also, if the user enters more than one entry, the display function should display these entries one at a time. The user will hit enter to display the next entry. And so forth. Here is my code:
const char FILENAME[80] = "C:\\MS Visual C++\\Programs\\AddressBooktest.dat";
struct addresstype
{
char lastname[21];
char firstname[21];
char line1[31], line2[31], line3[31], line4[31];
char phone[14];
};
int menu();
void add_to_address_book(struct addresstype &);
void output_info(struct addresstype &, ofstream &);
void input_info(struct addresstype &);
void display_address_book(struct addresstype);
void main()
{
struct addresstype addin;
int choice=0;
ofstream outfile;
outfile.open(FILENAME, ios::out);
if(outfile.fail())
{
cout<<endl;
cout<<filename<<"="" could="" not="" be="" opened="" for="" output."<<endl;=""
cout<<"the="" file="" might="" corrupted."<<endl;=""
exit(1);=""
}=""
else=""
{=""
while(choice!="3)"
choice="menu();"
if(choice=""> 3)
{
system("cls");
cout<<"\t\t" << "INVALID ENTRY"<<endl<<endl<<endl;
}=""
else=""
{=""
switch(choice)=""
case="" 1:="" add_to_address_book(addin);=""
output_info(addin,="" outfile);=""
break;=""
case="" 2:=""
input_info(addin);=""
display_address_book(addin);=""
outfile.close();=""
int="" menu()=""
int="" choice="0;"
cout<<endl<<endl;=""
cout<<"\t\t"="" <<="" "what="" do="" you="" want="" to="" do?"<<endl<<endl;="" "1.="" add="" an="" entry"<<endl;="" "2.="" display="" entries"<<endl;="" "3.="" exit"<<endl;=""
cout<<endl<<endl<<endl;="" "enter="" your="" (1,="" 2="" or="" 3):="" ";=""
cin="">>choice;
return choice;
}
void add_to_address_book(addresstype& addin)
{
system("cls");
cout<<endl<<endl;
cin.ignore(100,="" '\n');=""
cout<<"\t\t"="" <<="" "last="" name:="" ";=""
cin.get(addin.lastname,="" 21,=""
cin.ignore(100,="" "first=""
cin.get(addin.firstname,="" "address="" line="" 1:=""
cin.get(addin.line1,="" 31,="" 2:=""
cin.get(addin.line2,="" 3:=""
cin.get(addin.line3,="" 4:=""
cin.get(addin.line4,="" "telephone="" number:=""
cin.get(addin.phone,="" 14,=""
system("cls");=""
}=""
void="" output_info(addresstype&="" addin,="" ofstream&="" outfile)=""
{=""
outfile<<addin.lastname="" "#"=""
<<addin.firstname=""
<<addin.line1=""
<<addin.line2=""
<<addin.line3=""
<<addin.line4=""
<<addin.phone="" endl;="" input_info(addresstype="" &addin)=""
ifstream="" infile;=""
infile.open(filename,="" ios::in);=""
if(infile.fail())=""
cout<<endl;=""
cout<<filename<<"="" could="" not="" be="" opened="" for="" writing="" into."<<endl;=""
cout<<"the="" file="" might="" corrupted."<<endl;=""
exit(1);=""
infile.get(addin.lastname,="" '#');=""
infile.ignore(1);=""
infile.get(addin.firstname,=""
infile="">> addin.line1;
infile.ignore(1);
infile >> addin.line2;
infile.ignore(1);
infile >> addin.line3;
infile.ignore(1);
infile >> addin.line3;
infile.ignore(1);
infile >> addin.phone;
infile.ignore(100, '\n');
}
void display_address_book(addresstype addin)
{
system("cls");
cout<<"All the entries are:"<
|
|
|
|
|
You people have seen games like RedAlert, Starcraft etc, the way we have a little window into a large map. We can scroll that window to shift our focus to other regions of the map. I want to know how that is possible in MFC? I need a view that only looks at part of the whole "world", and then I want to be able to scroll to other parts without disturbing the underlying "world".
Here's what I have in mind. The world will be a square with 6000 miles sides. I want to see, maybe, a 50 x 50 mile area through my view. So when the view scrolls I see a new portion of the world.
I want to be able to make changes in the world(like change the (x,y) of a car) (without dealing with device coords), and the view updates at regular intervals to show the change(if the view is positioned above an area where a change took place).
Someone help me!
|
|
|
|
|
Two things:
1/ If you're writing a game, you'll want to use DirectX, not just GDI/MFC.
2/ This sort of view is easy to achieve. You keep track of the whole world, and what it is doing, and remember the top left point you are at - then only try to draw things within the 50 x 50 box that is built from it, and compensate for these values when drawing. i.e. if I have an 800x600 screen ( you'd have to draw 600x600 to maintain aspect ratio - option bars on the edges ? ) and I am at point 1000/500, I draw anything between 1000/500 and 1050/550. I subtract 1000 from all X values and 500 from all Y values before I draw, and scale by 12 in both directions to go from 50 to 600. BTW, if you need to divide for any conversions you should multiply by a float, multiplication is faster than division.
As for your little view, again it's a case of taking the point clicked on, normalising it ( making it's top left edge 0,0 and moving the other points so the size is unchanged ) and then getting a co-ordinate by scaling betwen the size of the scanner box and the size of your world.
Christian
I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in.
The early bird may get the worm, but it's the second mouse that gets the cheese.
|
|
|
|
|
>> 1/ If you're writing a game, you'll want to use DirectX, not just GDI/MFC.
OpenGL is another option also. For simple things, OpenGL is easier to pick up than DirectX. But if you're in it for the long run, DirectX will offer more flexibility at the expense of a high learning curve.
- Pros
|
|
|
|
|
I don't think it's that simple - Quake is/are written using GL, after all. I agree with the curve thing - I got GL working in less time than it took me to figure how to get DirectX started. But I presume that a RTS game will use an isometric view, which makes DX a better option, because you can use Direct Draw instead of having to create and draw 3D objects, and given that you'd use Direct Sound/ Direct Input anyhow, it seemed the way to go in this case. But it was remiss of me not to mention GL, all the same.
Christian
I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in.
The early bird may get the worm, but it's the second mouse that gets the cheese.
|
|
|
|
|
Was this reply meant for someone else. My problem is an address book. Not a game!
What does this have to do with my qustion???
|
|
|
|
|
I've noticed this forum mixing things up a little - your reply has appeared in the thread 'A window into a big world', where I answered a question relating to games such as Red Alert.
Christian
I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in.
The early bird may get the worm, but it's the second mouse that gets the cheese.
|
|
|
|
|
The answer you have already gotten is a good one, I think. However, since you expressly asked
if it could be done in MFC, I figured I would toss in here that it can.
I don't want to sound like a commercial, but there is a book called "Beginning Visual C++" from
Wrox Press written by Ivor Horton that contains an example of a sketch program that imcorporates
multiple views and scaling of the views. It sounds like a solution to what you want to do here.
I have the book and learned a lot from it (but I am a beginner). You may want to check it out.
The crux of it is multiple CViews of the CDocument. You then set your scale modes.
I hope that helps. David.
|
|
|
|
|
I store an exe image in my program as a resource,then I load this block in the memory but now I want to execute this exe block wihout need to write it in exe file
|
|
|
|
|
As far as I know you cannot do that.
What you can do is create a temporary file for the .exe with the FILE_FLAG_DELETE_ON_CLOSE flag:
search in MSDN for FILE_FLAG_DELETE_ON_CLOSE and Jeffrey Richter's Win32 Q&A Januari 1998.
This makes sure the file is deleted after all the refering handles are closed.
What you also could try is experimenting with the Win32 API call WriteProcessMemory...
Best regards.
--------------------------------------------------
If my messages appear curt, I apologize.
I try to be brief to save your time as well as mine.
--------------------------------------------------
|
|
|
|
|
I'm using WriteFile, CopyFile and so on... and creating an application that has to work without mouse and without some keyboard combinations (Alt+tab...).
if during the operation of copying files to the disk the user removes the disk, a lot of messages pop up and I would like to avoid this.
Could you help me?
Thank you in advance...
|
|
|
|
|
Excerpt from WriteFile documentation:
"If you are attempting to write to a floppy drive that does not have a floppy disk, the system displays a message box prompting the user to retry the operation. To prevent the system from displaying this message box, call the SetErrorMode function with SEM_NOOPENFILEERRORBOX."
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hello All,
How to convert a variant, which is returned by vb dll that
actually contains a adodb.recordset, to recordet in vc++?
I casted it to IDispatch and to Recordset. But always I'm not getting
records. If I used recordcount, it's returning only -1.
Advance thanks for ur reply.
regards,
ramesh
|
|
|
|
|
You can convert the IDispatch to a _RecordsetPtr.
//mycontrol.h
_RecordsetPtr m_pRS;
//mycontrol.cpp
STDMETHODIMP CMeCTable::put_DataSource(IDispatch *newVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
if (m_pRS == NULL)
m_pRS = NULL;
HRESULT hr = newVal->QueryInterface(__uuidof(_RecordsetPtr), (void**)&m_pRS);
if FAILED(hr)
{
return E_FAIL;
}
}
|
|
|
|
|