Ok, i have two programs.
One launches the other at some point.
And i have my programs in classes for win32.
Now what i want to do, is combine them in some sort of thread. I can do this easily using CreateThread etc... However, i dont want them in same window.
I want them to be opened and LOOK like as if they are 2 seperate programs. So i can switch between program 1 and 2. However, i want it all in one exe...
Is this at all possible? I think it is, as i've seen some other programs do it. Right now my program just launches the other program using CreateProcess.
I'ts not a good idea to try to put a GUI in two different threads. You can however create as many top level windows as you want and have worker threads to send mesages to each so it might look like seperate programs.
But in the taskbar on bottom, will it look like 2 different programs? Because mainly i want to be able to switch around with it.
I understand building GUI in same spot is better (I have no idea why tho), i could just send createstruct to other functions but anyway.
How do i create extra top level windows?? Any tutorials on that? I know dialog boxes but they are part of the main program and don't look like a seperate window.
Here is a quick example. As you can see both windows are added to the task bar and the user won't know if it is the same program or seperate programs (well he can guese because the windows look similar and have the same icon but you can change that).
You will probably want to create seperate window procedures for each window.
const char szClassName = "Window Class";
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hwnd, msg, wParam, lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = &WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
HWND hwnd1 = CreateWindowEx(WS_EX_CLIENTEDGE, szClassName, "Window 1", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, hInstance, NULL);
HWND hWnd2 = CreateWindowEx(WS_EX_CLIENTEDGE, szClassName, "Window 2", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, NULL, NULL, hInstance, NULL);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
Thanks a lot for the help.
I'll tell you how it goes when i do it.
Ok, seems like this is a wee bit more complicated for me. I'm using a more complex class, like the one in foosyerdoos.fsnet.co.uk and it seems like it's not working as i have been debugging for a couple hours.
I got to a point where it says "failed to create wnd". Which means i can register WNDCLASSEX, but i cannot create the window or something. I guess something to do with something getting lost because of having such complicated classes.
So i have two classes. One is a windows program that works fine, then at a certain part a function is activated, which activates WINAPI WinMain2 (the other program), and tries to make it. However things aren't going too well.
Ill keep debugging.
Here's exactly what I did. It compiled and linked great (im using DevC++), but it fails to "create wnd". The following code is like the main.cpp of my FIRST program. It's suppose to launch the second program, which is included in another class Called CppWnd2.
The class functions i used are self-explanatory and work great.
EDIT AGAIN: i fixed the code, so no errors anymore. There is no error. The only problem is when i launch the other program, it just closes the parent window on me and doesn't show any other window. The program just dissappears!!! Everything gets interpretted till the CreateWindowEx is called for this window.
//give the wnd a class name to register with os
//give the wnd a caption
//register and create wnd,checking the return value to ensure that a valid wnd handle has
if (App2.Create(hAppWnd)) // Parent Handle.
MSG Msg; //a simple structure for storing message information
//start message loop
//translate and dispatch other messages
LRESULT CALLBACK MainWndProc2(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
//just send the message and other parameters to the class function for handling
I set window style to: WS_CAPTION | WS_POPUPWINDOW;
and class style to: CS_HREDRAW|CS_VREDRAW;
The hwnd that is returned... works great, no error messages, and hwnd is NOT null. However, they just dissappear... I think something to do with the styles i set.
Well i hear the error message, i hear a sound that's familiar to a messagebox MB_ICONERROR. However, i can't see it O_O.
Ok it's fixed.
I shouldn't have redefined hInstance. HINSTANCE hInstance;
I just had to give the original HINSTANCE of the first program :).