|
If you have a CPoint value that contains coordinate relative to dialog, then you can try this in your dialog:
CPoint p = ...;
ClientToScreen(p);
m_cMyPicture.ScreenToClient(p);
Hope it helps.
|
|
|
|
|
I am currently working on a project where I need to use a number of icons and store them in a datafile that also contains other data. I could use something like:
ICONINFO Info;
DWORD dwSize;
char Bits [5000];
char Mask [ 250];
if ( m_hIcon == (HICON)1
|| m_hIcon == NULL)
return ;
GetIconInfo (m_hIcon, &Info);
dwSize = GetBitmapBits (Info.hbmColor, 5000, Bits);
dwSize = GetBitmapBits (Info.hbmMask , 250, Mask);
I could get the icon back again by using the CreateIconIndirect routine, using the data that I extracted in the above way.
However, this results in 4096 bytes of colorbits and another 128 bytes of mask data, whereas the original .ico file is only 766 bytes! Does anyone have a better idea on how to extract the bits of the icon and put them back in another icon again?
Secondly, I would very much like to add a very simple icon editor to my program. Does anyone know of an open-source icon editor that I could include in my project?
Thanks in advance,
William
|
|
|
|
|
Engberts wrote: Does anyone have a better idea on how to extract the bits of the icon and put them back in another icon again?
If you want to preserve the database space, I think you should compress the data.
If you work with source *.ico files, you can store the content of these files.
Otherwise, if you create icons dynamically, you can try to save your HICON objects to *.ico format. For this, you can try the CxImage library available at http://www.codeproject.com/bitmap/cximage.asp[^]. With this library, you can store the icon to a memory or disk file, and then store this content to database.
Alternatively, you can use a third-party compression procedure. For instance, you can try zlib library from http://www.zlib.net[^].
|
|
|
|
|
consider a class
Class C
{
private:
int a;
int b;
};
then i write a copy constructor.
i believe copy constructor can be written in two wayz:
C& C::operator=(const C&);
void C::operator=(const C&);
In the former case, we deference by returning this* and the latter we dont return anything, so here is my question:
which one of the above is better??(in terms of efficiency)
|
|
|
|
|
The efficiency of the two does not realy differ very much. Of course, the first way comes with some additional machine instructions. It mainly depends on what you want to do with your constructor.
William
|
|
|
|
|
namaskaaram wrote: which one of the above is better??(in terms of efficiency)
I think first one is good to direct the reference correctly. As well we can give the gurantee of consistency in data.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Actually "copy constructor" is this one: C(const C & ) ;
Regarding overloading assignment operators, I think your first variant, which returns a reference, allows multiple assignments like this: a = b = c , or compact expressions like this: f(a = b) . The second one does not allow this, but is little faster because of missing return value.
-- modified at 4:24 Tuesday 20th June, 2006
|
|
|
|
|
actually i meant assignment operator overloading....sorry abt the typo! ;o)
thank u all!!!!
|
|
|
|
|
Viorel. wrote: The second one does not allow this, but is little faster because of missing return value.
You'll save 1, or maybe 2 CPU cycles. (Depending on how the compiler allocates registers, you may end up saving no cycles)
|
|
|
|
|
in fact, prefer the following operator :
C& C::operator = (const C&);
the reason to prefer this one instead of the void operator is that the user of your class will then be able to cascade the assignment operations. consider this :
int i1, i2, i3;
C c1, c2, c3;
i1 = i2 = i3 = 5;
c1 = c2 = c3 = ;
this is possible only because the operator = returns a reference to the object it has just modified...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
Yes, you're right. The rationale is that the assignment operator should behave in the same way as assignment for primitive types.
Kevin
|
|
|
|
|
namaskaaram wrote: i believe copy constructor can be written in two wayz:
That is not a copy constructor, it's an assignment operator.
|
|
|
|
|
Hi,
lets say that i have an operation that is performed on two sets of data independently,
that is the data is separable, and not related.
so, for an example;
<br />
void Function1(int *a, int *b, int *c, int count)<br />
{<br />
for(int i=0; i< count; i++)<br />
c[i] = a[i] * b[i];<br />
}<br />
I can measure the execution time using QueryPerformanceCounter.
<br />
main()<br />
{<br />
Function1(a,b,c,count);<br />
<br />
OtherFunction(...);<br />
}
My question is, now, if i want to break the function to two threads, to take advantage
of dual cpu, or dual core, how do i
1- Measure the performance of the code..
2- Determine the function has finished, or terminated
Example of an implementation that i am looking at is;
void Function2(int *a, int *b, int *c, int count)<br />
{<br />
AfxBeginThread1()
AfxBeginThread2()
}
<br />
main()<br />
{<br />
Function2(a,b,c,count);<br />
<br />
<br />
<br />
OtherFunction(...);<br />
}
Can anyone help on this?
Thanks
|
|
|
|
|
See Here[^] maybe it is some helpful to you
whitesky
|
|
|
|
|
Hi,
nice link, there's some info on how to wait for a thread to finish, but how do i time the threads?
|
|
|
|
|
Usman Ullah Sheikh wrote: // How do i block OtherFunction from executing before Function2 finishes.
Use criticalSection
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
|
|
|
|
|
Usman Ullah Sheikh wrote: // How to measure the time Function2 takes? Function2 is multithreaded.
// Time it takes for both thread to finish,
Why not you use global variables? and update it with the last process that finishes its task?
<br />
void Function2(int *a, int *b, int *c, int count)<br />
{<br />
AfxBeginThread1()
now, if the process is completed, inside the function that thread1 runs,
do your///QueryPerformanceCounter - end
AfxBeginThread2()// for data in the range of count/2 -> count
now, if the process is completed, inside the function that thread1 runs,
do your///QueryPerformanceCounter - end
}
while updating your "end" check if it has been updated by the previous process, if so, one process is already over so no need to worry, the last one you update is the resultant one. If the "end" counter is still 0, no process is yet over. So after updating it, you still need to wait. When the next process gets over it again checks if the "end" counter is 0 or not. This time it finds value inside it (since it's been updated by the previous thread) now you can be sure everything's over and 'end'- this 'start' this is the total time taken.
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
|
|
|
|
|
I think that will work! Thanks! I'll try it!
|
|
|
|
|
Surely, the Dialog will close when the Enter and ESC key down.
I know reload the PreTranslateMessage(MSG* pMsg) function can avoid the problem.
In my project, there are some other controls in the dialog, and I want the Edit controls and buttons can get the Enter/ESC command but not close the Dialog, is there any way?
I tried the OnChar(), OnCommad(), there din't work at all.
BOOL CEditDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN)
{
if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
{
if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit)))
return true;// pMsg->wParam=NULL ;
else
{
...............
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
|
|
|
|
|
if your problem is in editbox do you have ES_WANTRETURN in property edit
whitesky
|
|
|
|
|
My edit controls are single-line.
in fact, what I want is send a message to Parent window, when the focused edits/buttons get Enter/ESC key.
|
|
|
|
|
Try WM_GETDLGCODE
Regards,
FarPointer
Blog:http://farpointer.blogspot.com/
|
|
|
|
|
That's why PreTranslateMessage is not a very clean solution. Prefer the solution described in the FAQ[^]. In this way, you still have the complete flow of messages inaltered, it is just the closing of the dialog that is suppressed and you don't need to make tricks to get back your esc and enter messages when you need them.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
then, how to handle the enter/esc key for Edit control and buttons?
And seems that it doesn't enter into the OnChar() at all.
|
|
|
|
|
zeus_master wrote: And seems that it doesn't enter into the OnChar() at all.
Then your problem is elsewhere, it has nothing to do with the destruction of the dialog on enter or Esc.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|