|
Im outputing some simple text to a view using CScrollView and i encountered something that I found to be very odd. When I use this code control the size of the scrollbars it cuts off some of the text.
CRAWConversionScrollDoc* pDoc = GetDocument();<br />
ASSERT_VALID(pDoc);<br />
<br />
CRect rTextSize;<br />
rTextSize.SetRect( 0, 0, 800, 1200 );
this->GetDC()->DrawText( *(pDoc->GetConvertedData()), &rTextSize, DT_LEFT | DT_EXPANDTABS | DT_CALCRECT );<br />
<br />
CSize sizeTotal;<br />
sizeTotal.cx = rTextSize.Width();<br />
sizeTotal.cy = rTextSize.Height(); <br />
CScrollView::SetScrollSizes(MM_TEXT, sizeTotal);
however when I modify the code to proportionaly resize the scrollbars like so it works just fine
CRAWConversionScrollDoc* pDoc = GetDocument();<br />
ASSERT_VALID(pDoc);<br />
<br />
CRect rTextSize;<br />
rTextSize.SetRect( 0, 0, 800, 1200 );
this->GetDC()->DrawText( *(pDoc->GetConvertedData()), &rTextSize, DT_LEFT | DT_EXPANDTABS | DT_CALCRECT );<br />
<br />
CSize sizeTotal;<br />
sizeTotal.cx = rTextSize.Width() + ((double)rTextSize.Width()/1.6);<br />
sizeTotal.cy = rTextSize.Height() + (rTextSize.Height()/8);<br />
<br />
CScrollView::SetScrollSizes(MM_TEXT, sizeTotal)<code><br />
<br />
What im wondering is the reason for this behavior. With the modified code my text comes out properly regrardless of how much text there is be it 1 page or 50+ pages.<br />
<br />
Any help with this would be appreciated<br />
-thx
|
|
|
|
|
The code you posted will measure the text based on the default font. Are you using a different font when drawing the text?
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Yes I am using a different font, I guess I will just change the font before I measure, thx for the help
|
|
|
|
|
I have an Edit box on a dialog and check the input and arrange for it to be set to the Max or Min value if data entered is out of range.
But I get a Stack Overflow error if say I enter say 999, the routine set the input to 180 which is OK. But I now enter -999 and the stack overflow problem occurs and I dont know why.
The Event Routine on the Edit box is show below:-
#define Value_MAX 180
#define Value_MIN -180
void CDataInput::OnEnChangeValue()
{
m_cValue.GetWindowText(m_strEditValue);
m_fValue = atof(m_strEditValue.GetBuffer());
if(m_fValue > Value_MAX)
{
m_fValue = Value_MAX;
g_strNewDataStr.Format("%0.2f", m_fValue);
m_cValue.SetWindowText(g_strNewDataStr);
}
else if(m_fValue <= Value_MIN)
{
m_fValue = Value_MIN;
g_strNewDataStr.Format("%0.2f", m_fValue);
m_cValue.SetWindowText(g_strNewDataStr);
}
}
Also if I just enter -999 I get the Stack Overflow problem.
Can someone explain what I am doing wrong.
grahamfff
|
|
|
|
|
Your SetWindowText is generating another EN Change event, you never get out of the loop!
You could maybe set yourself a monitor variable, like m_bInEnChange, and if that is TRUE, don't do your own processing again!
You are probably also in trouble because you have the
else if(m_fValue <= Value_MIN)
which will always be true once you set value to Value_MIN, so you get into recursive loop.
|
|
|
|
|
Rather than validating on the EN_CHANGE notification, try using the EN_KILLFOCUS notification. With EN_CHANGE, your user will get very frustrated trying to enter a valid value. Every keypress, you will try and validate what they are entering. With EN_KILLFOCUS, you validate only when they leave the control (which implies they are ready to commit the value).
Software Zen: delete this;
|
|
|
|
|
Something else: You don't need to call m_strEditValue.GetBuffer() in your atof() function call. Just pass m_strEditValue , and the built in cast to a LPCTSTR will take care of the required conversion.
Something else #2: In other circumstances, if you have to use GetBuffer() with a CString value, make sure you call ReleaseBuffer() . This ensures that the CString manages the buffer memory correctly.
Software Zen: delete this;
|
|
|
|
|
Thanks will use OnKillFocus, works better that way.
Graham.
grahamfff
|
|
|
|
|
I tried several times to get Diablo 2's window, came up with nothing... all I need is some insite on what to do. I image it would be the same for putting a label inside it, as it is in regular windows. Am I right? If perhaps, you need more info. then please let me know, by replying...
Thanks for replying, when you do!
Programmer_4_Fu73r
|
|
|
|
|
I am studying to use the DirectDraw, have what can I help?
I come from China, is a plait distance raw recruit.My English level is badly.
|
|
|
|
|
I have a property page with 4 tabs. How do I gray out a particular tab at run time.
Similarly my application (generated from MDI Doc -View Architecture) has
the SAVE icon.
This icon is enabled throught the application.I want it to be enabled only when changes are done to my application.How do i do this.
Any suggestions please.
Thanx in advance
laiju
|
|
|
|
|
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi,
I have 2 threads that for some reason lock up and I can't figure out why. Maybe if someone could look at some of my code they can see something obviously wrong:
<br />
UINT CChildView::CaptureThread()<br />
{<br />
bool ShutterChanged = false;<br />
int saveShutter;<br />
while(!m_bTerminateThread)<br />
{<br />
if (m_bCapturePaused)<br />
{<br />
::SetEvent(m_hCapturePausedConfirm);<br />
switch(::WaitForSingleObject(m_hCaptureEvent, 5000))<br />
{<br />
case WAIT_OBJECT_0:<br />
break;
case WAIT_TIMEOUT:<br />
continue;
}<br />
}<br />
...rest of the thread<br />
Note that inside this thread I use an object which implements CCriticalSection object that I lock and unlock for each function. Both the GUI thread and this thread calls functions on this object.<br />
}<br />
Furthermore I define:<br />
inline void StartCapture()<br />
{<br />
m_bCapturePaused = FALSE;<br />
::SetEvent(m_hCaptureEvent);<br />
::ResetEvent(m_hCapturePausedConfirm);<br />
}<br />
inline void PauseCapture()<br />
{<br />
m_bCapturePaused = TRUE;<br />
::ResetEvent(m_hCaptureEvent);<br />
::WaitForSingleObject(m_hCapturePausedConfirm, INFINITE);<br />
}<br />
The problem is in the main program when the user clicks a button I want to pause the thread. The deadlock doesn't occur always. Also any runs through the debugger work, so I don't know how to solve this problem.
Thanks.
|
|
|
|
|
First, I finally found how to debug multiple threads in VC++ 6. Run in debug mode, click pause, click Debug->Threads. After I did that I immediately saw the thread executing a line CComboBox::GetCurSel(). I thought I didn't have any more GUI modification within a thread but I guess I do. I think the problem is now fixed. I guess people aren't kidding when they say don't modify the GUI from a thread.
|
|
|
|
|
I guess people aren't kidding when they say don't modify the GUI from a thread.
Don't modify the MFC GUI from a thread that did not create the MFC object - you can modify any of them from the same thread that created them, of course.
|
|
|
|
|
I need to develop a little application to send some keystrokes to the active window, something like the On Screen Keyboard. I need to know what is the window that lose the keyboard focus when the user click on a button in my application so I tried to gain a hook (a thread hook, not a global hook) so I wrote the following routine as CBT event handler:
<br />
LRESULT CALLBACK<br />
CMainFrame::CBTProc(int nCode, WPARAM wParam, LPARAM lParam)<br />
{<br />
LRESULT nResult;<br />
<br />
if (nCode == HCBT_SETFOCUS)<br />
{<br />
m_hGaining = (HWND) wParam;<br />
m_hLosing = (HWND) lParam;<br />
<br />
TRACE1("HWND Gaining: %x\n", m_hGainingFocusWnd);<br />
TRACE1("HWND Losing: %x\n", m_hLosingFocusWnd);<br />
}<br />
<br />
nResult = CallNextHookEx(m_hHook, nCode, wParam, lParam);<br />
<br />
return nResult;<br />
}<br />
The problem is that when I switch (using mouse or Alt+Tab) between my application and another one such as Notepad I got this behaviour:
Switching from Notepad to my application:
HWND Gaining: 0x50558 (the handle of my application window)
HWND Losing: 0 (NULL)
Switching from my application to Notepad:
the hook procedure don't trap anything at all
What's wrong? Why I get NULL in the first case and I don't trap nothing in the second one?
Thanks
Gaetano Sferra
|
|
|
|
|
In a call to SetWindowsHookEx(), set the last parameter as '0' This would associate hook with all the existing threads.
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Nilesh K. wrote:
In a call to SetWindowsHookEx(), set the last parameter as '0' This would associate hook with all the existing threads.
Looking into the MSDN, in the SetWindowsHookEx explaination I see the following:
lpfn
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
If I set the last parameter of the SetWindowsHookEx() (dwThradId) to 0 I cannot provide a pointer to an hook procedure that reside in the my application process as shown in my previous post, I shoud build a DLL.
My questions are:
Can I obtain a handle to the window losing the keyboard focus without use a global hook (a hook procedure in a DLL)?
Why when my application window lose the ketyboard focus the hook procedure isn't called? (It should trap a CBT event with the lParam set to the handle to my application window)
Why when my application window gain the keyboard focus I got NULL as handle to the window losing the keyboard focus? (I should get the correct handle because the CBT event destination is the my application process)
If my interpretation of MSDN or my deductions are wrong, please correct me.
Thanks
Gaetano Sferra
|
|
|
|
|
I doubt it would be possible without global hook procedure.
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Thank you Nilesh,
I will begin a DLL development to handle it.
Gaetano Sferra
|
|
|
|
|
inline float FastCosF(float value)<br />
{<br />
#ifdef Im_In_VisualStudio<br />
<br />
__asm<br />
{<br />
fld value;<br />
fcos;<br />
fstp value;<br />
}<br />
<br />
#else //in GNU compiler<br />
<br />
<br />
#endif<br />
<br />
return value;<br />
}<br />
Through googling i got this: asm ("fsin" : "=t" (value) : "0" (value));
but i don't think it works
|
|
|
|
|
which CPU are you targeting?
i think the author of that bit is assuming anyone using Visual Studio compiler is going to be making EXEs for use on Pentium (and compatible) processors. but since gcc is used on many different architectures, not just Pentiums, you can't make the same assumption - and you'll have to pick a processor(s) to write for.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Hmm i didn't consider that...shows how much i know about asm. Looks like for sake of multiplatform im just gonna have to use the built in math functions.
|
|
|
|
|
Please help me in writing a code to know whether a webcam is attached to any USB port or not? This is very urgent
Thanking you
anukampa
|
|
|
|
|
The easiest way would probably be to use the driver for that device to check it's status.
Elaine
The tigress is here
|
|
|
|