|
Hi Roger,
Thanks for the reply.
I found that the custom draw DC is the 'correct' one that gives proper proportions, while the other is the 'bad' one.
How do I get the DC from the control? I thought I was already doing it by its position in the code? I have tried
CDC* pDC = CGoalsListView::GetDC(); // with resolution operator
but that didn't work. I've tried to extract it from the
void CGoalsListView::OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
header, but I was unable to find it.
Any suggestions? Thanks! JP
Jon Paul
|
|
|
|
|
What you had was almost correct I think.
void CGoalsListView::OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVDISPINFO* pDispInfo=(NMLVDISPINFO*)pNMHDR;
*pResult=1;
CDC* pDC = GetDC();
pDC->SaveDC() ;
CFont *pFont = GetFont() ;
if (pFont != NULL)
pDC->SelectObject(pFont) ;
...
pDC->RestoreDC(-1) ;
pDC->ReleaseDC() ;
}
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
Wow! It seems to work!--Thanks! ... However, I'm not sure why. Here's the full function (to position an CEdit box on top of the List Column--except for col==0 where it positions it on top of the tabbed text).
Perhaps something between GetDC() and pDC->GetTextExtent sets up the new DC? Or perhaps the GetFont() is necessary, but I thought that GetDC() gets the font of the current DC also. Hmm... Thanks again! JP
void CGoalsListView::OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVDISPINFO* pDispInfo=(NMLVDISPINFO*)pNMHDR;
*pResult=1;
CDC* pDC = CGoalsListView::GetDC();
pDC->SaveDC();
CFont *pFont = GetFont();
if (pFont != NULL)// you can get NULL if no font has been set for the control
pDC->SelectObject(pFont) ;
CPoint posMouse;
GetCursorPos(&posMouse);
ScreenToClient(&posMouse);
LV_COLUMN lvc;
lvc.mask=LVCF_WIDTH;
CRect rcItem;
GetListCtrl().GetItemRect(pDispInfo->item.iItem,rcItem,LVIR_LABEL);
if(rcItem.PtInRect(posMouse)) {
CString tIndent = GetDocument()->GetGoalArray()->GetIndentText(pDispInfo->item.iItem);
int npixIndent = pDC->GetTextExtent(tIndent + GLV_OFFSET).cx;
TRACE2("BegLabelEdit: string='%s', npixIndent=%d\n", tIndent, npixIndent);
m_LVEdit.m_x=rcItem.left + npixIndent;
lvc.cx = rcItem.Width() - npixIndent;
m_nEdit=0;
}
int nCol=1;
while(m_nEdit==-1 && GetListCtrl().GetColumn(nCol,&lvc)) {
rcItem.left=rcItem.right;
rcItem.right+=lvc.cx;
if(rcItem.PtInRect(posMouse)) {
m_nEdit=nCol;
m_LVEdit.m_x=rcItem.left;
TRACE1("BegLabelEdit: rcItem.left=%d\n", rcItem.left);
}
nCol++;
}
if(m_nEdit==-1)
return;
HWND hWnd=(HWND)SendMessage(LVM_GETEDITCONTROL);
ASSERT(hWnd!=NULL);
VERIFY(m_LVEdit.SubclassWindow(hWnd));
m_LVEdit.m_y=rcItem.top-1;
m_LVEdit.LimitText(50);
m_LVEdit.SetWindowText(GetDocument()->GetGoalArray()->GetItemColText(pDispInfo->item.iItem , m_nEdit));
m_LVEdit.m_cx = lvc.cx;
m_LVEdit.m_cy = rcItem.Height();
ReleaseDC(pDC);
*pResult=0;
}
Jon Paul
|
|
|
|
|
Im doing a simple non-MFC application.. I need to convert an ASCII string into an OLECHAR array. I want to pass my string into a SysAllocString(); function call like this:
<br />
char string[] = "ASCII STRING";<br />
(t+f)->str = SysAllocString(string);<br />
Of course this doesnt work because, SysAllocString is expecting an OLECHAR FAR*. The function works fine when I do:
<br />
(t+f)->str = SysAllocString(OLESTR("Test String"));<br />
Im actually passing in an array of UDTypes with variable length strings from VB and populating each element of the array / structure.
Im not very familiar with this whole ATL/COM string stuff.. =) Ill be honest, Im a C programmer, so Im out of my element. What can I do.. Please Help.
Ryan Baillargeon
Software Specialist
Fuel Cell Technologies Inc.
|
|
|
|
|
USES_CONVERSION;
char string[] = "ASCII STRING";
(t+f)->str = SysAllocString(A2CW(string));
This should do the trick. Make sure to include atlbase.h
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Thank you so much..
(i had tried to use the a2ole macro before, but could noit find information on which library it was in, or how to implement it..
THANK YOU ....
Ryan Baillargeon
Software Specialist
Fuel Cell Technologies Inc.
|
|
|
|
|
You're welcomed. Btw, where do u live in Canada? Me, I live and work in Hull, near Ottawa.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Any XP theme gurus please help me to know how to find the task bar color in the current theme? I don't even know where to look at
I have never wasted time worrying about such insignificant things. Keep your eye upon the donut and NOT upon the hole. - Bill Sergio about posting in the right forum. The Lounge - June 23, 2002
|
|
|
|
|
Checkout the SystemParametersInfo and the GetSysColor
functions. They control how windows ui stuff works and looks.
|
|
|
|
|
Is there a way to self terminate an application after a period of time.
Thanks
|
|
|
|
|
Do a PostMessage with WM_CLOSE - PostMessage(WM_CLOSE, 0 , 0)
|
|
|
|
|
use a CTimer for the "period of time" and then ... exit(0);
~RaGE();
|
|
|
|
|
main()
{
Sleep(TIME);
exit(0);
}
/Magnus
|
|
|
|
|
Now that is what I call a usefull program!
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
Sure. Zillions.
Here's a frighteningly unfriendly way; it hangs a sword of Damocles over
the process:
~~~~~
// the basic killer thread
DWORD WINAPI _MySleeper(LPVOID msWaitPeriod)
{
Sleep((DWORD)msWaitPeriod);
TerminateProcess(GetCurrentProcess(),0);
return 0;
}
// hang the sword
DWORD ThreadId;
DWORD ms=10*1000; // 10 seconds
CloseHandle(CreateThread(0,0,_MySleeper,(LPVOID)ms,0,&ThreadId));
~~~~~
Now that process has 10 seconds to live.
It'll suffer a brutal death, probably leaving leaving lots of
open resources improperly closed.
Better to just set a flag, and post a quit message during idle
or something.
|
|
|
|
|
I am having a problem getting intellisense to work with the header files for my libraries. I thought that all you needed to do was add an include path for the location of my header files and away you go but that doesn't seem to be the case. All intellisense will recognise are macros to the standard functions such as fxd_mem_copy() which macros to memcpy(). Nothing at all is offered for my own functions eg fxd_mem_format(). I use makefile solutions to build my programs with the source files attached to the project so they are easily editable in VS.NET. Can anybody provide suggestions as to what the problem is?
Thanks for any help you can provide
Steve.
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
Steve Thresher wrote:
I am having a problem getting intellisense to work with the header files for my libraries.
Many have. Head over to nntp://microsoft.public.dotnet.languages.vc. Maybe even better, check that NG from a Google Groups search.
++luck;
|
|
|
|
|
hi,
I have two classes.
CData
CHelper.
CData has an array (CArray) of CHelper.
CHelper has a pointer to CData so that nesting is possible.
Now,how to serialize CData so that even the nested things,any number and however deep it may be ,will also be serialized and importantly,retrieved.
Does inheriting CData from CObject help or should I bear the headache of the job?
PS:I am in the middle of a project and dont have much time to experiment all by myself.
Waiting.....
|
|
|
|
|
During the output process, keep an array (using for instance std::vector ) of pointers to the CData s serialized so far. When it comes to output a CData , first check whether it's been already serialized (do a linear search on the vector), and if so write some check variable to 1 informing about this circumstance, followed by the index of the object in the vector. If the object hasn't been serialized yet, write 0 as the check variable and proceed with serialization.
On the input stage, do the opposite, constructing the vector on the fly as well.
This scheme has some weak points, like the linearity of the search for serialized objects, but this could be remedied if the need arises.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
yah,thought on similar lines but isnt tehre any built in methods to accomplish this?
|
|
|
|
|
There are serialization frameworks that do that automatically, but they are rather intrusive (esentially they require that you replace all your pointers with their own smart pointers that take care of the looping references), so I don't think it'd be a good idea to try to use them if you're in the middle of a project. The solution proposed is local (all the code is inside a function) and it is not that hard to implement.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Yes, if you use the serialization support provided in MFC, it will properly handle nested and even cross-linked objects. You need to use CObject as the base class, and add the appropriate DECLARE_SERIAL and IMPLEMENT_SERIAL macros. You also need a Serialize routine for each class.
Best regards,
John
|
|
|
|
|
I don't think MFC automatically supports serialization of linked objects. Basically it provides the barebones framework, all the work is left to the programmer. Please correct me if I'm wrong.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
MFC has complete support for serialization of linked items. I have used it for years with no problems. Internally it keeps track of which objects have already been serialized by using a map.
As long as you setup your macros correctly (DECLARE_SERIAL / IMPLEMENT_SERIAL), it handles all the details of loading and saving complicated data structures which are interlinked, even with loops of objects.
Best regards,
John
|
|
|
|
|
Oh... You were right, I've read some stuff on the subject and the mechanism actually does what you say (and in a pretty clever way.) I used to think ;FC serialization was dumber than it is.
Regards,
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|