|
Hi,
I would like to know if there is a way to copy partial memory contents(variables) from one structure to another using the memcpy function.
ie
struct TEMP{
int x;
int y;
int z;
};
I would like to copy the struct TEMP except the variable int z, to another struct TEMP?
Thanks
|
|
|
|
|
you could do : memcpy(&destStruct, &sourceStruct, sizeof(int) * 2);
but that's only good if the stuff you want to skip is on the end of the struct.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Chris Losinger wrote: you could do : memcpy(&destStruct, &sourceStruct, sizeof(int) * 2);
but that's only good if the stuff you want to skip is on the end of the struct.
It probably works but the code is not safe and portable. The only guarantee is that the first data member and the struct have the same address (no virtual functions involved).
-- modified at 5:18 Sunday 29th January, 2006
A portable solution is:
memcpy(&destStruct, &sourceStruct, offsetof (TEMP, y) + sizeof(int));
|
|
|
|
|
Hi!
I try to fill a CListBox with elements of a CList object. The elements should be listed, as soon as the dialog will be opened. So, I have to do this via "OnInitDialog". But to get access to the list elements, OnINitDialog needs one parameter in his parameterlist.
Does somebody know, how I can overwrite this function?
Thanks a lot, hanno
|
|
|
|
|
|
Hello everyone!
OK, I posted a question 1 or 2 days ago about this... I already solved that problem, but now I'm facing another one!
The problem is that the maps don't load up correctly... Here's the ObjectType enumeration:
enum ObjectType<br />
{<br />
LX_EMPTY,<br />
<br />
L1_GRASS,<br />
<br />
L2_ROCK,<br />
<br />
L3_TELEPORTER,<br />
};
Here's some previous declarations needed to understand the troublesome methods:
<br />
#define WIDTH 512<br />
<br />
#define HEIGHT 384<br />
<br />
#define CHARW 32<br />
<br />
#define CHARH 32<br />
<br />
SDL_Surface ** mapLayerTiles;<br />
<br />
ObjectType mapLayers[3][WIDTH*HEIGHT];<br />
<br />
SDL_Surface * screen;<br />
Here's the method that loads the map layers:
void Mazzee::GetMapInfo(std::string map)<br />
{<br />
FILE * f[3] = {<br />
fopen((map + ".ml1").c_str(), "rt"), <br />
fopen((map + ".ml2").c_str(), "rt"), <br />
fopen((map + ".ml3").c_str(), "rt")<br />
};<br />
<br />
<br />
for (int x = 0; x < 3; x++)<br />
{<br />
if (f[x] == NULL)<br />
exit(1);<br />
}<br />
<br />
<br />
for (int x = 0; x < 3; x++)<br />
{<br />
int p = 0;<br />
while (p < (WIDTH/32)*(HEIGHT/32))<br />
{<br />
<br />
if (feof(f[x]))<br />
return;<br />
<br />
char v = fgetc(f[x]);<br />
<br />
<br />
switch (v)<br />
{<br />
case '.':<br />
this->mapLayers[x][p] = LX_EMPTY;<br />
++p;<br />
break;<br />
<br />
case '|':<br />
this->mapLayers[x][p] = L1_GRASS;<br />
++p;<br />
break;<br />
<br />
case 'o':<br />
this->mapLayers[x][p] = L2_ROCK;<br />
++p;<br />
break;<br />
<br />
case 'T':<br />
this->mapLayers[x][p] = L3_TELEPORTER;<br />
++p;<br />
break;<br />
<br />
<br />
}<br />
}<br />
<br />
<br />
fclose(f[x]);<br />
}<br />
}
And here's the method that displays the map on the screen:
void Mazzee::DrawMap()<br />
{<br />
for (int x = 0; x < (WIDTH); x += CHARW)<br />
{<br />
for (int y = 0; y < (HEIGHT); y += CHARH)<br />
{<br />
for (int v = 0; v < 3; v++)<br />
{<br />
SDL_Rect src, dest;<br />
<br />
if (v == 0)<br />
{<br />
if (this->mapLayers[v][(x/32)*(y/32)] == LX_EMPTY) src.x = 0;<br />
else if (this->mapLayers[v][(x/32)*(y/32)] == L1_GRASS) src.x = 32;<br />
}<br />
else if (v == 1)<br />
{<br />
if (this->mapLayers[v][(x/32)*(y/32)] == LX_EMPTY) src.x = 0;<br />
else if (this->mapLayers[v][(x/32)*(y/32)] == L2_ROCK) src.x = 32;<br />
}<br />
else if (v == 2)<br />
{<br />
if (this->mapLayers[v][(x/32)*(y/32)] == LX_EMPTY) src.x = 0;<br />
else if (this->mapLayers[v][(x/32)*(y/32)] == L3_TELEPORTER) src.x = 32;<br />
}<br />
<br />
src.y = 0;<br />
src.h = CHARH;<br />
src.w = CHARW;<br />
<br />
dest.x = x;<br />
dest.y = y;<br />
dest.h = CHARH;<br />
dest.w = CHARW;<br />
<br />
SDL_BlitSurface(this->mapLayerTiles[v], &src, this->screen, &dest);<br />
}<br />
}<br />
}<br />
}
Here's the map files:
<br />
map1.ml1:<br />
...............<br />
...............<br />
...|...........<br />
...............<br />
...............<br />
...............<br />
...............<br />
.........|.....<br />
...|...........<br />
...............<br />
...............<br />
...............<br />
<br />
map1.ml2:<br />
o.............o<br />
...............<br />
...............<br />
...............<br />
..............<br />
...............<br />
...............<br />
...............<br />
...............<br />
...............<br />
...............<br />
o.............o<br />
<br />
map1.ml3:<br />
...............<br />
...............<br />
..T............<br />
...............<br />
...............<br />
...............<br />
...............<br />
...............<br />
...............<br />
...............<br />
............T..<br />
...............<br />
Sorry for making it long... Thanks!
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
Hi all!
I used the Chris Maunder's Systray code to implement a systray with a popup menu, but i can't figure how to set a subitem checked!
I used the SetMenuItemChecked but it failed!!
I cant go on with this!! And i can't use Chris' classes with these stuffs too because they are for Mfc projects (mine is not mfc) !!
HELP ME PLEASE!!! (
---
|
|
|
|
|
|
You mean putting ON_UPDATE_COMMAND_UI as a switched case of the main dialog msg?
Like this?
case WM_INITDIALOG:
{
....
break;
}
case ON_UPDATE_COMMAND_UI:
{
//What to do here??
break;
}
---
|
|
|
|
|
|
Hi,
How can i find the selected row and read the cell values with mouse click event using the MS DataGrid v6 ActiveX Control ?
Regardsm
sdancer75
|
|
|
|
|
Hi all
Can any one post a sample source code for counting the number of children excluding the grand children in a particular node in a Tree
Lovekesh
|
|
|
|
|
If I understand your question correctly you want to count the immediate children of a node. If this is the case code like this should do it:
UINT Count = 0;
HTREEITEM hItem = m_Tree.GetChildItem(hRootItem);
while (hItem != NULL)
{
++Count;
HTREEITEM hNextItem = m_Tree.GetNextSiblingItem(hItem);
}
NOTE: I haven't actually tried this! Assumes you're using MFC (although it is easily adaptable if you're not).
Steve
|
|
|
|
|
Hi steven
the above code is not working
the while loop is iterating continously and it is not at all terminating
can u suggest me why it is happening
-- modified at 9:57 Saturday 28th January, 2006
|
|
|
|
|
Oops, it should look like this:
UINT Count = 0;
HTREEITEM hItem = m_Tree.GetChildItem(hRootItem);
while (hItem != NULL)
{
++Count;
hItem = m_Tree.GetNextSiblingItem(hItem);
}
Steve
|
|
|
|
|
Hi stephen
I ve written another code for my problem it works for me
but if i want to retreive the child including its children
and to retreive parent of a child
how the code willbe look like
-- modified at 4:13 Sunday 29th January, 2006
|
|
|
|
|
I want a MDI app withOUT a menu, any menu.
With a SDI all I have to do is override PreCreateWindow() as follows:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.hMenu = NULL; // no menu
return CFrameWnd::PreCreateWindow(cs);
}
This will not work for MDI (vs. SDI). Any ideas?
|
|
|
|
|
In the app after mainframe creation
m_poMainFrame->SetMenu(NULL);
In a custom CMdiClient intercept and eat
ON_MESSAGE(WM_MDISETMENU , OnMDISetMenu )
ON_MESSAGE(WM_MDIREFRESHMENU, OnMDIRefreshMenu)
|
|
|
|
|
HI joey Bloggs!
thank you for your reply!
i add the SetMenu(NULL).it works!@thank you very much,
but still has problems..
I add the micros to the ChildFrame as you metioned manually(there isn't WM_MDISETMENU message in my class wizard of VC6)as follow:
in the childfrm.cpp:
BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
ON_MESSAGE(WM_MDISETMENU , OnMDISetMenu )
ON_MESSAGE(WM_MDIREFRESHMENU, OnMDIRefreshMenu)
END_MESSAGE_MAP()
and int the childfrm.h i add :
afx_msg void OnMDIRefreshMenu();
afx_msg void OnMDISetMenu();
but int the functions OnMDISetMenu() and OnMDIRefreshMenu(),it can't receive the message WM_MDISETMENU and WM_MDIREFRESHMENU!
could you explain it detailedly?
thanks a lot!
|
|
|
|
|
It's not ChildFrame it's MDIClient that you need to customise
class CMdiClient : public CWnd<br />
{<br />
.<br />
.<br />
.<br />
afx_msg LRESULT OnMDIMaximize (WPARAM wParam, LPARAM lParam);<br />
afx_msg LRESULT OnMDIRestore (WPARAM wParam, LPARAM lParam);<br />
afx_msg LRESULT OnMDISetMenu (WPARAM wParam, LPARAM lParam);<br />
afx_msg LRESULT OnMDIRefreshMenu(WPARAM wParam, LPARAM lParam);<br />
}
Then make CMdiClient a member of MainFrame and subclass it in the create
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)<br />
{<br />
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)<br />
{ <br />
return -1;<br />
}<br />
<br />
if (!m_oMdiClient.SubclassWindow(m_hWndMDIClient))<br />
{<br />
MYTRACE(_T("Failed to subclass MDI client window\n"));<br />
return -1;
}<br />
-- modified at 1:53 Tuesday 11th April, 2006
|
|
|
|
|
Hai,
I am struggling, not able to put IStream object into IDataObject.Here is the code snippet.I get error at set data line as Access Violation.Pls help me
LPDATAOBJECT pDO ;
FORMATETC fmtetc = {0};
fmtetc.cfFormat = CF_TEXT;
fmtetc.dwAspect = DVASPECT_CONTENT;
fmtetc.lindex = -1;
fmtetc.tymed = TYMED_ISTREAM;
fmtetc.ptd = NULL;
//STGMEDIUM definition
STGMEDIUM medium = {TYMED_ISTREAM,NULL,NULL};
medium.tymed = TYMED_ISTREAM;
medium.pstm->AddRef();
//error in this line during execution
pDO->SetData(&fmtetc,&medium,TRUE);
Saravana Kumar
|
|
|
|
|
saravana pandy wrote: STGMEDIUM medium = {TYMED_ISTREAM,NULL,NULL};
medium.tymed = TYMED_ISTREAM;
medium.pstm->AddRef();
Where is pstm set - It should be a pointer to a stream. I would think this code would crash when you call AddRef as you're calling it on a NULL pointer.
Steve
|
|
|
|
|
Yes the progam crashes at that point.
How to set the pointer to the Stream.
If i give the pointer to the stream it throws error as
'initializing' : cannot convert from 'struct IStream' to 'struct HBITMAP__ *'
I just give like this:
LPSTREAM lpStream = NULL;
.
.//Write some data into stream
.
STGMEDIUM medium = {TYMED_ISTREAM,lpStream,NULL};
medium.pstm = lpStream;
Saravana Kumar
-- modified at 7:23 Saturday 28th January, 2006
|
|
|
|
|
Here's how I'd do it:
STGMEDIUM medium;
medium.tymed = TYMED_ISTREAM;
medium.u.pstm = lpStream;
lpStream->AddRef();
medium.pUnkForRelease = NULL;
Steve
|
|
|
|
|
Hai stephen,
Thanks for reply.
Wht is that medium.u.pstm?
I dnt get any thing called medium.u
Instead i set value as
medium.pstm = lpStream
lpStream->AddRef();
It gives me the same exception as access violation at
LPDATAOBJECT pDO;
FORMATETC fmtetc = {0};
fmtetc.cfFormat = CF_TEXT;
fmtetc.dwAspect = DVASPECT_CONTENT;
fmtetc.lindex = -1;
fmtetc.tymed = TYMED_ISTREAM;
fmtetc.ptd = NULL;
//Access violation exception 0xC0000005
pDO->SetData(&fmtetc,&medium,TRUE);
Can u please point out where i am going wrong?
Thanks for ur help.
Saravana Kumar
|
|
|
|