|
In MFC, how would you go about getting that PATH of the current executable - AfxGetAppName is not enough.
Help
|
|
|
|
|
__argv[0] should do the trick. It's global variable in MFC.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
__argv[0] will contain incomplete path when you launch the program from command line. Seems that most reliable way of getting the path will be ::GetModuleFileName.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Cheers. I had a feeling about GetModuleFileName, but thought it would only provide the filename again.
|
|
|
|
|
Giles wrote:
I had a feeling about GetModuleFileName, but thought it would only provide the filename again.
It'll give you complete path, including filename. If you want to have only directory part left, copy the filename into CString, then use CString::ReverseFind and CString::Left.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
GetModuleFileName(0,...)
includeh10
|
|
|
|
|
i need a dockable menu (that is: the menu can be move around and docked at top, left ... of main frame,
Help.....
seven flowers for u ...
includeh10
|
|
|
|
|
Hello everybody!
I tried to outsource some common classes from some existing projects into a shared static WIN32-library. The classes were implemented into a MFC dialog application and make use of MFC templates such as "CMap" and also of MIDL base_types like "hyper"...
The problem is: If I try to compile those classes within a static WIN32-lib workspace, Visual Studio mourns about that "hyper", "CMap", etc. are unknown (Error C2501). Although I've set the option that I want to use MFC in this library.
I think that I have to link some more headers or set some switches in the properties of the static lib workspace... But I found no suitable hints at the MSDN library at all!
So... Maybe someone can give me a tip how to implement "hyper", "CMap" & Co. into a static WIN32-library...??? *pls*
Many thanks in advance!
With best regards,
Andreas Dilling
|
|
|
|
|
Hello,
when i exit my application, i get this message from the debugger:
Warning: calling DestroyWindow in CDialog::~CDialog --
OnDestroy or PostNcDestroy in derived class will not be called.
What is the meaning of this Warning?
Thanks for your Help!
|
|
|
|
|
This means that you're having problems with lifetime of your dialog. Is your dialog main window of your app?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
That msg occurs when you have a class instance that is being
destroyed before its window. The class destructor will
automatically destroy the window for you, but since this is
done from the destructor, the instance is no longer around
to handle any messages. This is sometimes the behavior you
want, just make sure that your destructor AND OnDestroy both
call a cleanup routine in common.
|
|
|
|
|
Hello Thomas and Scott,
Thank you very much for your help!
I have found the error:
I have a view, he create via new dialogs. When i exit the dialogs, in my OnDestroy-function of the view, i delete the dialog.
Now i delete the dialogs in the destructor of my view.
|
|
|
|
|
I've just started to read about this. seems like custom controls can have relected messages. so a regular old button added from the toolbox is not able to do reflection?
Thanks,
ns
|
|
|
|
|
anonymous wrote:
so a regular old button added from the toolbox is not able to do reflection?
All controls can use reflection.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
The article I was reading was adding handlers for messages starting with = via the classwizard. One selects the class of the control and then handles the = message. Since I added my button through CW I dont have a control class for it in my CW. Thats why I incorrectly deduced that standard controls couldnt refelect.
Thanks,
ns
|
|
|
|
|
Hi All !
One problem pursues me for a few years already:
all my Win32 apps, written in VC++ (5.0-6.0),
crash on the second run under debugger.
Toolbar code in comctl32.dll causes access violation.
In more details:
1)The crap arises only when the app
is run 2 times successively from the VC++ IDE.
When running my app standalone, all's ok.
2)The program crashes when a mouse is moved
over the toolbar. WM_MOUSEMOVE is finally
dispatched to DefWindowProc() in comctl32.dll,
and there fails.
The mouse coordinates seem to be correct.
3)If toolbar is hidden, it's allright.
4)This bug seems to be not accidental
concatenation of circumstances:
this happened on different Windows versions,
under both VC5 and VC6, after many reinstallations
of the VC++ and OS etc,
and, finally, with all my Win32 GUI apps -
independently of tyhe architecture of the app,
and of the way I use tollbars
(containing ReBar, different styles, etc.)
5) The bug arises and disappears from time to time,
during the course of program development.
It seems that it depends somehow
on the size of the .exe or something like that.
Anyone ever faced this problem ?
Any help or hint would be appreciated !
Thanks in advance !
|
|
|
|
|
I was wondering what are the principles of creating a plugin extendable program.
I mean a program that accepts custom functions being created by third party developer, following certain rules.
Like Winamp, or Windows Media Player, that with plus has the Speaker Enanchement pluging: you install the plugin and there is a new Item in the Windows Media menu.
Is there any tutorial, guide, etc about this?
Thank you.
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
|
for the plugin system i use, i simply came up with a COM interface for the plugins and just told people that if they want to write a plugin for my apps they must: create an ATL object with this interface, name the object thusly, and place it in this folder.
at runtime, my app scans that folder and finds all the DLLs there. then it does a CreateObject call on each of "%DLLNAME.MyInterfaceName" . if that works, the object is a plugin.
it works great.
i can elaborate, if you'd like
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
Chris Losinger wrote:
for the plugin system i use, i simply came up with a COM interface for the plugins and just told people that if they want to write a plugin for my apps they must: create an ATL object with this interface, name the object thusly, and place it in this folder.
Oh, this sounds very efficient.
Can you indicate me to some documentation about COM interfaces, since I am profane?
Thank You.
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
COM is a huge subject. but, here is a link to a tutorial i wrote on how to create plugins for my apps. you can use VC's ATL wizard to do most of the work.
to use these plugins, you need to create a COleDispatchDriver object and use it to create an instance of the plugin:
cosnt char * pInterfaceName = "TNImgAutomation";
CString csPluginObjectName = csDLLName + pInterfaceName;
COleDispatchDriver disp;
BOOL ok = disp.CreateDispatch(csPluginObjectName);
now we have a plugin object. the next part is to call methods of the plugin. this is where it gets tricky, in my system. because i create COleDispatchDriver objects directly, I am responsible for finding the methods and handling all of the method parameters myself.
Here's how you get the DISPID of a method in an ActiveX object (DISPID is basically the enumerated ID of the method. each method will have a unique ID).
HRESULT GetDispID(COleDispatchDriver &disp, const char *pName, DISPID &dispid)
{
USES_CONVERSION;
LPOLESTR lpOleStr = T2OLE(pName);
if (disp.m_lpDispatch==NULL)
{
ASSERT(0);
return E_INVALIDARG;
}
return disp.m_lpDispatch->GetIDsOfNames(IID_NULL, &lpOleStr, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
}
so you can do this:
DISPID dispid;
GetDispID(disp, "GetPluginName", dispid);
now you know the ID of that method. now you can call it.
here's how I call "GetPluginName" on a plugin:
CString CTNPlugInBase::GetPluginName()
{
CString csOut;
BSTR bsTemp;
long result;
static BYTE parms[] =
VTS_PBSTR;
disp.InvokeHelper(m_GetPluginNamesDispID, DISPATCH_METHOD, VT_I4, (void*)&result, parms, &bsTemp);
csOut = bsTemp;
SysFreeString(bsTemp);
return csOut;
}
the tricky part here is that "parms" variable. that's where you list the parameters for the method. with one parameter (in this case a pointer to a BSTR: &bsTemp), it's pretty easy. but when you get more parameters, it looks like this:
long result;
static BYTE parms[] =
VTS_PI4 VTS_PI4 VTS_PI4 VTS_I4 ;
disp.InvokeHelper(dispId, DISPATCH_METHOD, VT_I4, (void*)&result, parms, MemoryHandle, Width, Height, Context);
notice that there are no commas between those VTS_ things.
this might seem really horribly complicated if you've never used COM/ATL before. but it's really not too bad, once you get into it.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
I have to realize a very complicated user interface and
I have to insert a lots of control in a small space.
I'd like to used CDialog and CDialogBar classes but I need
to modify the window appearance in order to resize or remove
the window border and the title bar.
How can I do that???
Where can I find some samples ??
Thank you very much.
|
|
|
|
|
no sample is needed.
in resource, change dialog style to 'sizeable', that is all.
includeh10
|
|
|
|
|
I want to print data in text file out to the paper
If my data in text file is
110011110
I want to change 1 in the above data to solid black (which have 2 pixel width and 4 pixel height) and 0 in the above data to solid white (which have 2 pixel width and 4 pixel height)
This below is code but it does not work. The printer print the blank page. What wrong with my code?
code:
------------------------------------------------------------
void CTestprint::OnPrintButton()
{
DOCINFO di ;
CPrintInfo printInfo ;
CDC dc ;
CRect draw_area ;
CPrintDialog dlg(FALSE) ;
if (dlg.DoModal() == IDCANCEL)
return ;
HDC hDC = dlg.GetPrinterDC() ;
if (hDC == NULL)
return ;
di.cbSize = sizeof(DOCINFO) ;
di.lpszDocName = "Document name";
di.lpszOutput = NULL ;
// prepare the print information structure
dc.Attach(hDC) ;
printInfo.m_bDirect = TRUE ;
printInfo.m_rectDraw.left = 0 ;
printInfo.m_rectDraw.right = dc.GetDeviceCaps(HORZRES) ;
printInfo.m_rectDraw.top = 0 ;
printInfo.m_rectDraw.bottom = dc.GetDeviceCaps(VERTRES) ;
draw_area = printInfo.m_rectDraw ;
dc.StartDoc(&di) ;
CString testline = "101101001" ;
int x = 0 ;
int y = 0 ;
int pos = 0 ;
// start printing the document
dc.StartPage() ;
while (pos < testline.GetLength())
{
if ((testline.GetAt(pos)) == '1')
{
CBrush brush;
// Creation of the brush with a black color
brush.CreateSolidBrush(RGB(0, 0, 0));
// Create a rectangle with coordinates x,y,x+2,y+4 corresponding with top, left, bottom, right
CRect Rectangle(x, y, x + 2, y + 4) ;
// Fill a rectangle in the current device context or DC
dc.FillRect(&Rectangle , &brush);
x += 2;
}
else if ((testline.GetAt(pos)) == '0'){
x += 2 ;
}
pos++ ;
}
y += 4 ;
x = 0 ;
pos = 0 ;
dc.EndPage() ;
printInfo.m_rectDraw = draw_area ;
dc.EndDoc() ;
VERIFY(dc.DeleteDC()) ;
}
------------------------------------------------------------
|
|
|
|
|
Perhaps a little SetClipRect ?
|
|
|
|
|