|
I'd like to do something if a view in my MDI app loses focus to another view, but not if it loses focus to a dialog or message box. OnKillFocus gives me a pointer to the new CWnd, so is there a safe way to check if that is a CView?
thanks,
Jake
|
|
|
|
|
I think you may use pWnd->IsKindOf(RUNTIME_CLASS(CView)) - look in MSDN for that function (from CObject).
Paolo
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|
You can try this:
CWnd* m_wnd; (pointer you get from OnKillFocus)
if (m_wnd->IsKindOf(RUNTIME_CLASS(CView)))
// Its a CView
else
// Its not a CView
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
I have an OnKillFocus handler on an edit control. If the user
presses the window close ("x") button while the focus is on the
control, I would like to handle the WM_CLOSE message, however the
KillFocus message is being generated first.
How can I either determine in the OnKillFocus handler that the
user pressed the "x" button, or alternately, what message can
I handle that would occur before the KillFocus.
As a last resort, is there any way to disable the "x" button?
Thanks,
|
|
|
|
|
How can I tell which if any ports are open. I can attempt to open and close them, but that doesn't tell me if its already opened, that only tells me whether or not I can open it now (which may mean the port just does not exist)..
Thanks,
John
|
|
|
|
|
yust trace netstat -a
|
|
|
|
|
|
I have an app A, which uses CreateProcess to spawn another app B. It works fine.
I took the code from A and moved it to another app C. I thought app C would now launch app B. It does but as soon as B becomes alive it(B) causes an 'illegal instruction' and exits.
How can it be it works with app A and not C? Could you help me find possible reasons for this behaviour.
Thank You
LP
|
|
|
|
|
Hi,
in a simple application using Document/View Architecture:
In My view I have a CWnd Item, I use it to create a very special control, it work very well.
so you can see theses lines in my view definition (.h)
class CBoopView : public CView
{
[.....] //some stuff
public:
CMYSpecialControl MyControl;
[.....] //other stuff
};
//then in the cpp file i create the control itself that way
int CBoopView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CRect MyRect(10,10,200,30);
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
//for sure MyControl.Create is an override to simplify his creation
MyControl.Create(MyRect,this,1);
MyControl.ShowWindow(SW_SHOWNORMAL);
return 0;
}
in the CMYSpecialControl, derived from CWnd you can find this override on
the create function
BOOL CGraphScroll::Create(const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
return CWnd::Create(NULL,
_T(""),
WS_CHILD,
rect,
pParentWnd,
nID,
pContext);
}
Now the problem is:
MoveWindow(...) and SetWindowPos(...) did'nt work!! My special control is a CWnd so i'm supposed to be able to replace it anywhere in the parent frame(my view) but it didn't work.
I've try a lot of thing.
who control the client area of my control? his parent(My View)? himself?
It's hard to find the exact way you must create a child window in a view and how deal whit it....
thanks for help or anything who can help me to find the solution
Remi Morin
Remi.Morin@Lyrtech.com
|
|
|
|
|
Well, a view is just like any other window, nothing special from the system's point of view.
Which exactly is the problem? Can you see the child window?
Maybe you need to add the style WS_CLIPCHILDREN to the view, in PreCreateWindow(). You should be able to move/resize the child window at any time (if it's been created of course).
Paolo
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|
I can see the control at it's original position, but if I move it, it is not display anymore. In fact my special control is only able to draw himself in the first rectangle he received in the create function.
example:
MySpecialControl.Create(CRect(10,10,100,50),this,1);
this will work very well
I can see my control but when i try to move it that way:
MySpecialControl.OnNewSize(this,CRect(10,35,100,50));
OnNewSize is a member function that i have create
void CMySpecialControl::OnNewSize(CWnd *pParent,CRect MyRect)
{
//that way
MoveWindow(MyRect,TRUE);
//or that way (i have also try the two...)
SetWindowPos(pParent,
MyRect.top,
MyRect.bottom,
MyRect.Width(),
MyRect.Height(),
SWP_SHOWWINDOW)
}
Maybe there something I don't understand whit windows...
By the way I've try this
PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |=WS_CLIPCHILDREN ;
return CView::PreCreateWindow(cs);
}
nothing...
do I have to call the OnSize(UINT nType, int cx, int cy) or something like that?
thank you
Remi Morin
Remi.Morin@Lyrtech.com
|
|
|
|
|
...now it work...
i don't know why...
and I don't know why it was'nt working...
Remi Morin
Remi.Morin@Lyrtech.com
|
|
|
|
|
I am using CInternetSession, CHttpConnection, and CHttpFile to get a file
from an HTTP server.
I am having a problem though determining if the initial connection succeeded
or not. If the server is 'off' then the code seems to execute despite my
'ifs' and produces an exception. If I put the statement throwing the
exception into a try-catch, it isn't caught, and crashes the program anyway.
CInternetSession net;
CHttpConnection* http = NULL;
CHttpFile* file = NULL;
http = net.GetHttpConnection("cabadam.homeip.net");
if (http == NULL)
{
status += "Failed to connect to server!\r\n";
dlg->edit_status.SetWindowText(status);
dlg->GetDlgItem(IDC_BUTTON_CONTINUE)->EnableWindow(1);
return 1;
}
file = http->OpenRequest(CHttpConnection::HTTP_VERB_GET,"version.txt");
try
{
file->SendRequest(); //THIS STATEMENT crashes the program even though it
is inside a try catch
}
catch (CInternetException pEx)
{
status += "Failed to connect to server!\r\n";
dlg->edit_status.SetWindowText(status);
dlg->GetDlgItem(IDC_BUTTON_CONTINUE)->EnableWindow(1);
return 1;
}
I have tried several different things, but I haven't been able to figure out
how to determine if it was unable to connect with the server.
Am I doing something wrong? Or is there an easier way to do this?
Thanks!
Adam
cabadam@houston.rr.com
|
|
|
|
|
try this:
try
{
http = net.GetHttpConnection("cabadam.homeip.net");
}
catch(CInternetException *ex)
{
...failed...
ex->Delete();
}
hope this helps
|
|
|
|
|
Oh duh!!
On the catch, I had the pEx as CInternetException, not CInternetException*
That did it...
thx
Adam
cabadam@houston.rr.com
|
|
|
|
|
When I fail to define a New Class correctly, how do I remove the New Clas from the project, si I can redifine it?
Richard
|
|
|
|
|
delete the files from the file view (highlight, press delete)
delete the actual files (from Explorer)
delete your .CLW file (from Explorer). this will be regenerated the next time you launch classwiz
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I'm done building my program, but I was just wondering what DLL to include with it. Some of my friend who doesn't own VC++ have trouble running it. Please help...
|
|
|
|
|
Use the Dependency Walker program that comes with MSVC++. It'll show you all the DLLs required to run your application; it's generally a good idea to package those into your installer, and have it install the DLLs if the ones present on the user's system are older.
You don't need to package them all, mind you -- you probably won't need to add Kernel32 into your installer, for example -- but MFC/OLE/COM DLLs should definitely be packaged.
|
|
|
|
|
just a tip: if its an MFC program goto Project>Options and on the combobox change "Debug" to "Release", then choose "Link MFC in static library" instead of "Link MFC dynamically" then click ok. goto Build(or run or comile whatever it says) and click "batch build" then select "Release" and click build. it will now build ur project in a folder called "Release" in ur main project folder, so in it you will find an executable which is linked statically and should contain everything you need.
Kuniva
Want, take, have.
(oh btw, best way of learning some language is by looking at examples, start large!) :p
|
|
|
|
|
Hello.
This portion of code works perfect in an aplication that conect to Access 2000 with a DSN ODBC.
CRecordset rs;
rs.Open(CRecordset::forwardOnly,"SELECT COUNT(*) FROM mytable",CRecordset::readOnly);
short nField=0;
CString str;
rs.GetFieldValue(nField,str);
long NumRecords = atol(LPCSTR(str));
Now I am porting the aplication to works with SQL Server 2000 and this portion of code give me the error: "State:S1002,Native ,Origin:[Microsoft][ODBC SQL Server Driver] Invalid column number".
In MSDN I have found "GetFieldValue calls the ODBC API function SQLGetData. If your driver outputs the value SQL_NO_TOTAL for the actual length of the field value, GetFieldValue throws an exception. For more information about SQLGetData, see the ODBC SDK Programmer's Reference"
I don't know if this is the problem. Anybody can tell me how can I solve this problem?.
Thanks in advance.
Tomás.
|
|
|
|
|
SQL automatically makes column 0 the bookmark column (which is useless unless you're using bookmarks). Start your column numbers at 1.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Thank you Bret.
This is not the solution.
I start with 1 and the error is "The index is not valid or the field name is incorrect".
I think the problem is another but I have no idea.
Tomás
|
|
|
|
|
Are you using a snapshot or dynaset recordset?
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
I am using...
In the constructor:
m_nDefaultType = dynaset;
And to open:
rs.Open(CRecordset::forwardOnly,_T("SELECT COUNT(*) FROM mytable"),CRecordset::readOnly);
|
|
|
|
|