|
Or even easier to understand:
int count =m_List.GetItemCount();
for (int i=0;i<count;i++)
{
}
m_List.DeleteAllItems();
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
You should start using the MSDN documentation to learn about the classes you are implementing. Had you done so you would surely have found this[^].
I must get a clever new signature for 2011.
|
|
|
|
|
Note that reversing the loop
for (int i = count-1; i >= 0; i--)
{
m_List.DeleteItem(i);
}
would solve you problem.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
int count = m_List.GetItemCount();
for (int i = count - 1;i >= 0; i--)
{
m_List.DeleteItem(i);
}
if you delete item from a list, you should delete it from the last to the first.
|
|
|
|
|
Facing an uphill batte against OpenGL vs. Vista/Win7 ...
Seems we cannot use GDI to BitBlt to do a screenshot when Aero is turned on.
Reading a lot on the web (opengl.org,gamedev.net, ...) about this, it looks like I need to use glReadPixels to get the RGB(A) values from the OpenGL buffer.
The issue is that I'm not certain how to transfer the resulting pixel array ( RGB(A) ) to something that Windows can use.
glPushAttrib(GL_PIXEL_MODE_BIT);
glReadBuffer(GL_FRONT);
glFlush();
glFinish();
unsigned char *glBuffer = new unsigned char [width*height*4];
ASSERT( glBuffer) ;
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, glBuffer);
unsigned char* Buffer = new unsigned char [width*height*3];
unsigned char* ptmp = Buffer;
unsigned char* pbuffer = glBuffer;
for (int j=0; j<height; j++)
{
for (int i=0;i<width; i++)
{
*ptmp++ = *pbuffer++;
*ptmp++ = *pbuffer++;
*ptmp++ = *pbuffer++;
pbuffer++;
}
}
delete [] glBuffer;
HBITMAP hBitmap= ::CreateBitmap(width, height, 3, 24, Buffer);
ASSERT( hBitmap);
The array returns by glReadPixels looks ok, but creating the bitmap returns a NULL handle; at first, even if it did not work, I half expected to have a corrupted bitmap, but not just a NULL.
I'm certainly missing a lot of things, but I'm not certain what; probably mixing up context and some things ... all that I can find is that people say use glReadPixels and it works!
Any idea ?
Thanks.
Max.
Watched code never compiles.
|
|
|
|
|
I think the number of planes is supposed to be 1.
HBITMAP hBitmap= ::CreateBitmap(width, height, 1, 24, Buffer);
ASSERT( hBitmap);
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Hi,
I am taking string ("Tom & Harry") from resource. In some system it is displaying like "Tom _ Harry" and some system it is fine "Tim & Harry"?
What is the problem? Please guide....
|
|
|
|
|
It sounds like the problem is where you're displaying it. If you using it in menus the & character is used the include an accelerator key. If this is the case use two &s.
Steve
|
|
|
|
|
If I remember correcly, the "&" will mark the following letter as the mnemonic (the underlined letter in the menu).
Resources strings for UI need to have "&&" : "Tom && Jerry'
(look at the documentation).
Watched code never compiles.
|
|
|
|
|
I’m trying to use ImageMagick for what I believed would be a simple task.
I want to generate a dimmed version of an image/icon at runtime in the application.
I use the magick++ c plus api.
I have found some commands that give me an ok result when run from the command line.
Converting the commands to the c++ api was a bit challenging, and the result is then not as hoped.
// Command example
convert -size 32x32 xc:"#999999" gray32.png
composite -dissolve 50% logo32.png gray32.png dim_logo32.png
How would this look in c++?
I came up with this.
Magick::Image gray;
gray.size( Magick::Geometry(image.columns(), image.rows()));
gray.read( "xc:#999999");
gray.label( "gray" );
if(gray.isValid()) {
gray.opacity(QuantumRange/2);
image.composite(gray, Magick::Geometry(image.columns(),image.rows()), Magick::DissolveCompositeOp );
But the transparency in the picture is lost.
A other suggestion as to make a dimmed image, is to make the full image semi transparent.
convert input.png -channel Alpha -evaluate Set 50% output.png
This could work. The transparency is kept when I tried this from command line.
Changing this to c++ api confused me a lot.
I ended up with this single line.
image.opacity(QuantumRange/ 2);
Now the result from this confuses me. The image is semi transparent, but the background that was originally transparent is now magenta.
orginal icon
dimmed icon
|
|
|
|
|
Thue Andersen wrote: Now the result from this confuses me. The image is semi transparent, but the background that was originally transparent is now magenta.
i suspect you've set the entire alpha channel to 128, not just reduced the exiting alpha by 1/2.
|
|
|
|
|
Aside from the transperency in the alpha channel, one pixel value can be chosen as fully transparent. This is often chosen to be magenta (R=255, G=0, B=255, A=255).
Now that you have modified the alpha component of every pixel, what was previously (R=255, G=0, B=255, A=255), is now (R=255, G=0, B=255, A=128). It's no longer recognised as fully transparent and instead treated as magenta at half transperency.
So to solve your problem, you'd have to either exclude the magenta (R=255, G=0, B=255, A=255) pixels from having their transperency halved or change the transparent pixel value to be (R=255, G=0, B=255, A=128).
modified on Friday, January 14, 2011 6:04 PM
modified 13-Sep-18 21:01pm.
|
|
|
|
|
So imagemagick internally uses magenta as transparent colour?
And when I changed the opacity of the whole image it also applied this for the transparent colour.
The two suggested solutions sound interesting,
I have tried to implement solution two.
image.opacity(MaxRGB / 2);
Magick::Color color(MaxRGB, 0, MaxRGB, MaxRGB / 2);
image.transparent(color);
But why is this exstra step necessary? In the command line we just set 50% alpha and done.
Would there be a better solution to create a dimmed icon?
|
|
|
|
|
Not an answer to your question, but what i don't understand is:
Why not render the dimmed icon offline (with the commandline) and read this icon in, during runtime? I guess you don't create icons in runtime on the fly, so what is the use to create a dimmed version in runtime?
|
|
|
|
|
Because the icons are defined by the end-user.
The system allows end-user to save his own icons into the database. To simplify this task he only has to provide one version of the icon, and we will generate the dimmed version automatically.
|
|
|
|
|
In the below code, I am attempting to count the number of letters and number of words in a phrase. In researching the return values of isalpha(), I noted that when a letter is present the first character isalpha() output is 1. But the second character isalpha() output is 2? The phrase that was input into this example was the following: How do you organize? Can someone help me with why I am not getting uniform output for the "H" character and the "o" character?
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int ch;
float avg = 0;
int spaces = 0;
int letters = 0;
int test = 0;
int ltrcnt = 0;
int spccnt = 0;
while((ch = getchar()) != '\n')
{
test = isalpha(ch);
if(isalpha(ch) == 2)
{
ltrcnt++;
}
if(isspace(ch) == 8)
{
spccnt++;
}
}
printf("The Number Of Words Are %d , The Number Of Letters Are %d ",(spccnt+1),ltrcnt);
}
|
|
|
|
|
isalpha returns zero if the given character is not an alphabet.
Returns non-zero if it is alphabet.
And may return '1' if the alphabet is of upper case, and '2' if it is lower case.
|
|
|
|
|
Yes, note the following defines from ctype.h
#define _UPPER 0x1 /* upper case letter */
#define _LOWER 0x2 /* lower case letter */
#define _DIGIT 0x4 /* digit[0-9] */
#define _SPACE 0x8 /* tab, carriage return, newline, */
#define _PUNCT 0x10 /* punctuation character */
#define _CONTROL 0x20 /* control character */
#define _BLANK 0x40 /* space char */
#define _HEX 0x80 /* hexadecimal digit */
#define _LEADBYTE 0x8000 /* multibyte leadbyte */
#define _ALPHA (0x0100|_UPPER|_LOWER) /* alphabetic character */
|
|
|
|
|
Andrew,
Ahh,
Thank you for directing me to the defines. Since I am an newbie, I have never looked in the header file. Thank you for the answer as well.
|
|
|
|
|
And you don't have to look there, what matters is the documentation: isalpha return a boolean result, either zero or non-zero; since the different non-zero values are not documented, you should not rely on them. Nor on any observation you may make, not in a .h file and not when running a test app.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Cool_Dev,
Thank you for the answer.
|
|
|
|
|
You should familiarise yourself with the MSDN pages[^]; they contain a wealth of useful information.
I must get a clever new signature for 2011.
|
|
|
|
|
Here is a sample code which works just fine:
#include <stdio.h>
#include <windows.h>
#define malloc(s) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, s)
#define free(m) HeapFree(GetProcessHeap(), 0, m)
#pragma warning(disable: 4996)
wchar_t *test()
{
wchar_t aaa[] = L"aaaa,bbbb,cccc,dddd";
static wchar_t *lol = (wchar_t *)malloc(sizeof(wchar_t *) * wcslen(aaa) + 1);
wcscpy(lol, aaa);
return lol;
}
int main(int argc, char **argv)
{
wchar_t *t;
int i;
wchar_t *stuff = test();
t = wcstok(stuff, L",");
for(i = 0; t; t = wcstok(NULL, L","), i++)
{
wprintf(L"::%s\n", t);
}
return 0
}
This prints
::aaaa
::bbbb
::cccc
::dddd
Now, here is sample code which just dont work and i got no idea why. Its a wcstok inside of wcstok loop.
#include <windows.h>
#include <stdio.h>
#define malloc(s) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, s)
#define free(m) HeapFree(GetProcessHeap(), 0, m)
#pragma warning(disable: 4996)
wchar_t *test()
{
wchar_t aaa[] = L"aaaa,bbbb,cccc,dddd";
static wchar_t *lol = (wchar_t *)malloc(sizeof(wchar_t *) * wcslen(aaa) + 1);
wcscpy(lol, aaa);
return lol;
}
wchar_t *lolz(wchar_t *lol)
{
int i = 2;
static wchar_t *stuff = (wchar_t *)malloc(sizeof(wchar_t *) * (wcslen(lol) + MAX_PATH)*i);
wcscpy(stuff, L" ");
while(i > 0)
{
wcscat(stuff, lol);
wcscat(stuff, L",");
i--;
}
return stuff;
}
int main(int argc, char **argv)
{
wchar_t *t;
int i;
wchar_t *stuff = test();
t = wcstok(stuff, L",");
for(i = 0; t; t = wcstok(NULL, L","), i++)
{
wprintf(L"::%s\n", t);
wchar_t *get = lolz(t);
wchar_t *t2;
int i2;
t2 = wcstok(get, L",");
for(i2 = 0; t2; t2 = wcstok(NULL, L","), i2++)
{
wprintf(L":%s\n", t2);
}
wprintf(L"End for: %s [%d]\n\n", t, i);
}
return 0;
}
this should print:
::aaaa
:aaaa
:aaaa
end for aaaa
::bbbb
:bbbb
:bbbb
end for bbbb
You can see from the code, like, for each main tokens it should get subtokens, but it prints only:
::aaaa
:aaaa
:aaaa
end for aaaa
and thats it. Why? thanks
011011010110000101100011011010000110100101101110
0110010101110011
modified on Thursday, January 13, 2011 10:19 AM
|
|
|
|
|
Did you try to use your debugger to see what's happening ?
Also, please use the code tags when pasting code, because it is very difficult to read right now.
|
|
|
|
|
Have wrapped the code with tags but it is all red now...
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|