|
Redeemer-dk wrote:
anyone know what's wrong?
Yes, and so does the MSDN documentation:
Note that all I/O buffers must be sector aligned (aligned on addresses in memory that are integer multiples of the volume's sector size), even if the disk device is opened without the FILE_FLAG_NO_BUFFERING flag.
|
|
|
|
|
I program an app that uses a treeCtrl, and I use the tv_item::lParam save an address of an item in std::list. Code like this:
std::list<MyStruct> items;
....
std::list<MyStruct>::iterator pCur = items.begin();
TVM_INSERTITEM tvi;
tvi.item.mask = TVIF_TEXT | TVIF_PARAM...
tvi.item.lParam = &(*pCur);
....
TreeView_InsertItem(hTree, &tvi);
....
when I retrive an item of the tree and its MyStruct:
MyStruct* pMyStruct;
TV_ITEM item;
item.mask = TVIF_TEXT|TVIF_PARAM...
TreeView_GetItem(hTree, &item);
pMyStruct = (MyStruct*)item.lParam;
Now, the pMyStruct is not equal the &(*pCur) above.
How can I prohibit STL alter its items' addresses?
|
|
|
|
|
hmm, just wild guess, looking on the code excerpt, I would expect the problem lays in a definition:
std::list<MyStruct> items;
the stl actually creates a copy of your item, because this definition says keep a list of MyStruct instances. And as stl works, they keep a copy of your structures. Benefit is that the instances will be destroyed together with the list.
Better then is the definition like this:
std::list<MyStruct*> items;
this will keep the pointers, so they should remain the same (their content). Disadvantage of this method - when releasing the list, only the pointers will be cleared, but not the structure instances (possible memory leaks)
or even better is to use some kind of auto_ptr (I use CAutoPtr from ATL), this have a benefit, that all the structures are released when the list is cleared, but no whole-structure-copying overhead.
|
|
|
|
|
I found some code on MSDN which loads jpegs and put it into my program with a little modification. I have a jpeg loaded into dialog which is part of a tab control. From the resource editor I drew the outline of the picture and gave it a border and I thought that the actual painting should be done through a WM_CTLCOLORSTATIC message. The picture loads fine with some exceptions. When I switch tabs the picture disappears and never comes back until I reopen the dialog. If I click outside the window to hide it under some other program I might be running (eg. Iexplorer) and bring it back the picture is gone for good also. Here is the code:
<br />
case WM_CTLCOLORSTATIC:<br />
iStaticWindow = GetWindowLong( (HWND) lParam, GWL_ID );<br />
<br />
switch(iStaticWindow)<br />
{<br />
case IDC_PICTURE:<br />
hDC = GetDC(hwndPicture);<br />
<br />
if (gpPicture)<br />
{<br />
long hmWidth;<br />
long hmHeight;<br />
<br />
gpPicture->get_Width(&hmWidth);<br />
gpPicture->get_Height(&hmHeight);<br />
<br />
int nWidth = MulDiv(hmWidth, GetDeviceCaps(hDC, LOGPIXELSX), HIMETRIC_INCH);<br />
int nHeight = MulDiv(hmHeight, GetDeviceCaps(hDC, LOGPIXELSY), HIMETRIC_INCH);<br />
<br />
RECT rcDlg;<br />
GetClientRect(hDlg, &rcDlg);<br />
<br />
RECT rc;<br />
GetWindowRect(hwndPicture, &rc);<br />
<br />
MoveWindow(hwndPicture, rcDlg.right - (nWidth + 4), 11,<br />
nWidth + 3, nHeight + 3, TRUE);<br />
<br />
gpPicture->Render(hDC, 0, 0, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, &rc);<br />
<br />
}<br />
<br />
ReleaseDC(hwndPicture, hDC);<br />
<br />
return TRUE;<br />
<br />
case IDC_CONTROL1:<br />
case IDC_CONTROL2:<br />
SetTextColor( (HDC) wParam, RGB(0, 0, 0));<br />
SetBkColor( (HDC) wParam, RGB(170, 170, 213) );<br />
<br />
return (BOOL) hControlBrush;<br />
After playing around with it I noticed that I don't have these problems if I remove the switch statement but I need that in order to take care of the other static controls. I also noticed that if I get rid of the MoveWindow function then the picture never gets drawn in the first place. One last peculiarity to mention: In the resource editor if I don't use a modal or a static frame for the picture window (which I chose enhanced metafile) then the picture gets drawn at the top left corner of the screen (entirely outside the window). If anyone can help me I would appreciate it. This also includes sending me to places to learn about painting because it is obvious I know nothing about it. Thanks in advance.
|
|
|
|
|
I'm not master of painting, but I would stick with the painting code to the WM_PAINT message - this you receive allways, when something needs to be repainted (part of window, whole window...). Don't know if and how to handle it is with dialogs, but normally in windows everything needs to be repainted againg and again when something is drawn over it (another window). For that is there the WM_PAINT message (one of the parameters is the rectangle needed to be repainted, then you do not need to repaint the whole window allways)
For reference of the GDI and other window stuff, there is a good book from Charles Petzold (ISBN:157231995X). Haven't read it personally (as I am not working with GUI much), but the references are quite good.
|
|
|
|
|
Hi all,
I have a vc problem which i am unable to think of a solution. so can anyone help ??
i have a data type as follow:
typedef struct complextag
{
double dRe;
double dIm;
} COMPLEX;
and i have 3 classes which need this data type. (main class, class A and class B). The main class will have to interact with class A and class B and pass a COMPLEX variable to them.
Hence i have put the "typedef struct complextag" in the class A and class B header. I also include the class A and class B header in class main.
However when i compile the program, vc complaint of this "error C2011: 'complextag': 'struct type redefinition'
is there a way to solve this prob ?? or is there a way to make the COMPLEX data type to be universal like "int" or "float" ???
Thank you very much for the kind attention.
|
|
|
|
|
One way ( I am sure there are others ) is to wrap the declaration in an #define macro. That way it will not get redeclared.
#ifndef I_ALREADY_DEFINED_THIS_STRUCT
#define I_ALREADY_DEFINED_THIS_STRUCT
typedef struct complextag
{
double dRe;
double dIm;
} COMPLEX;
#endif
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Put the type definition in a header file (just in case), and add #pragma once at the top of it.
|
|
|
|
|
Hi PJ Arends and .S.Rod.
Really thanx a lot for your help !!
I have used the suggested macro and it works !!
|
|
|
|
|
hi. i am writing a project in MFC and i am using GDI+ in this project. when i Execute my project.exe in another Operating System it says : mfc40...dll Not Found. the joke is that my project Size is only 300kb and the Size of all Dll that needed in project is 2 mb
is there anyway to include these Dlls in project to get rid of them or somthing to recude the Dlls Size ?
thanks.
-=Ehsan-de-Burge=-
|
|
|
|
|
-=Ehsan-de-Burge=- wrote:
is there anyway to include these Dlls in project to get rid of them or somthing to recude the Dlls Size ?
Link statically with the MFC library : Project settings, General, Link statically with MFC.
-=Ehsan-de-Burge=- wrote:
the joke is that my project Size is only 300kb and the Size of all Dll that needed in project is 2 mb
I am not sure you are going to like it when it comes to .NET. The run-time is 24MB (core run-time, without mentioning additional stuff including IE6, MDAC, ...), while your app can be a few hundreds kb only. There are so many classes in .NET that your app is likely to be small (you don't reinvent the wheel).
|
|
|
|
|
my IMvironment is Visual C++.net.in witch menu should i set this option?
|
|
|
|
|
Right-click while you are on the project item. In the General tab, change Use Of Mfc : "Use MFC in a shared dll" to "Use MFC in a static library".
|
|
|
|
|
Project menu -> Properties
On the properties pages you want to select the 'General' page. Under 'Project Defaults' you will find 'Use of MFC'. From the dropdown list select 'Use MFC in a Static Library'.
ps. be sure to select correct configuration (Debug, Release, etc.)
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Hi,
I am using visual C++ Ver.6.
I want to read form an XML document a element node by name "childNmae" that is a child of another node
whose name is "nodeName". "childNmae" a child of other nodes as well, in which I am not interested.
Using IXMLDOMDocumentPtr->getElementsByTagName("nodeName")
I get the list of nodes with the name "nodeName". A loop over nodes is made.
How do I get directly to children nodes of these nodes that their name is "childNmae" ?.
A method getElementsByTagName(...) does not exist for the IXMLDOMNode object.
I don't wnat to go through each child and check it's name.
Thanks.
|
|
|
|
|
You migh wanna take a look at selectNodes() which uses XSLT to select nodes, very handy.
For example, the following code will select all nodes with the attribute id = "3" and the path /test/yadda.
<code>
IXMLDOMElement* pElem;
pDoc->get_documentElement(&pElem);
IXMLDOMNodeList* resList;
if(SUCCEEDED(pElem->selectNodes(CComBSTR("/test/yadda[@id = \"3\"]"), &resList)))
{
long len;
if(SUCCEEDED(resList->get_length(&len)))
{
for(long n = 0; n < len; n++)
{
IXMLDOMNode* pNode;
resList->get_item(n, &pNode);
CComBSTR strXml;
pNode->get_xml(&strXml);
MessageBox(CString(strXml.m_str));
}
}
}
</code>
"You can stand all night at a redlight anywhere in town, hailing Marys left and right but none of them slow down. I've seen the best of men go past. I don't wanna be the last..."
|
|
|
|
|
Thanks. Is there a way to do it without usitng the attribute?. I want to get the child using only the name and I still don't have a way to do it.
|
|
|
|
|
nodelist = xmldoc->GetElementsByTagName("name");
hope this helps...
|
|
|
|
|
Thanks, but it doe's not help.
I would like to find in the nodelist ( returned from the call nodelist = xmldoc->GetElementsByTagName("name");) a child with the name "name1" which I don't know how to get from a node in the list.
Another solution? Thanks.
|
|
|
|
|
Just remove the attribute, i.e. "/test/yadda"
"You can stand all night at a redlight anywhere in town, hailing Marys left and right but none of them slow down. I've seen the best of men go past. I don't wanna be the last..."
|
|
|
|
|
Hi all,
I am writing my own HTTP web server that is suppose to be runnig on a computer in a network that is connected to the internet througth a router.
Now the router has been configed to send any HTTP protocal messages to the
computer with the web server. But when I try to connect to the web server througth the routers internet IP from the same computer running the server it fails to connect. Now I think that you arn't suppose to be able to connect to a local web server througth a internet ip, am I right? But then how can I test that my web server works on the internet and what about FTP servers? Any ideas on how to test if the server works with the same computer running it, without connecting to it througth it's local IP?
Aidman » over and out
|
|
|
|
|
Hi guys, I'm writing a program using database, there are some fields should be currency data type, so I used COleCurrency... but I got some problems/questions(never used COleCurrency before):
1, How do you handle negative currency value?
For example, I have a variable with value COleCurrency(0, 0), now I have to further deduct it, so its negative. And now if I want to divide it by a DWORD, its value messed up.
COleCurrency init(0, 0); // initial value is 0.00
COleCurrency refund = blahblah; // some value determined at runtime
init -= refund; // remaining value, it's negative
DWORD dwQty = 500;
COleCurrency unitPrice = init / dwQty; // now value of init becomes a mess
My observation: we cannot divide a negative COleCurrency value?
2, How do you use "SUM" to get sum of currency format field values from a table in database?
I used the following SQL to access the sum value of "dPrice" column, which is in currency format, and the table name is tblDStorage:
"SELECT SUM (dPrice) AS total_price FROM tblDStorage"
Now, on one of my PC it worked well but on another the result is always 0. Why? Both machines have same softwares installed.
3, Can you use double instead of currency to store currency values in database, if no, what's the downside of doing so, and in what case we may loss precision?
I've actually tried to use double, and all problems are gone and there has been no data loss found, but I was told that currency would be more precise for sure...
Thanks a lot for your time.
|
|
|
|
|
hi.
char buf[100];
I want to save the buffer on the file.
say, first 87 array has a character but left over has NULL.
so when I save it, also save NULL value into the file.
fputs(buf,fp);
How can I save just 87 character into the file??
thanks
|
|
|
|
|
Tomohiro wrote:
How can I save just 87 character into the file??
By using C++ instead of C. If you used an ofstream, even if you use a C style string instead of std::string, it will stream only the 87 characters you are after.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
fprintf
-c
I'm not the droid you're looking for.
|
|
|
|
|