|
|
I'm creating a custom control which creates a child header control to display column headings. I'm wondering how tall to make the header control. I looked at GetSystemMetrics(), but couldn't find one that seemed appropriate. Currently, I just defaulted to using the horizontal scroll bar height from GetSystemMetrics(), but was wondering if there was a more correct method.
Any ideas?
|
|
|
|
|
I would give it a default height to begin with, but make it self adjusting to fit the text size. For a default height I would set it to the same height as the default font. Infact to calculte it I would use the same method as creating a font size
int lfheight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
|
|
|
|
|
basing it on the font size sounds like a good approach. it should probably be a little larger than the font height, though, to allow for a little space and the borders drawn by the control.
Thanks!
|
|
|
|
|
Hi ,
I am facing a problem.
In my MFC application I have to check whether serial port is in Plugged/Unplugged status.
Any method for finding it?
any window message or event for knowing serial port status?
Thanx in advance
|
|
|
|
|
Hello.
There are status signals you can test, such as DSR (Data Set Ready) and CTS (Clear To Send) (Provided you did set RTS (Request To Send) high first).
If there are a device connectoed to the port, those staus signals should indicate the port is connected to a powered on device.
But in my experience, the status signals aren't 100% trustworthy when the serial port is unplugged. What's worse, it seems as their state depends on the hardware.
So the best way to find out, is to send some kind of status question to the device, then wait for an answer. If you get an answer, it's definately plugged in.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
hi, is there anybody who know let a CEdit control(child of CView) setfocus in a simple SDI program when program startup.
I define CEdit control in my CView(.h file) like "CEdit m_edtContent", then in my CView's cpp file's create function, call like m_endContent.Create(....).
But when the program startup, every time, i must click the CEdit first, then it will be focused, so can anybody tell me i don't need to click it, but let the program to setfocus my CEdit control.
thanks.
|
|
|
|
|
use SetFocus(...)
Good Luck.
Uday kiran
|
|
|
|
|
it's complex, only use SetFocus can't succeed
|
|
|
|
|
hwndEdit=CreateWindow ("EDIT","Anshuman",WS_CHILD|WS_VISIBL|WS_BORDER,10,10,80,20,hWnd,(HMENU)IDC_EDIT1,hInst,NULL);
SetFocus (hwndEdit); // Call at last to set the focus.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
tried this method several times at many different places, such as when created, when updated, or in InitInstance, can't success. don't know what's the problem
|
|
|
|
|
Call it immediatly before exiting your OnInit function. If that doesn't work look through your code for any other instances of SetFocus , maybe you are setting it but it is later being stolen.
|
|
|
|
|
On way is using CEdit::Setfocus in overridden OnActivateView()
|
|
|
|
|
|
I don't know what's the reason, but i called m_edtContent.SetFocus in my overridden OnActivateView(), are you OK in your side, thanks for your help.
|
|
|
|
|
its failing ? Is it giving some ASSERT or just not doing what its intended to do?
Have you suppressed its base class call ? You need to do that.
It would just look like this,
void CSDIView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
m_edtContent.SetFocus();
}
|
|
|
|
|
yes, really thanks for your help, it succeeds when i call like "CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
m_edtContent.SetFocus();"
but not if i call like"
m_edtContent.SetFocus();
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
".
it's really very good, but after i quit the program, it will say "The exception Breakpoint, A breakpoint has been reached."
|
|
|
|
|
ikohl wrote: CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
tries to set foucs on view itself. In your case its not needed.
|
|
|
|
|
yes, it's ok in sdi program, except for can't focus previous program when this program quits.
but for mdi program, there's an error box will jump out when quit this program.
really thanks for your help, you're a kind man.
|
|
|
|
|
Actually, problem was you can't use SetFocus unless that window ,parent window is visible.
OnActivateView is one place where you can achieve this. You can use its parameters for certain checks.
Other place I feel is overriding WM_SHOWWINDOW, but it will get called once.
You can look for such messages and use SetFocus there.
|
|
|
|
|
ok, i will review it, really thanks for your help
|
|
|
|
|
hi all,
I want a part of program/code ie., the USB reading alone in a separate thread so that it doesnt block the main functions/code which is a continuous process.
How can I do it?
Can anyone help/suggestions ...with code snippets please?
Thanks in advance.
|
|
|
|
|
Look up the _beginthread and the _beginthreadex CRT functions of if you're using MFC check out the CWinThread class and the AfxBeginThread global function. Make sure you link to the multithreaded libraries.
Steve
|
|
|
|
|
do u have any example programs or any relevant code snippet that would help me understand it better.
where to call the Afxbeginthread..etc?
iam using MFC for the first time. so am in the learning curve now.
|
|
|
|
|
// The thread.
class CMyThread : public CWinThread
{
public:
DECLARE_DYNCREATE(CMyThread)
CMyThread()
{
m_Data = 0;
}
virtual BOOL InitInstance() { return TRUE; }
virtual int Run() // Do work in here!!!!
{
// Do some work!
while (++m_Data < 1000) {}
return 0;
}
private:
int m_Data;
};
IMPLEMENT_DYNCREATE(CMyThread, CWinThread)
// To start the thread.
AfxBeginThread(RUNTIME_CLASS(CMyThread));
// ------------------------- //
There are many ways to skin a cat however. Using <code>_beginthread</code> is probably easier.
Steve
|
|
|
|