|
printf( "%04x", 255 );
output will be
00FF
so what you want is probably
for( int i = 0; i <= 21; i++ )
{
printf( "%04x\n", i );
}
|
|
|
|
|
Thanks Archer,
Would you mind breaking the statement down for me or maybe you know of a link that would explain it to me. I appreciate your time.
|
|
|
|
|
Keep in mind that cout and printf() are not the same thing. The former is C++ while the later is C.
For a purely C++ solution, you simply need:
cout.fill('0');
cout << setw(5) << hex << i << endl;
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Personally i prefer to use printf() over cout<<
but thats a matter of personal opinion
i really dont know how to explain printf()
you can look at microsofts description if it makes any sense
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_printf.2c_.wprintf.asp
but what i can do is give you some examples and maby you can pick up on it (note i figured it out from examples)
printf( "This is a %s", "test" );
output: This is a test
printf( "This is 282 in lowercase hex %x", 282 );
output: This is 282 in lowercase hex 11a
printf( "This is 282 in uppercase hex %X", 282 );
output: This is 282 in uppercase hex 11A
printf( "I was born %02d/%02d/%02d", 11, 28, 87 );
output: I was born 11/28/87
|
|
|
|
|
HICON hIcon;
LPBYTE lpBuffer;
hIcon=dlg.GetIconHandle();
lpBuffer=(LPBYTE)::GlobalLock(hIcon);
HANDLE hUpd=BeginUpdateResource("D:\\n.exe",0);
UpdateResource((HMODULE)hUpd,
RT_ICON,MAKEINTRESOURCE(1),
MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT),
(LPBYTE)lpBuffer,
GlobalSize(hIcon));
EndUpdateResource(hUpd, FALSE);
GlobalUnlock(lpBuffer);
I'm using this code to take the icon from an exe and replace the icon in another exe, but it doesn't work. Every time lpBuffer is empty after GlobalLock. the hIcon handle is retrieved by ExtractIcon();
What am I doing wrong?
Please help!
|
|
|
|
|
I doubt you can do lpBuffer=(LPBYTE)::GlobalLock(hIcon); .
See this MSDN article[^] for more information on icons and resources. It links to a program written in C which has some code you can look at too.
Please note that the structs in the article are wrong. Look at the code in the linked project instead. I believe you will have to fill out an entire ICONDIR, as icons are stored that way (an icon can contain several images). Then the appropriate number of ICONDIRENTRYs and ICONIMAGEs. That's what's supposed to be inside the resource part.
But you are talking about replacing the icon in one exe from another one. I believe you can do the copy without too much work. Just grab a pointer to the icon resource in the source exe, and use it to update the icon entry in the other exe. I think that should work. The linked project has all the details. Good luck
--
Arigato gozaimashida!
|
|
|
|
|
Well this is my problem: How can I grab a pointer from the resource (HICON)??? I was trying to do just that by using GlobalLock().
Do you know any other way to do this???
|
|
|
|
|
Read the MSDN article. It'll tell you what you can do with an HICON (hint: GetIconInfo() and build resource data from that)
--
Arigato gozaimashida!
|
|
|
|
|
If I have the following:
struct Node
{
// various types
} *(*pNode)[7]; // ptr to a 2-dimensional array
===========================
In the ctor I have the following initialization procedure:
for(short i=0; i<7; ++i)
{
*(*(*pNode)+i) = NULL;
}
It doesn't work, and neither does various other efforts.
Later I want to do this:
**pNode = new Node;
(**pNode)->Lvl = 1;
etc.
==============================
If the array is not initialized, no object can be placed in it.
There is a reason why I DON'T want to define the pointer to the array as shown below (or something similar):
*pNode[5][7];
How can I initialized the array using the first example?
Thanks for any insight. I appreciate it.
William
Fortes in fide et opere!
|
|
|
|
|
*(*pNode)[7] is the same as :
Node* (*pNode)[7];
And reads as : a pointer to an array of 7 Node pointers.
Two pointers, two things need to be allocated.
1.
*(*pNode)[7] you have two * and an index [7]
*(*(*pNode)+i) you have three * and an index i
These don't match.
Instead use either :
*((*pNode)+i) = NULL;
or,
(*pNode)[i] = NULL;
2. for( ...
Before you can initialize pNode you have to allocate it. Remember pNode is a 'pointer ...'.
i.e.
pNode = (Node*(*)[7])calloc(7, sizeof(Node*));
Also, by using calloc you don't need to loop to initialize.
3. **pNode = new Node;
What are you trying to do ? pNode is a pointer to an array. Here you only ever access first element.
You likely want to use syntax from 1. i.e. (*pNode)[i] = new Node;
Might be able to help more if you explain the context of its use.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Thanks for responding. I appreciate it.
Yes, you are very correct that by my doing the following:
**pNode = new Node;
I am only accessing the first of 7 Nodes. But then notice the next statement:
(**pNode)->Lvl = 1;
in which I start filling in data to that first node (which happens to be my root node). Later on, through the use of the "for" statement I begin to fill in the rest of the array this way (as an example):
for(short i=1; i<limit; ++i)
for(short j=0; j<7; ++j)
{
(*(*pNode+i)+j)->Lvl = *(lvlData+j);
(*(*pNode+i)+j)->lvlNode = *(nodeData+j);
... etc.
}
=============================
Inside the Node structure, there is still a third array to which I assign data this way:
*((*(*pNode+i)+j)->nodesUp+k) = *(nodeCnt+k);
=============================
It was the initial allocating of memory to the "j" level of the array that was holding me back.
Thanks for the help. I appreciate it.
William
Fortes in fide et opere!
|
|
|
|
|
If you will kindly indulge me one more time, I forgot to mentioned that I'm using:
free(pNode);
to deallocate the memory. Is that OK, or should I do a 'delete' on the individual Nodes I dynamically created, BEFORE doing the 'free(pNode)'?
Thanks. I appreciate the use of your valuable time.
William
Fortes in fide et opere!
|
|
|
|
|
Hi,
1.) struct Node
{
// various types
} *(*pNode)[7];
this is not a ptr to a 2-dimensional array. This is an array of ptr to ptr.
To make it clearer you can rewrite it:
typedef Node **PtrPtrNode;
PtrPtrNode ppNode[7];
2.) initilalize it as follows:
for (int i = 0; i < 7; i++)
{
pNode[i] = new (Node*);
*(pNode[i]) = new Node[5];
}
3.) filling a node is done as follows:
Node* pNodeArray = NULL;
for (int i = 0; i < 7; i++)
{
pNodeArray = *(pNode[i]);
for (int j = 0; j < 5; j++)
{
pNodeArray[j].Lvl = 0;
}
}
4) releasing:
for (int i = 0; i < 7; i++)
{
delete [](*(pNode[i]));
delete pNode[i];
}
}
I didn't compile it but I hope it's 'error free'
Regards, Tomer
|
|
|
|
|
Confer Lippman's "C++ Primer", page 414 (about 3/4 down the page) under Section 8.4.3, and see his example of a two dimensional array of which I similarly used.
I can quote you my references, quote me yours.
William
Fortes in fide et opere!
|
|
|
|
|
Sorry,
I was wrong you were right
I was confused between *(*pNode)[7] and **pNode[7] which are two different things.
|
|
|
|
|
Hi,
is there a way to check an item when using InsertItem()? I'm trying to use SetCheck after InsertItem but it won't work!
How can I do that?
Thanks!
|
|
|
|
|
I have an MFC dialog based application containing several modeless dialogs.
A user has asked that one of the dialogs be multiple; i.e. the particular dialog displays data from an internal database and wants up to 5 instances of this dialog display showing various filtered views on he database.
So my question as I have all the code for managing the display dialog, can this dialog be made into an dialog array. Or are they another way extra instances of this dialog can be created.
Any suggestions for this unforeseen problem.
grahamfff
|
|
|
|
|
That is the beauty of a class. All it's data objects are self contained. So, provided it is a modeless dialog, you can create as many instances of it as you like. And yes, you can do it from an array if you want too.
|
|
|
|
|
Thanks for your post.
Just one question I can't see how to do an array of Modeless dialogs.
ANy help appreciated.
grahamfff
|
|
|
|
|
Hi to all
Recently I decided to move my application to UNICODE. All is near done (it complies and works (most of the time)) but I found a strange problem.
When I have some unicode string in for example WCHAR szTest[100] table - calling AfxMessageBox or SetWindowText on dialogs - displays unicode strings correctly.
But if I try to SetWindowText the same string into static control (or button) it shows a garbage text. Spy++ utility reports that those static controls and buttons are Unicode windows.
Any idea why it works this way?
Thanks for your time!
Irek
Check out my software at: http://www.ireksoftware.com
|
|
|
|
|
If you're using VC 6, you need to manually edit the .rc file and change the dialogs to use MS Shell Dlg as the font instead of MS Sans Serif .
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Laugh it up, fuzzball.
"That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."
-- Buffy
|
|
|
|
|
Thanks Michael - that solved the problem. I wonder why it's not mentioned even a single time in MSDN...
Very best regards!
Irek
Check out my software at: http://www.ireksoftware.com
|
|
|
|
|
Hi GURUS
Ive transfered a program from WinXP back to Win98 (VC++6,MFC)
Trying to print on the same printer I get following problem:
Code:
m_PrintDC.SetMapMode( MM_HIMETRIC );
CSize winsize = m_PrintDC.GetWindowExt();
In WinXP I get the correct size of the window in HiMetric
(about 20100x27000) but in Win98 I always get 2450 x 2450 !!
I also cannot change (SetWindowExt, SetViewportExt ) to anything.
Calling m_PrinterDC.GetMapMode() results in MM_HIMETRIC !
The GetDeviceCaps(HORZSIZE)... works fine !.
But calling LineTo() with values in the range of the devicecaps is outside WindowExt/Org so it doesnt work -
Where does this difference come from ? Is there any default in XP which I have to Set for Windows 98. (another mapping mode ?)..
pls help, -> thx !
|
|
|
|
|
i want to open a wav file and get the file from my drive c harddisk. what commands should be used to get the wav file??Thanks i really badly needed the commands.Thanksss!!!Help me out
|
|
|
|
|
http://www.wotsit.org/search.asp?page=8&s=music[^] <- This site should give you some help with that. It should give you the format of the data to read. Be careful when loading the sound data, as it could take up a lot of memory.
Joel Holdsworth
|
|
|
|