Archived

This topic is now archived and is closed to further replies.

need two WinMains() There visible but I can only control one.

This topic is 5573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

need two WinMains() There visible but I can only control one. the first window is perfectly fine but the second Window does nothing when I try to use it's buttons. I'm sure the mistake is here, I have never tried two main windows I need them both running at the same time. well each main window has it's own WNDCLASS,HWND,lpfnWndProc,CreateDialog the rest is shared. did I miss something ? even a guess would be nice. Any tutorials on Two Main Windows. Please help me out.
  
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
{
  WNDCLASS wc;
  MSG      Msg;
	 
  // Register window class

  wc.style         = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc   = PickSolorSystemProc;
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = DLGWINDOWEXTRA;
  wc.hInstance     = hInst;
  wc.hIcon         = LoadIcon(hInst, IDI_APPLICATION);
  wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  wc.lpszMenuName  = NULL;
  wc.lpszClassName = g_szClass;
  RegisterClass(&wc);

  // Create the dialog box window and show it

  hWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_EDIT), 0, NULL);
  UpdateWindow(hWnd);
  ShowWindow(hWnd, nCmdShow);
 

 //other window

 WINDV(hInst,hPrev,szCmdLine,nCmdShow);
   

 ZeroMemory(&Msg, sizeof(MSG));
  while(Msg.message != WM_QUIT) {
    
    // Handle Windows messages (if any)

    if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
	} 
  }



  UnregisterClass(g_szClass, hInst);
 
  return 0;
}
int WINDV(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
{
  MSG      Msg;
	WNDCLASS DVwc;
  // Register window class

  DVwc.style         = CS_HREDRAW | CS_VREDRAW;
  DVwc.lpfnWndProc   = DirectXView;
  DVwc.cbClsExtra    = 0;
  DVwc.cbWndExtra    = DLGWINDOWEXTRA;
  DVwc.hInstance     = hInst;
  DVwc.hIcon         = LoadIcon(hInst, IDI_APPLICATION);
  DVwc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  DVwc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  DVwc.lpszMenuName  = NULL;
  DVwc.lpszClassName = g_DVszClass;   
 if(!RegisterClass(&DVwc)){
	 FatalError("Error registering window class");}
  
    DVhWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_VIEW), 0, NULL);   
    UpdateWindow(DVhWnd);
    ShowWindow(DVhWnd, nCmdShow);
 ZeroMemory(&Msg, sizeof(MSG));
  while(Msg.message != WM_QUIT) {
    
    // Handle Windows messages (if any)

    if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);


	}

  }
  UnregisterClass(g_DVszClass, hInst);
  return 0;
}
  
did I miss something ? even a guess would be nice. Any tutorials on Two Main Windows. Please help me out. [edited by - Oluseyi on September 10, 2002 5:35:30 PM]

Share this post


Link to post
Share on other sites
i''ve never heard of having 2 winMains, my gut tells me that you can''t have that. it sounds like you want a multi-threaded application. i.e. 2 independant control loops that maintain some access to each other''s data.

i''d start finding tutorials on multi-threading (try google or this site''s Articles & Resources section) to start. it''s a very handy and powerful tool.

-me

Share this post


Link to post
Share on other sites
You seem to be mistaking windows for the function WinMain.
WinMain is simply the main entry point to your program - in effect it's the function that Windows (the OS) itself calls when it runs your application.
A window (the thing on the screen) is a completely separate entity.
You should be creating both windows in WinMain, or in their own setup functions, and you should only need one main loop, of the form:
while (Msg.message != WM_QUIT)
{
if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}

This loop will retreive messages from both windows, but you can use the hwnd field of the Msg struct if you need to find out which window the message was about.
You will still need to register both window classes, and call CreateWindow for each window.

About multi-threading: As Palidine said, you could use multi-threading to control two windows. This may make both windows respond more smoothly, but it won't necessarily do so, and it isn't required. I would suggest you ignore multi-threading for now, as it can make memory management difficult, but you could of course look into it if you wish.

I hope that makes it a bit clearer,

John B

Edit: Formatting, multi-threading, and making it a bit clearer.

[edited by - JohnBSmall on September 10, 2002 2:06:08 PM]

Share this post


Link to post
Share on other sites
yes I need three main windows
one directX8,
2nd to modify Graphic data like a text editor,
3rd window is a main window for pure data.

the 2nd main loop is there only when
the first window closes.
other wise all the windows will close.



thx for your help.

I did not know this thx.+++
You seem to be mistaking windows for the function WinMain.
WinMain is simply the main entry point to your program - in effect it's the function that Windows (the OS) itself calls when it runs your application.
+++


here is a little more code see any thing wrong with this

this one will not let you use it's buttons.
here is it's LRESULT CALLBACK

  
LRESULT CALLBACK DirectXView(HWND DVhWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{


switch(uMsg) {
case WM_COMMAND:
switch(LOWORD(wParam))
{

case IDOK:
PostQuitMessage(0);
EndDialog(DVhWnd, TRUE);
return TRUE;



case IDCANCEL:
PostQuitMessage(0);
EndDialog(DVhWnd, FALSE);
return TRUE;


}

case WM_DESTROY:
PostQuitMessage(0);
break;
default: return DefWindowProc(DVhWnd, uMsg, wParam, lParam);

}
return 0;
}

see any thing wrong ?



[edited by - Oluseyi on September 10, 2002 5:36:32 PM]

Share this post


Link to post
Share on other sites