|
The solution described in this article doesn't use propsheets or proppages, no matter how they titled it. They just create a tab control and host child dialogs inside ('real' propsheet uses similar method). When tabs are clicked, hosted dialog is replaced by another 'page'.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hello,
I want to create my mainframe with a certain size. Right now I have overridden CMainFrame::PreCreateWindow and I set the members of the CREATESTRUCT x,y,cx and cy to hardcoded values.
I would however like to do this properly, by using AdjustWindowRect(Ex) to calculate the values for me.
The whole point is I want the client area to be of zero height, like the Visual Basic development environment used to be.
I cannot make this work. Here is my code:
BOOL COptixFrmMain::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= ~WS_MAXIMIZEBOX;
// cs.style &= ~WS_THICKFRAME;
// cs.style &= ~WS_SYSMENU;
/* These values are the ones I want!
cs.x = 0;
cs.y = 0;
cs.cx = 450;
cs.cy = 105;
*/
RECT rect;
SetRectEmpty(&rect);
rect.right = 450; // I want it to be 450 wide
::AdjustWindowRect(&rect,cs.style,TRUE);
cs.x = 0;
cs.y = 0;
cs.cx = rect.right - rect.left;
cs.cy = rect.bottom - rect.top;
cs.lpszClass = AfxRegisterWndClass(
CS_DBLCLKS, // if you need double-clicks
NULL, // no cursor (use default)
NULL, // no background brush
AfxGetApp()->LoadIcon(IDR_MAINFRAME)); // app icon
ASSERT(cs.lpszClass);
if( !SECFDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
If you look carefully, you can see that I use Objective Toolkit, and their FDI classes, but that should hardly matter in this case.
All help is appreciated!
************************
Peter Andersson
peter.andersson@dtsag.ch
|
|
|
|
|
Objective Toolkit should hardly matter. You would be surprised. We gave up on using Stingray for our projects because they had so many features we had to work around. I recently had another project that used a Stingray tree control that gave some strange runtime errors. I eventually tracked it to the fact that while I expected a NULL to be returned in some cases it was not. I took Stingray out of the picture and everything worked perfectly.
|
|
|
|
|
I think you are right. A small testprogram shows that AdjustWindowRect does not understand the StingRay tear-off menu.
However, the std MFC testprog works fine, except for not noticing the toolbar. How do I find the height of that one?
Peter
************************
Peter Andersson
peter.andersson@dtsag.ch
|
|
|
|
|
You can use the following VB Script to create a project:
Set objMSDEV = WScript.CreateObject("msdev.application")
objMSDEV.addproject "test","c:\myapp",TRUE
objMSDEV.ActiveProject.AddFile "test.cpp"objMSDEV.QuitWScript.Echo "Done"
From this I have determined that the following C++ code should also generate a project:
#include "stdafx.h"
#include <stdio.h>
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <initguid.h>
#include <comdef.h>
#include <ObjModel\appauto.h>
#include <ObjModel\appdefs.h>
#include <ObjModel\appguid.h>
#include <ObjModel\bldauto.h>
#include <ObjModel\bldguid.h>
#include <ObjModel\blddefs.h>
#include <ObjModel\textauto.h>
#include <ObjModel\textguid.h>
#include <ObjModel\textdefs.h>
#include <ObjModel\dbgauto.h>
#include <ObjModel\dbgguid.h>
#include <ObjModel\dbgdefs.h>
IApplication *pApp;
int main(int argc, char* argv[])
{
HRESULT hr = CoInitialize(NULL);
if(FAILED(hr))
{
printf("Failed to initialize the COM libraries\n");
return FALSE;
}
hr = CoCreateInstance(CLSID_Application, NULL, CLSCTX_LOCAL_SERVER, IID_IApplication, (void**)&pApp);
if(FAILED(hr))
{
printf("Failed to create an instance of MSDEV\n");
CoUninitialize();
}
CComBSTR bProjectName("project");
CComBSTR bPath("c:\\myproject");
CComBSTR bType("Application");
VARIANT_BOOL bCreateDirs=VARIANT_FALSE;
pApp->AddProject(bProjectName,bPath,bType,bCreateDirs);
pApp->Quit();
pApp=NULL;
CoUninitialize();
return 0;
}
The problem is the call to add the project generates the following error:
Debug Error!
Program: test.exe
Module:
File: i386\chkesp.c
Line: 42
The value of ESP was not properly saved accross a function call.
This is usually a result of calling a function declared with one
calling convention with a function pointer declared with a different
calling convention.
Can any body tell me what I am doing wrong?
Thanks for any help you can provide.
Steve.
|
|
|
|
|
I don't see a pApp->Release() call being made. Not sure if that's the problem though....
HTH
Jignesh
|
|
|
|
|
The error comes from the call to pApp->AddProject() so I dont get far enough to make a call to pApp->Release(), but thanks for trying.
|
|
|
|
|
I think this has something to do with IDispatch vs IUnknown - IApplication is a dual interface, so I decided to try using IDispatch::Invoke instead of calling the AddProject interface directly:
#include <stdio.h>
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <initguid.h>
#include <comdef.h>
#include <ObjModel\appauto.h>
#include <ObjModel\appdefs.h>
#include <ObjModel\appguid.h>
int main(int argc, char* argv[])
{
HRESULT hresult = CoInitialize(NULL);
if(FAILED(hresult))
{
printf("Failed to initialize the COM libraries\n");
return FALSE;
}
IUnknown FAR* punk;
IDispatch FAR* pdisp = (IDispatch FAR*)NULL;
DISPID dispid;
hresult = CoCreateInstance(CLSID_Application, NULL, CLSCTX_SERVER,
IID_IUnknown, (void FAR* FAR*)&punk);
if(FAILED(hresult))
{
printf("Failed to create an instance of MSDEV\n");
CoUninitialize();
}
hresult = punk->QueryInterface(IID_IDispatch,
(void FAR* FAR*)&pdisp);
OLECHAR FAR* szMember = L"AddProject";
hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1,
LOCALE_USER_DEFAULT, &dispid);
VARIANT varResult;
EXCEPINFO excepInfo;
unsigned int uArgErr;
DISPPARAMS dispparams;
dispparams.rgvarg = new VARIANT[4];
CComBSTR bstrProjectName("project");
CComBSTR bstrPath("c:\\myproject\\project");
CComBSTR bstrType("Application");
dispparams.rgvarg[0].vt = VT_BOOL;
dispparams.rgvarg[0].boolVal = VARIANT_TRUE;
dispparams.rgvarg[1].vt = VT_BSTR;
dispparams.rgvarg[1].bstrVal = bstrType;
dispparams.rgvarg[2].vt = VT_BSTR;
dispparams.rgvarg[2].bstrVal = bstrPath;
dispparams.rgvarg[3].vt = VT_BSTR;
dispparams.rgvarg[3].bstrVal = bstrProjectName;
dispparams.cArgs = 4;
dispparams.cNamedArgs = 0;
hresult = pdisp->Invoke(
dispid,
IID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_METHOD,
&dispparams, &varResult, &excepInfo, &uArgErr);
if(DISP_E_EXCEPTION == hresult) {
_bstr_t bt(excepInfo.bstrDescription);
printf("VC Exception: %s\n", (char*)bt);
}
szMember = L"Quit";
hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1,
LOCALE_USER_DEFAULT, &dispid);
dispparams.cArgs = 0;
hresult = pdisp->Invoke(
dispid,
IID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_METHOD,
&dispparams, &varResult, &excepInfo, &uArgErr);
pdisp->Release();
punk->Release();
delete [] dispparams.rgvarg;
CoUninitialize();
return 0;
}
Pretty ugly, but seems to work. The docs and samples for this are a bit lacking, and somebody stole borrowed my copy of Essential Com, so I don't know if this is the only way this can be done.
I guess the theory here is that the interface is intended to be invoked through IDispatch, and problems show up if parameters need to be passed when using AddProject directly.
Would appreciate if someone could verify or debunk said theory.
-----
"They put the COM in COMplicated"
|
|
|
|
|
Thankyou very much for the information.
|
|
|
|
|
I would suggest to use the #import statement on your typelibrary/dll and call COM by using the IApplicationPtr smart pointer that this import statement creates for you.
-Nick-
|
|
|
|
|
Ah! Good idea - actually, article Q247035 discusses both methods, but neither seems at first glance what I would call elegant.
Using #import, this is about the simplest I could come up with - please excuse the strange err handling...
#include "stdafx.h"
#include <atlbase.h>
#import "devshl.dll"
using namespace DSSharedObjects;
int main(int argc, char* argv[])
{
HRESULT hr = CoInitialize(NULL);
if(FAILED(hr)) {
_asm int 3;
}
DSSharedObjects::IApplicationPtr pIApp;
hr = pIApp.CreateInstance("MSDEV.Application");
if(FAILED(hr)){
_asm int 3;
}
_bstr_t bstrProjName("myproject");
_bstr_t bstrPath("e:\\project\\myproject");
_bstr_t bstrType("Application");
VARIANT_BOOL bCreateDirs = VARIANT_TRUE;
hr = pIApp->AddProject(bstrProjName, bstrPath, bstrType, bCreateDirs);
if(FAILED(hr)) {
_asm int 3;
}
pIApp->Quit();
return 0;
}
But it looks to me like this automation will be obsolete with VS.NET - I just started looking at beta 2 and there are no ObjModel headers, and no devshl.dll.
|
|
|
|
|
Thanks again for helping me with my problem. I managed to get this method working last night (this morning technically). I am now trying to figure out how to add source and header files to the project.
Steve.
|
|
|
|
|
I would like to have a simple dialog so that user could change line style (color, thickness, and dashed/solid) of my object appearance. Is there any standard dialog available in MFC of doing this?
Beginner_1
|
|
|
|
|
The closest thing you get is the color dlg. For your application you'll need to create one.
|
|
|
|
|
I started off trying to use CSocket but then read that this doesnt call the callback functions OnAccept and OnConnect, because it simulates a blocking socket. So Instead I used CAsyncSocket which is a non blocking socket. My socket now connects (to a web server if this is relevant), but still my OnConnect function just doesnt get called. (i have overriden the virtual functions with a MessageBox - code below, would REALLY appreciate some help with this:
AfxSocketInit();
if( !m_Sock.Create() )
AfxMessageBox("Failed to create!");
else
{
if( !m_Sock.Connect( "www.loucoll.ac.uk", 80 ) )
{
itoa( m_Sock.GetLastError(), Buff, 10 );
AfxMessageBox( Buff );
}
}
and connection function:
void CConnectSocket::OnConnect(int nErrorCode)
{
AfxMessageBox("Connected!");
CSocket::OnConnect(nErrorCode);
}
thanks
|
|
|
|
|
I want to make a program that has an interface similar to Sub7 where you click a button and instead of opening a new dialog window, it changes the view inside that dialog....kinda like another dialog inside of the main dialog! Anyone understand my drift? Help would be appreciated!
Thanks
Ashman
|
|
|
|
|
Look at PropertySheet and PropertyPages?
|
|
|
|
|
I am currently having a problem with access to files on a dual processor machine that has a anti-virus scanner installed. The anti-virus scanner is Innoculate-IT from Computer Associates. CA advice is set the scanner to scan incoming only or add the file extension to the excluded list. Has anybody here had a similar problem and does anybody know of any other workarounds.
Thanks for any information you can provide.
Steve.
|
|
|
|
|
ok i have used the wizard to make an mfc windows explorer skeleton, but am lost as to where to put the tree forming code and document opening code, and saving code and other bits, please help cos i'm on work experience and thinking of finding bill gates ans custard pieing him - anything like an mfc source code for the windows explorer would be great -i've been hunting but no found any.
|
|
|
|
|
add a tool tip to a button?
pliz post some code...
thanks
|
|
|
|
|
I would like to know if someone could explain me wht is the cause of this debug error:"abnormal program termination ".
thanks in advance
gerald
|
|
|
|
|
SYMPTOMS
When creating a temporary object and then re-throwing an exception, as demonstrated in the sample code in the More Information section of this article, the application terminates abnormally.
RESOLUTION
See the More Information section for the sample code and the workaround.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0.
MORE INFORMATION
Sample Code:
class aClass
{
public:
aClass(const char*){} ;
~aClass(){} ;
} ;
void push(const aClass& val)
{
}
void main()
{
int a = 5 ;
try
{
try
{
throw a ;
}
catch(int)
{
//Workaround: uncomment the following 2 lines
//aClass aObj("ABC") ;
//push(aObj) ;
//Comment the line below
push("ABC") ;
throw ;
}
catch(...)
{
}
}
catch(...)
{
}
}
Read the MSDN!
|
|
|
|
|
This seems a depressingly typical problem with learning MFC. All the examples of changing view, of course, assume you're doing it in the frame window, in response to a message. I'm trying to do it from the CDocument (switching to an errors list if the incoming document fails to validate). How the devil do I find my way to the frame window object from there? I suppose, if I get really desperate, I can store a pointer to my frame window in a global inside it's constructor but please tell me there's a better way than that.
This seems to be part of a pattern with MFC. Object instances are created inside MFC methods and hidden away from the programmer in undocumented and unsupported members. Persnally I think that the whole thing would be much better if the CRuntimeClass stuff had never been dreamed up.
|
|
|
|
|
You could get a pointer to the first view, and then call myView->GetParentFrame(). There may be a more acceptable way, but this is the one I thought of first.
|
|
|
|
|
Hi all,
I added an ActiveX to my resource ...
Now, i want to remove that ... how can i do that ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|