|
you need to register the control with admin rights !!! You better use for that a console window
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Anyone please help me to read write 3 differnt structure to a file...and read them searching the file....like
struct A
{
int id;
int data;
};
struct B
{
int id;
float data;
};
struct C
{
int id;
double data;
int data2
};
-----------------------------
I am a beginner
|
|
|
|
|
|
thanks...
I quickly read the article, its somewhat interesting...I need to write the different type of class..not only the one....in that case please help me ...
One more important thing is that I am not using MFC...its a pure C++ console based application
-----------------------------
I am a beginner
modified on Thursday, December 17, 2009 12:42 AM
|
|
|
|
|
|
You mean plain text? You could keep every such struct as a "section" and use an .inf file to store the values. For example, for a string value, you could use WritePrivateProfileString[^] (and there's an 'int' variant, and so on). For reading, use GetPrivateProfileString[^]. This would be plain text and readable. If you need encryption, you must take care of it.
You might as well serialize[^] your data.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
thanks a lot...but i need a file system only ...not INI file...preferably a binary file
-----------------------------
I am a beginner
|
|
|
|
|
I already gave you some code, but OK, it was incomplete.
Let's try a plain, not object oriented, C -Like approach:
#include <stdio.h>
enum SerialType
{
eTYPE_UNRECOGNIZED,
eTYPE_A,
eTYPE_B,
eTYPE_C,
eTYPES
};
struct A
{
int id;
int data;
};
struct B
{
int id;
float data;
};
struct C
{
int id;
double data;
int data2;
};
size_t getSize(SerialType st)
{
switch( st)
{
case eTYPE_A:
return sizeof(A);
case eTYPE_B:
return sizeof(B);
case eTYPE_C:
return sizeof(C);
default:
return 0;
}
}
bool store( SerialType st, void * pData, FILE * fp)
{
int type = st;
size_t size = getSize(st);
if (!fp || !pData || !size) return false;
fwrite(&type, sizeof(type), 1, fp);
fwrite(pData, size,1,fp);
return true;
}
SerialType readType( FILE * fp)
{
SerialType type;
if (!fp ) return eTYPE_UNRECOGNIZED;
if ( fread(&type, sizeof(type), 1, fp) == 0 ) return eTYPE_UNRECOGNIZED;
return type;
}
bool readData( SerialType st, void * pData, FILE * fp)
{
size_t size = getSize(st);
if ( !fp || !pData || !size ) return false;
fread(pData, size, 1, fp);
return true;
}
void main()
{
SerialType type;
A a[2];
B b;
C c1,c2;
A * pa=NULL;
B * pb=NULL;
C * pc=NULL;
a[0].data = 5;
a[0].id = 12;
a[1].data = 6;
a[1].id = 13;
b.data=25.75f;
b.id=100;
c1.data = 27;
c1.data2=35;
c1.id = 7;
c2.data=1000.372;
c2.data2=1000;
c2.id=1;
FILE * fp = fopen("data.raw", "wb");
store(eTYPE_C, &c2, fp);
store(eTYPE_A, &a[1], fp);
store(eTYPE_B, &b, fp);
store(eTYPE_A, &a[0], fp);
fclose(fp);
fp = fopen("data.raw", "rb");
while ((type=readType(fp)) != eTYPE_UNRECOGNIZED)
{
switch (type)
{
case eTYPE_A:
pa = new A();
readData(type, pa, fp);
printf("type A, id=%d, data=%d.\n", pa->id, pa->data);
delete pa;
break;
case eTYPE_B:
pb = new B();
readData(type, pb, fp);
printf("type B, id=%d, data=%g.\n", pb->id, pb->data);
delete pb;
break;
case eTYPE_C:
pc = new C();
readData(type, pc, fp);
printf("type C, id=%d, data=%g, data2=%d.\n", pc->id, pc->data, pc->data2);
delete pb;
break;
}
}
fclose(fp);
}
Please note, an object oriented approach would be better: serialization fits well into OOP paradigm (however, any attempt about left to the reader...).
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]
|
|
|
|
|
Hi
I am trying to use the theme images for the start menu in Vista. It has areas that are fully transparent (around the corners), areas that are fully opaque (for the menu items) and translucent areas for the black frame.
I tried DrawThemeBackground but the translucent areas show opaque. So basically I get either alpha 0 or alpha 255. Nothing inbetween. I looked up the image in the msstyles file (it is image #717) and it has the correct opacity values. Here's my code:
BITMAPINFO dib = {sizeof(dib)};
dib.bmiHeader.biWidth = rc.right;
dib.bmiHeader.biHeight = rc.bottom;
dib.bmiHeader.biPlanes = 1;
dib.bmiHeader.biBitCount = 32;
dib.bmiHeader.biCompression = BI_RGB;
unsigned int *bits;
HBITMAP bmp=CreateDIBSection(hdc,&dib,DIB_RGB_COLORS,(void**)&bits,NULL,0);
SelectObject(hdc,bmp);
SetDCBrushColor(hdc,0x0);
FillRect(hdc2,&rc,(HBRUSH)GetStockObject(DC_BRUSH));
DrawThemeBackground(theme,hdc,SPP_PLACESLIST,0,&rc,&rc);
I then check the alpha values in the bits array and besides couple of pixels with alpha=0 all the rest are 255.
Any ideas how to get the true opacity?
|
|
|
|
|
Did you tried AlphaBlend [^]
Величие не Бога может быть недооценена.
|
|
|
|
|
AlphaBlend will not help me. It is used for copying an image from one DC to another. I still need to get the correct alpha in the source DC somehow. And that's where the problem lies.
|
|
|
|
|
Ivo Beltchev wrote: AlphaBlend will not help me. It is used for copying an image from one DC to another. I still need to get the correct alpha in the source DC somehow. And that's where the problem lies.
If you need a code snippet to merge an alpha channel in from another bitmap, feel free to mail me.
Rozis
|
|
|
|
|
Does DrawThemeBackground touch the alpha channel of the bitmap at all? I mean, are the alpha channel values different before and after using DrawThemeBackground?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Kind of. First I fill the whole DC with 0, which is transparent black. After the call to DrawThemeBackground almost all pixels are opaque (255), except a few pixels in the corner (that make up the rounded corner). So those few pixels in the corner are not touched.
BTW, if instead of SPP_PLACESLIST I use LVP_LISTITEM+LISS_SELECTED and set the theme to "explorer", I get a translucent blue rectangle. Most pixels have alpha 179. That's the blue highlight of the listview items in Explorer. So it IS possible to get some alpha out of DrawThemeBackground . It just doesn't work with the start menu elements...
|
|
|
|
|
Odd, i would have expected it to not touch the target's alpha channel...anyways, try maybe filling the bitmap with 255s for alpha rather than zeroes (you might need to do this manually or using GDI+ for example because as far as i can remember normal GDI calls will either ignore the alpha or set it to zero) and see if anything changes. It could also be possible -althorough it would be kinda stupid- that DrawThemeBackground expects the background onto which it draws to be filled with some system-set start-menu background color...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
hi,
I'd like to know..
is it possible to run notepad.exe in my CView window?
my Cview window coule be parent window of notepad.exe?
so notepad.exe can move only inside my view window?
thanks.
|
|
|
|
|
Notepad is pretty much a wrapper on top of the edit control. Just use CEditView[^] and you have your Notepad.
|
|
|
|
|
Hi All,
I am working on a tabbed application for my current project.
In the process of development i have see that my application behaves differently if i minimize and maximize the application using the minimize/maximize application button of the window and if i minimize/maximize it by clicking the application icon on the task bar.
what happens:
In the tabbed dialog d1 for a special case i am overlaying another dialog d2 so that i can see d2 only.
if i minimize the application using the minimize button and again maximize using the button, i can see the d2 dialog.
if i click on the application icon on taskbar to minimize and again maximize, d2 dissapers and d1 shows up.
I will appreciate if any one have inputs on this issue.
Kasi
|
|
|
|
|
I hope you are calling SetActivePage( page index) and your code may need to remember which is current active page
HTH
abhi
|
|
|
|
|
Hi guys,
I'm creating a multi-threaded application using _beginthreadex() and _endthreadex() . If my thread executes correctly I call _endthreadex( 0 ) but if it doesn't I call _endthreadex( <some error code> ) . How can I capture the thread's exit code in the main thread?
Thanks.
|
|
|
|
|
|
masnu wrote: If my thread executes correctly I call _endthreadex( 0 )
Just return ing would be the best way to exit a thread.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Hi Rajesh,
I know that returning from a thread will call _endthreadex() but everything I have read says that "terminating a thread with a call to endthread or _endthreadex helps to ensure proper recovery of resources allocated for the thread". Is it safe to assume that returning will accomplish this?
Thanks,
Paul
|
|
|
|
|
Hi Paul,
masnu wrote: but everything I have read says that
The documentation is confusing (I presume you read the documentation? If there's some other source which recommends _endthreadex instead of just return ing the control, please ignore it. It's wrong). The documentation could have better been:
"Do not call _endthread() or ExitThread() or TerminateThread(), etc., on a thread that was created by a call to _beginthreadex(). That will lead to resource leak. If you have to explicitly "end" a thread that was created by _beginthreadex(), then you should only call _endthreadex(). But just returning from the function is a better alternative." (similarly, _endthread and _beginthread is a pair)
It's been explained very elaborately on the book Windows via C/C++ (and probably in a couple of other books too). I remember Dr. Joseph Newcomer had written on this too, which I'm lazy to search for now.
masnu wrote: Is it safe to assume that returning will accomplish this?
Yes! The resource cleanup will happen perfectly if you simply return the control. To conclude, there's simply no reason to call _endthreadex (or any of their akin functions that explicitly "ends" a thread) from your code. Returning the control is the best thing to do! Let me know if you need more information.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
OK, I just searched Dr. Joseph's article and it's here: http://www.flounder.com/badprogram.htm#AfxExitThread[^] (He's a man that has earned a lot of respect in the community, and he says "Doing this will result in erroneous programs").
Now it's 12.59 AM here and I better hit the bed or I'll wake up late. Good night (probably good day) to you!
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|