Writing a Console Program trying to spawn an MFC Wnd App is not really possible, or desirable!
The only practical way this is possible is by the Console Program calling the Standard 'C' 'system(...)' function to launch the Windows App.
If you are looking for tooling to restart a misbehaving Windows Program, you came to the right door. I have just that.
The actual code is proprietary, but I can explain how it works.
I ended up having the debugging modeless dialog box HWND being returned to me from the SendMessage to the main window as both LRESULT and HWND are both 64 bits wide running 64 bit mode as I don't want the console program to sit around and wait for a response (and hold it up) I do a PostMessage from the console program
I (like Bram) am confused as to what you are trying to do here. Or indeed what your point is of using a console application to launch a Windows application, to launch a modeless dialog.
1.) You said quote: "Later I create a modeless Dialog in the childprocess for which I would like the to get the HWND handle."
Doesn't matter which create method you use you get the handle back right then ... so why don't you hold it??????
2.) Like others I wonder why you are using MFC at all which will be problematic why would you not just use the WIN32 API.
3.) If GetWindow(MainFrame,GW_CHILD) and EnumChildWindows are returning false the your created window isn't parented
to the window at all. It's most likely parented to the desktop and again go back to number 1 above show us the how
you created the modeless dialog and check you gave it a parent.
The key point here is a show use the lines of code around the modeless dialog creation call.
I did use GetWindow and got NULL. I was able to get Window Handle by doing a SendMessage to the other app as the return Value is From the other Window App (not Windows like PostMessage) I returned the dialog window in LRESULT
Using MFC, in a multithreaded environment, communication via SendMessage(...) is an essential.
Trying to sculpt WDK Messages for my own purpose. Use WM_USER+x, Major Crash,turned out, WM_USER+x was already used by MFC42 in a control I used in my Dialog!
has Anyone any idea what the range of messages are used or reserved by MFC in general, and what the Real Message range is, available to MFC developers.
++"#define WM_MFC_USERS 0xABXD1234
Or, something of that kind in some header somewhere. If this is the case, please let me know the Name and the value of the macro is.
I am aware of RegisterMessage(...) etc, but have always considered it as a canon to shoot a fly. It may be the better Idea for future, particularly after the nightmare I encounter now. Your idea of attaching a GUID is particularly fetching.
WM_USER +X, It worked for me many a time in the past. I can now see the flaws
My header files do not provide a macro for WM_APP. Maybe you could let me know for future reference, if it is a single value. Also AOP has advised me to Register a Windows Message. Probably the way forward for the Future.
Critical Sections are Synchronisation Objects, It is of use only if your project is multi threaded,ie Has More than One thread running in the One Program. Each thread of your program, will wait in front of a CriticalSection where you try to Enter It, until all other threads leave it. It is a communal comunication deal between threads in a program. One thread of a program will not allow another thread to run, until the section is released. Other programs can switch thread in the mean time.
The Nature and context of the question worries me! You seem to have to learn an awfull lot more before you are ready to discus critical sections
It is NOT, and I explained that already!
However, I also answered your other question, in quite a lot of detail. Before you can attempt to learn MFC Multi Threaded Programming, you will need to learn basic MFC Programming, and elements of the Windows SDK. MFC is a thin wrapper around the Windows SDK. Sometimes you need the real thing! Definitely needed in Multithreading.
Cannot Help it, You need to study more before we can help you.
I have 3 rows of text in my rich edit.
At the end of each line I move a carriage return line feed, to force a new line
/r/n. Do these 2 bytes count as 2 characters when determining the count for the selection
Really? I just tested (using VS2008) and it came out as two separate characters. Here's the code I used:
// the control contained the text: David\r\n
int len = m_richedit.GetWindowTextLength();
TRACE(_T("Len = %d\n"), len);
TRACE(_T("Text = %s\n"), text);
for (int x = 0; x < len; x++)
The resulting output looked like:
Len = 7
Text = David
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles