|
Normally if you create any window and create child windows (controls) related to it. Then you can just hide the main window and all is hidden!
Group box or normal static controls can do the job! However, if you are using the resource editor, then do the following:
in your WM_INITDIALOG try to make your group box the parent for the controls by calling SetParent. I am not sure if this will change their position, but give it a try!
|
|
|
|
|
I've tried to create a MainFrame app in MS VC6 by using the templates in VC6. I select creating an app using MFC with no documents, and what results is an app that only has a frame. Good! Yet when I compile the app and run it, the frame paints and dumps a deadly error from mfcocc with Abort Retry or Fail. The only option is to Abort. I have tried to look at the template for any problem, but I must admit, I'm only a novice. Any hints?
|
|
|
|
|
Hi!
How do you get access to the file name that you double click on, in the file explorer/ or on the desktop.
I have a custom application and a custom file extension. The application gets launched whenever I double
click on a file with that extension. However I am trying to obtain the name of the file that was double clicked.
AB
|
|
|
|
|
Did you check the command line?
Look at GetCommandLine() API!
Mh2!
|
|
|
|
|
Thanks!
Actually I was checking the command line, but when I created the registry key for my extension, I had not included the
%1 option! duh!
ab
|
|
|
|
|
Hi, I have a couple of questions regarding the usage of DLLs in a single process from within several threads. I am using dynamically loaded DLLs (to borrow a term from elsewhere on this website), that is I am calling AfxLoadLibrary and then GetProcAddress to find my functions. All of the dlls and the exe are built using MFC as a shared library. Please do not tell me I should be using COM to address any of these issues
1. Is there a way that the main thread in the EXE can call AfxLoadLibrary while a worker-thread is inside of a function in the DLL w/o causing lots of nasty problems? Right now I have hacked up a solution where it suspends any threads it thinks might be using the DLL, and it seems to work, but it causes memory leaks since that thread probably allocated memory inside of the DLL functions it might have called.
2. On a completely different note, would there be a way to call AfxLoadLibrary within each thread, and have each thread obtain its own HINSTANCE so that each thread could call AfxFreeLibrary independently of the others? I have tried to do this, and noticed that all copies of the dll functions seem to be the same. I know that in general, DLLs are loaded on a process basis rather than a thread basis, and was wondering if there was a way to override this behavior? If this were possible, #1 wouldn't be so much of an issue.
3. What is the safest way to share CWnd objects between threads, and within functions inside of DLLs? Basically, the main EXE opens the HINSTANCE to the dll, and then creates a separate thread to perform various lengthy operations in DLL functions, passing the thread an HWND (window created in EXE), and the thread then passes that HWND as an arguement into the GetProcAddress(ed) function. Inside the DLL, I call: CWnd::FromHandle. This seems to work if I use functions like SetWindowText or SendMessage, but does not work if I call PostMessage on that HWND (or use the CWnd wrapper). Since using SendMessage is dangerous because I don't want to overload the EXEs message pump, I'd really like to be able to use PostMessage. One weird issue here is that CStatic::SetWindowText works fine, while CProgressCtrl::SetPos does not seem to have any effect.
Mach5 Enterprises, LLC. http://www.mach5.com/
"Web Intelligence for the New Economy"
|
|
|
|
|
You can call AfxLoadLibrary from any thread to load a DLL. No problem with that!!
One thing with Dynamically loaded dlls is that you shouldn't use _declspec(thread) in your DLL!
If you want to use data per thread, then you should use tlsAlloc for thread local storage!
The only place that were you might hang is at startup... look at article Q142243 in MSDN
Regarding the memory leak, look at article Q105286. Note that the term USRDLL in the article is no longer valid, the article actually applies to all DLLs that use MFC
Mh2!
|
|
|
|
|
Ummm, its not exactly clear what the problem is. If you had stated what you are trying to acheive I'd have more to work with. However, I'll try. First off, you'll
be pleased to hear that COM has nothing to do with any of this.
1. Is there a way that the main thread in the EXE can call AfxLoadLibrary while a worker-thread is inside of a function in the DLL w/o causing lots of nasty problems? Right now I have hacked up a solution where it suspends any threads it thinks might be using the DLL, and it seems to work, but it causes memory leaks since that thread probably allocated memory inside of the DLL functions it might have called.
Once a DLL is loaded, subsequent calls to LoadLibrary just increment its reference count. So any worries about address space changes, or whatever it is you are worrying
about shouldn't matter.
2. On a completely different note, would there be a way to call AfxLoadLibrary within each thread, and have each thread obtain its own HINSTANCE so that each thread could call AfxFreeLibrary independently of the others? I have tried to do this, and noticed that all copies of the dll functions seem to be the same. I know that in general, DLLs are loaded on a process basis rather than a thread basis, and was wondering if there was a way to override this behavior? If this were possible, #1 wouldn't be so much of an issue.
Nope. The HINSTANCE returned is actually the load address (in the current Win32 implementation) of the DLL. YOu can check this in your debugger. Any calls to LoadLibrary after the first call, just increment the ref count and return the HINSTANCE as usual.
3. What is the safest way to share CWnd objects between threads, and within functions inside of DLLs? Basically, the main EXE opens the HINSTANCE to the dll, and then creates a separate thread to perform various lengthy operations in DLL functions, passing the thread an HWND (window created in EXE), and the thread then passes that HWND as an arguement into the GetProcAddress(ed) function. Inside the DLL, I call: CWnd::FromHandle. This seems to work if I use functions like SetWindowText or SendMessage, but does not work if I call PostMessage on that HWND (or use the CWnd wrapper). Since using SendMessage is dangerous because I don't want to overload the EXEs message pump, I'd really like to be able to use PostMessage. One weird issue here is that CStatic::SetWindowText works fine, while CProgressCtrl::SetPos does not seem to have any effect.
Using HWND is the way to go. Don't turn them in CWnd's as that requires access to the correct CWnd/HWND map which may not be in the thread you are calling from. USing
SendMessage is an absolute no-no in multithreaded code as you can get a deadlock.
You must use PostMessage or SendMessageTimeout. If you use PostMessage, your message
will not get processed until the thread that has the message loop processes the
message. This may be why you are not seeing the result of the posted message (the thread you are posting from may be too busy or in a higher priority group than the
message queue thread.
I don't know if those answers help, but maybe they'll help you post a clearer
explanation of the problem, or why you'd want multiple HINSTANCEs for the same DLL.
Stephen Kellett
--
C++/Java/Win NT/Unix variants
Memory leaks/corruptions/performance/system problems. UK based.
Problems with RSI/WRULD? Contact me for advice.
|
|
|
|
|
Thank you for your response.
To clarify what I'm doing:
1. EXE loads a library into a CWinApp derived member HINSTANCE, and also stores a bunch of
function pointers. This HINSTANCE is freed in the OnExitInstance of the EXE.
2. The EXE can launch a CWinThread derived class, passing a struct with function pointers. This happens an arbitrary number of times. The CWinThread thread uses a CDialog GUI.
3. Each GUI-based thread, in turn, responds to events in a dialog by creating worker threads and those worker threads call the DLL functions. The DLL functions are smart enough to take HANDLE arguements where necessary to distinguish between threads. All of this is working fine, and I don't think is the root of the problem. I can easily have the DLL functions accept only 1 thread at a time (i.e. they return false if they detect a 2nd thread) which I'm doing until I get the whole mess straightened out. Regardless, the problem is exactly the same with one thread as it is with many -- access violations when the EXE releases the HINSTANCE.
Everything works great until the main EXE wants to close. I set a flag in the DLL telling functions to return, and this works fine sometimes. The problem is, that if the main EXE closes, and there are lots of threads still "in" the DLL, and in particular, if they are "in" system functions inside the dll, they don't notice the halt-flag until it's too late, and they trigger an access violation because the EXE has already freed the DLL. I'm wondering if there's a way to have the AfxFreeLibrary start a cascase of reference counting instead of directly freeing the dll, so that the dll would stay alive until the last thread was halted, but I'm not dll-savvy enough to know how to do this. So this gets me back to my multiple-HINSTANCES thought, that if instead of having the AfxLoad/Release in the EXE it was per-thread, and if they were all independent of each other, then I wouldn't have any problems.
Thanks for your help!
Mach5 Enterprises, LLC. http://www.mach5.com/
"Web Intelligence for the New Economy"
|
|
|
|
|
Hey guys,
What I need is a standard library algorithm to find an element in an ordered vector... binary_search would be fine if it returned an iterator--?
Hope this isn't a dumb question, but all the suitable looking algorithms I found took linear time- surely what I need is in there, but where do I look?
Thanks,
nick
|
|
|
|
|
look at bsearch in < stdlib.h >
Mh2!
|
|
|
|
|
ForwardIterator lower_bound(ForwardIterator beg, ForwardIterator end, const T& value) returns the position of the first element greater than or equal to value. There's also a version that takes a binary comparision predicate. It's logarithmic time for random access iterators.
|
|
|
|
|
thanks a heap dude
|
|
|
|
|
I'm using SendInput in my application to simulate someone typing keys on the keyboard, but I'm thinking it's sending stuff to the target window's message queue too quickly for it to keep up. It's semi tolerable under Windows NT 4 Workstation, but when on a Windows 98 box almost twice as fast, almost half of the input doesn't make it through.
Anyone have any sort of experience with this thing? Or possible pointers/advice/etc? Thanks in advance
--
Peace,
Amit Jain
|
|
|
|
|
I am using SendInput and it is working fine on both Win9x and NT/Win2K
However, if the user is Interfering then he can definitely screw things!
Mh2!
|
|
|
|
|
Calling BlockInput before and after prevents the user from screwing things up most of the time...
--
Peace,
Amit Jain
|
|
|
|
|
My company is developing a custom keyboard and i would like some help on how to interface with the keyboard messages and stuff. Any help will be appreciated.
DrunkerII
|
|
|
|
|
|
Hi,
How is it possible to detect that a new application has been launched ? The idea is to have a program always sleeping but that wakes-up each time a new application (thread or process) is launched.
Thank's
--Francois
|
|
|
|
|
You can write a shell extension called a shell execute handler, which will be called when a program is run.
|
|
|
|
|
Hi,
Ok, where should I start looking for info about these "shell extensions" stuff (if you just had some function names). Thank's
--Francois
|
|
|
|
|
|
Hello All,
This is important, atleast for me So any hints will be usefull.
I have my App as a SDI, With the CFormView as the base class of the view class. the problem is this,
when maximize the Main App window (to fill the screen) the Form doesn't get resized to fill the App main window, but it stays at its original size and location.
I was wondering if there is a way to get the view form (dialog) gets resized to fill the App main window when I maximize the App window, and to Get it to be resized to fill the App window if I resized the App.
Basically I want the View Form to occupy the App Main window at all times.
Thanks in advance.
Fady.
|
|
|
|
|
Hey,
I know I saw a resizable FormView around here some where, maybe it was at CodeGuru. Anyway, you could modify one of the Resizable dialog classes to suit you need.
Here is one:
http://www.codeproject.com/dialog/resizabledialog.asp
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Hello All,
I have a quick question, you know Al know the "File Sharing Violation" error (i.e. when you try to delete a file that is in use).
The Question is this, I'm trying to write an application that I give it this filename, and it tells me who, or what is using this file.
So I was wondering if there is a way (MFC or a Win32 API ) that can accomplish this
Thanks in Advance
Fady
|
|
|
|
|