|
Thank you very much
--PerspX
|
|
|
|
|
I don't really know exactly what this is called, so that may be why i haven't found any good information about it.. From one of my programs (a VC6.0 dialog based MFC application) i want to be able to check checkboxes, slide sliders etc of other MFC dialog based applications. Im not sure if its possible, but i would guess that it is since other programs can like hide windows and stuff. Is there a nifty way to do so in c++? (except for cheapy ways like moving the mouse and clicking by code)
Like CheckBox(SomeWindow, SomeName, 1); :P (i know it can't be that easy, but in general..)
Anybody have any experince with this, know what it might be called or have any urls?
Since i dont have anything to work with right now i am open to any information
thanks
//Johannes
|
|
|
|
|
Such a thing is possible if you first obtain the window handle of the checkbox, slider, etc., and then use SendMessage() to send window messages to it.
The hardest thing about this is determining the exact window to which you want to send the messages.
Keep in mind that in Vista, your manipulator app has to have high enough "integrity" to send messages to other processes.
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
You could use the EnumWindows() API to search for all of the windows that are open, then when you have found the right window, you could use the FindWindowEx() API to find the right child window owned by the window returned by EnumWindows(). Then, as said above, you could use the SendMessage API to send the designated message to the window.
Hope this helps!
--PerpspX
|
|
|
|
|
in addition to what Perspx said, you can use GetDlgItem() or EnumChildWindows() to get each controls in a dialog and then use GetClassName() to find which control it is.
nave
|
|
|
|
|
Thanks for the help
So im looking at the SendMessage, FindWindow and FindWindowEx, but im having trouble connecting them all,
I declare a HWND to "hold the window".
FindWindow("Control", 0); //Makes it so my program has control to the window called "Control" ?
Then i have to use FindWindowEx to set which dialog radio buttons /checkboxes should be set and to what
then SendMessage() to set it?
Might you know how i would connect these? Or is the some nice tutorial somewhere :/
thanks
//Johannes
|
|
|
|
|
Hi all,
I am trying to convert MFC code to Borland 6 C++.
I have never done programming in MFC. So facing bit problem. Well firstly i would like to know whether in MFC we can drag and drop the tool bars...well i am trying to view design of the form but i dont see any option and i cant view it...
The project is created on earlier version of VStudio as i am using VS2005. Is there much difference ?
Because i am getting few exception when i run this project on vs2005.
OK secondly when i am trying to step through this mfc application . After pressing F10 i get the appmodul.cpp file and it just step through one or two lines and run the whole application. How can i step through the whole program...Break point isnt helping me out.
Thirdly i have got this function class_def::abc(CProgressCtrl *pp) to get the progress bar working with addition of SetRange, SetStep and SetPos functions.
In Borland there is this TProgressBar option i guess. But if i just write TProgressBar in place of CProgressCtrl i get error i.e.[ } expected]. And what replaces the SetRange,SetStep, and SetPos functions...
Any or all help would be greatly appreciated.
Thanks
SS
|
|
|
|
|
VC6 -> VC2005 is a huge difference, VC6 was not very standards compliant at all. MFC has not changed that much, however.
Software_Specialist wrote: How can i step through the whole program...Break point isnt helping me out.
Run in debug mode ?
Software_Specialist wrote: But if i just write TProgressBar in place of CProgressCtrl
Obviously if they are different classes, they will expose different methods and you will get errors.
Moving from one framework to another is essentially a rewrite.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i am using picturebox to create visual buttons, but i want the picturebox has tabstop property, how can i do?
any api function ??
|
|
|
|
|
Try overiding the WM_GETDLGCODE message of the picture box and return DLGC_WANTTAB.
nave
|
|
|
|
|
i am gladly pleased you
|
|
|
|
|
In Test.exe module the application class CTestApp was derived from CWinApp . Everything worked fine. Then I decided to move some common stuff from CTestApp to CCommonApp . This CCommonApp is defined in Util.dll module. Now CTestApp is derived from CCommonApp which is derived from CWinApp .
The contructor of CTestApp is called properly and all its parent contructors. However the application crashes right after this, because the AfxGetApp returns NULL in MFC core and can't call InitApplication method.
Any idea what can be the problem?
Thanks, Abyss
|
|
|
|
|
You'll still need a global app object in the EXE project, something like:
// The one and only CTestApp object
CTestApp theApp;
If you already have that...
How is CCommonApp declared? It should be like this:
class AFX_EXT_CLASS CCommonApp : public CWinApp
{
...
};
Your DLL needs to be a legitimate MFC extension DLL as well.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks for advice.
I have this global application object in EXE. My DLL is also a dynamic DLL, where the CCommonApp is exported using __declspec(dllexport) and imported in EXE using __declspec(dllimport) .
I'm not sure what did you mean by legitime MFC extension DLL.
My Util.dll project has its own CUtilApp : CWinApp class, and _USRDLL define in project settings. Also tried to use DllMain method with _AFXEXT define. It did not help .
Maybe something is wrong with project settings, maybe something else. But I have no idea what could be wrong.
Thanks, Abyss
|
|
|
|
|
Abyss wrote: I'm not sure what did you mean by legitime MFC extension DLL.
See Extension DLLs[^]
Classes derived from MFC classes in a DLL and then derived from in an EXE means the DLL MUST
be an MFC extension DLL. MFC requires certain initialization in DllMain() and import/export
properties on classes must be dealt with. It's all documented at the link (and sublinks) above.
Also important - you can't statically link to MFC libraries - the DLL and the EXE need to use the
shared MFC DLL library.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Well, I tried to generate these two projects from scratch using VS Wizard. The EXE application is a simple MFC non doc-view architecture module. The DLL is a MFC Extension module. I added my CCommonApp class to the DLL and exported using AFX_EXT_CLASS macro. In EXE I replaced CWinApp with CCommonApp .
The result is the same
Now I would say that this is not supported. However I can remember that in the past I saw several projects where it worked well (unfortunately I can't find them)...
Any help is appreciated.
Thanks, Abyss
|
|
|
|
|
I found the culprit. My project is base on Multibyte character set. When I introduced the new DLL module it was set to unicode character set by default. And this caused the whole problem - different MFC libraries where linked to my modules. It was enough to switch the project to Multibyte char. set and it started to working.
It does not matter if the DLL is MFC Extension or Regular DLL. In both cases it works fine.
Thanks for your help.
Abyss
|
|
|
|
|
Cool! Glad you found it!
Abyss wrote: It does not matter if the DLL is MFC Extension or Regular DLL. In both cases it works fine.
It will probably matter eventually - the initialization in the extension DLL is important to many
of the MFC classes. It just depends which ones you use and where The CWinApp class is one of
them - it's initialization in the DLL module is used with window/dialog creation for example.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi I'm trying to call a function in a DLL and am having trouble doing so because it uses callback and I need the function in the DLL to write to my dialog.
The function prototype is like this:
<br />
UINT CALLBACK PatchApply(LPSTR lpszCmdLine,LPVOID (CALLBACK *lpfCallBack)(UINT Id, LPVOID lpParm),BOOL WaitFlag);
and the example given is in C and not C++ (i'm making a dialog based program in unmanaged VC++ 7
Example snippet :
<br />
typedef LPVOID (CALLBACK* PATCHCALLBACK)(UINT, LPVOID);<br />
<br />
UINT CALLBACK PatchApply( LPSTR CmdLine, <br />
PATCHCALLBACK CallBackFn, <br />
BOOL WaitFlag);<br />
<br />
LPVOID CALLBACK __export CallBack( UINT Id, LPVOID Parm );<br />
My callback function is declared as
LPVOID CALLBACK CallBack(UINT Id, LPVOID Parm);<br />
and in the callback program I try to write to a listbox on my dialog.
Prior to calling I do like this:
<br />
typedef LPVOID (CALLBACK* PATCHCALLBACK)(UINT, LPVOID);<br />
PATCHCALLBACK CallBackPtr; <br />
CallBackPtr = MakeProcInstance((FARPROC) CallBack, AfxGetInstanceHandle());<br />
<br />
nRetCode = PatchApply(lpszBuf, CallBackPtr, TRUE);<br />
The MakeProcInstance is also from example and I try to call the PatchApply function directly from the DLL as I link the lib file into my program.
I get this error "cannot convert from 'overloaded-function' to 'FARPROC'" with above code and don't know what to do
Can anyone tell med what I need to do to call this succesfully ?
Thanks
|
|
|
|
|
Well, one thing is that FARPROC is defined as
typedef INT_PTR (WINAPI *FARPROC)(void);<br />
whereas your callback function has a return type of LPVOID .
So it looks like you're trying to redefine the return type of the callback function when you cast it to (FARPROC) in the call to MakeProcInstance .
Also, FARPROC has no arguments, so it is a very different function signature.
-- modified at 13:32 Sunday 27th May, 2007
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
Hi all:
My program crashed at the line:
for (vector<int>::iterator it = list.begin(); it != list.end(); ++it) {
if (*it < 0) list.erase(it);
}
//Filtering out all the negative numbers from a vector.
I am sure that it is vector::erase(it) is causing all the pain, but not sure how to fix.
Can anyone help?
Thank you
|
|
|
|
|
When you call erase, it will invalidate your current iterator and all iterators that follow. Thus, when you erase something and try to increment this same iterator, this will cause an exception. The erase function returns an iterator to the next valid element, you need to use that.
Try to change your code to something like this:
while (it != list.end())<br />
{<br />
if (*it<0)<br />
{<br />
it = erase(it);<br />
}<br />
else<br />
it++;<br />
}
|
|
|
|
|
Thank you very much, it worked.
|
|
|
|
|
Cedric's given you an answer, and its good that it works - here's another way - include <algorithm> and use remove_if ..
the following link shows how :-
http://support.microsoft.com/kb/156532[^]
'g'
|
|
|
|
|
Hi 'g':
Thank you very much for bringing that into attentaion as well.
I have learnt a lot from both of you.
Thank you
|
|
|
|