|
Well, what seems odd, is that, let's say I derive a control from CStatic (or make a custom control.) In my OnPaint handler, I have the code below, and it works fine! So it's not a problem with CString or Set/GetWindowText, or TextOut. It does make me wonder what a CStatic (or Windows static) control could possibly be doing that is messing this up??
<br />
CPaintDC dc(this);<br />
<br />
CString str;<br />
CRect rect;<br />
<br />
GetWindowText(str);<br />
GetWindowRect(&rect);<br />
<br />
CSize textSize = dc.GetTextExtent(str);<br />
<br />
int x, y;<br />
x = rect.Width() / 2 - textSize.cx / 2;<br />
y = rect.Height() / 2 - textSize.cy / 2;<br />
<br />
dc.SetBkMode(TRANSPARENT);<br />
dc.SelectObject((CFont *)GetFont());<br />
dc.TextOut(x, y, str);<br />
The early bird may get the worm, but the second mouse gets the cheese.
|
|
|
|
|
Hi...
just few simple questions:
1. how do u call an application in your VC++ project? e.g. I want to call real player.exe in my project.. what's the command?
2. What's the command to copy one file? e.g. I wanna copy pic.bmp to c:/image/pic.bmp
3. How do I know what's my current working directory?
Thanks a LOT....
|
|
|
|
|
|
1- CreateProcess();
2- CopyFile()
3- GetCurrentDirectory();
Cheers
Carlos Antollini.
Today is Friday!!! for All!!!
|
|
|
|
|
MSDN has all these functions, although these types of functions are typically Windows API, and not wrapped in any way by MFC.
For running a process, there are a couple others:
1. ShellExecute: it is nice if you have a program's date (e.g., a RealPlayer file) and want the system to find the app that handles it.
2. CreateProcess: if you want full control over creation, but it is probably the most complicated of the ways to run a program.
The early bird may get the worm, but the second mouse gets the cheese.
|
|
|
|
|
I have a property sheet, and one property page (CFirstPage). m_showInfo is a bool, and m_ctrShowInfo is the DDX control for the checkbox. I want to initialise the property page with the current settings.
In my implementation file;
CFirstPage::CFirstPage() : CPropertyPage(CFirstPage::IDD)
{
if(m_showInfo)
m_ctrShowInfo.SetCheck(1);
else
m_ctrShowInfo.SetCheck(0);
}
If i use SetState() instead, everything goes well. However, SetCheck() crashes at CButton::SetCheck. Any ideas why?
---
"Transmit in all known frequencies and in all known langauges, including Welsh."
|
|
|
|
|
because m_ctrShowInfo isn't a "window" yet, and SetCheck is sending a window message.
try setting this in your InitDialog
-c
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Argh! My head is hurting. All this MFC i've been doing has reduced my potential lifespan. I actually figured it out whilst watching neighbours, but thanks anyway.
---
"Transmit in all known frequencies and in all known langauges, including Welsh."
|
|
|
|
|
Look into the declaration of m_ctrShowInfo Is a CButton or another thing?
Best Regards!!!
Carlos Antollini.
Today is Fridad!!! for All!!!
|
|
|
|
|
Look into the declaration of m_ctrShowInfo Is a CButton or another thing?
But the problem is that you are in the contructor of your class, and the control have not HWND yet.....
Best Regards!!!
Carlos Antollini.
Today is Fridad!!! for All!!!
|
|
|
|
|
Try to do that in the InitDialog. In that instance the Hwnd exists
Best Regards!!!
Carlos Antollini.
Today is Friday!!! for All!!!
|
|
|
|
|
The app that I am making has this sucken in look where all the controls are at. I tried changing the windows style in this function, but that didn't work. I am trying to get rid of the sunken in look and make the whole area where the controls are located raised up with the rest of the app.
I sure appreciate any help.
|
|
|
|
|
Two questions:
(1) Is your app MDI or SDI?
(2) What kind of view you are using to display controls?
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
The app is SDI and I am using IDD_MFC_FORM.
|
|
|
|
|
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.style = WS_OVERLAPPEDWINDOW;
return TRUE;
}
I thought by adding the OVERLAPPEDWINDOW would fix this problem, but it does not seem to do it.
|
|
|
|
|
No, I guess WS_OVERLAPPEDWINDOW style bit is already set for MFC frame windows before ::PreCreateWindows() gets the hit, so this won't help.
I think I have a solution, I'll come back soon.
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
Here is a quick solution for you.
Overide CMainFrame's ::ReCalcLayout() and add this
void CMainFrame::RecalcLayout(BOOL bNotify)
{
CFrameWnd::RecalcLayout(bNotify);
CView* pView = GetActiveView();
if(pView && pView->GetSafeHwnd())
{
CRect rect;
pView->GetWindowRect(rect);
ScreenToClient(rect);
rect.InflateRect(2, 2);
pView->MoveWindow(rect);
}
}
This would take out the client edges nicely provided that you don't have any controlbars docked on the frame.
This is a quick and dirty solution. There could be other ways of doing this. I'll try to find other solution later.
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
Nice!!! This worked like a charm! Thank you for taking the time on this problem!
|
|
|
|
|
Here's part of my code:
void CValidateurlDlg::OnButton1()
{
...
for(int i=0;i<m_purllist->GetCount();i++)
{
...
ValUrlMgr.Validate(this, url);
}
}
void CValidateUrlMgr::Validate(CWnd* pWnd, Url UrlInfo)
{
THREADPARMS* ptp = new THREADPARMS;
ptp->UrlInfo = UrlInfo;
ptp->pWnd = pWnd;
ptp->pCriticalSection = &m_cs;
ptp->pEvent = &m_event;
CWinThread* pThread = AfxBeginThread (ThreadFunc, ptp,
THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
::DuplicateHandle (GetCurrentProcess (),
pThread->m_hThread, GetCurrentProcess (), &m_hThread,
0, FALSE, DUPLICATE_SAME_ACCESS);
pThread->ResumeThread ();
}
//////////////////////////
UINT ThreadFunc(LPVOID pParam)
{
...
THREADPARMS* ptp = (THREADPARMS*) pParam;
Url UrlInfo = ptp->UrlInfo;
CCriticalSection* pCriticalSection = ptp->pCriticalSection;
CEvent* pKillEvent = ptp->pEvent;
CWnd* pWnd = ptp->pWnd;
delete ptp;
pCriticalSection->Lock ();
Doing some stuff....
pCriticalSection->Unlock ();
return 0;
}
If I dont comment the Lock() / Unlock() lines, I get an Unhandled error message. Not using them = works great! What's the use of critical sections then???
thanks!
|
|
|
|
|
This may have nothing to do with your problem, but have you taken into account that CCriticalSection s by default are locked right after construction? Maybe you'll have to add m_cs.Unlock() somewhere on the ctor for CValidateUrlMgr . If this is already known to you, excuse my guessing around.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
I did not know that (thanks for the tip!), but I tried what you suggested with no good results. Although I have to say that I launch multiple instances of the same thread (look at my code), so I wonder if it's not failing when the thread function gets executed the 2nd time...
I'm sorta new to threads, just trying to figure out how they work...
Thanks again!
|
|
|
|
|
Guess more context is needed to help you find the problem. For instance, are you sure that CValidateurDlg exits only when all threads launched by OnButton1 have terminated? The m_hThread variable suggest you only keep track of the last thread launched.
Joaquñin M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
This doesn't really answer your question, but here's the basics of a little class that can be used for simple locks:
CX_Lock::CX_Lock(CRITICAL_SECTION *cs){
EnterCriticalSection(cs);
m_pCriticalSection = cs;
}
CX_Lock::~CX_Lock(){
LeaveCriticalSection(m_pCriticalSection);
}
Now, for a class whose, say, accessor functions should be guarded, declare a member CS:
CRITICAL_SECTION m_cs;
And don't forget to call InitializeCriticalSection(&m_cs); in the constructor and DeleteCriticalSection(&m_cs); in the destructor.
Then inside a block of code in a memeber fn you just declare a local lock object like so:
DWORD MyClass::GetMyMemberVar()
{
CX_Lock lock(&m_cs);
return m_dwMyMemberVar;
}
And voila, you've serialized thread access to the code in the block where the lock object has scope.
This has the advantages of exception safety (unwinding the stack will call the lock's dtor and exit the CS) and less code to muck with.
As an additional nice touch, declare the default ctor private (so people will use the class properly).
Not sure where I stumbled on this - I thought the MFC had an equivalent, but not sure.
|
|
|
|
|
Try out locking with the primitives:
CRITICAL_SECTION lock;
in the ctor: ::InitializeCriticalSection(&lock);
locking: ::EnterCriticalSection(&lock);
unlocking: ::LeaveCriticalSection(&lock);
in the dtor: ::DeleteCriticalSection(&lock);
I often heard about porblems with MFC-sync-Classes.
mfg HintiFlo
|
|
|
|
|
How to set a bitmap as a dialog background ?
Thanx.
|
|
|
|