• Announcements

Archived

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

using win api and open gl in the same app

Recommended Posts

Is this possible? I got the dialog up but the animation stops since it stops running the drawgl scene function while it''s in the message loop. Is there a way to do both? I have a star field simulation and the the dialog pop''s up but I want the stars to keep on moving while, waiting for user input on the dialog. I can''t just call the draw gl sceene function in the message loop since it is defined after so the compiler will not find it. If I put the win api code after, I will not be able to call that from the draw scene. I''m in a hard situation right now! Please let me know what I have to do, thanks! By the way, I think I posted this before but I forgot to check it and it''s gone past page 3 in del heaven!

Share on other sites
Nothing prevents you from putting a declaration of your GL function prior to the definition of you message loop.

void display();whatever MessageLoop( whatever ){  display();}void display(){  //  draw stuff}

Share on other sites
I think this will solve your problem:

Look up Modal and Modeless dialogs. I think Modal is the default one (it acts like the window that pops up when you call MessageBox(). Modeless makes a new execution thread, and allows the parent window to continue running its message loop (I''m pretty sure that''s how it works). Just do a search in google.

I''v done it in MFC before, but never in win32. It can''t be much different.

Here, I found a good website on MSDN Home that lists the functions you can use to make a modeless and modal dialog in Windows.
Go Here

Share on other sites
Use function prototypes. They tell the compiler that a function will appear later in the code. For example, the compiler would give you an error in this code because it doesn''t know about the second fucntion yet:
  void function1(void){ function2(); doSomething();}void function2(void){ doSomethingElse();}

To get that to work without having to place the second function before the first function in your code, do this:
  // This is a prototype - the function declaration plus a semicolon instead of a bodyvoid function2(void);void function1(void){ function2(); doSomething();}void function2(void){ doSomethingElse();}

Share on other sites
Thanks, that works but now I got another problem. It does not call it fromt he win api loop. Did I do something wrong in this win api code?

BOOL MainDialog_OnCommand(HWND hWnd, WORD wCommand, WORD wNotify, HWND hControl)
{

DrawGLScene();

switch (wCommand)
{

case IDC_EXIT:
{
EndDialog(hWnd,0);
PlaySound("explode.wav",NULL,SND_FILENAME);
exit(0);
}
break;

}
return TRUE;
}

BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{

case WM_INITDIALOG:
{

// Put dialog box initialisers here
return 0;
}
break;

case WM_COMMAND:
return MainDialog_OnCommand(hWnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
break;

case WM_CLOSE:

EndDialog(hWnd, 0);
return TRUE;
}
return FALSE;
}

I tried diffrent places with diffrent resaults. Is there a special case statement I need to add in for stuff like this? Thanks!

Share on other sites
The problem is that you have put the draw call in the dialog callback (which is only called when you have done something in the dialog). You have to insert the call into the actual message loop (which escapes me at this moment).

What I did to handle a similiar case was to setup a timer thread that calls the draw every X amount of time (I used .125 seconds).

Share on other sites
You can do 2 things:

1. Create a second thread. The second thread is used for displaying Win32 GUI stuff. This thread has a local message loop to handle just the Win32 GUI messages.

2. Use modeless dialogs. Modeless dialogs require you to pump the dialog messages in your main message loop, calling IsDialogMessage() on each message (IsDialogMessage() handles dispatching the message to the dialog, if it is intended for the dialog). Then inside your main message loop put your call to your rendering code.

If you use Modal dialogs on your main thread, then that thread is stuck in the message loop for the modal dialog until the dialog exits, so you either have to call your render function from the dialog''s message proc, or have your rendering pause while the dialog is up.

Doing either #1 or #2 is pretty simple, and is the correct way to write your Win32 app.

• Partner Spotlight

• Forum Statistics

• Total Topics
627639
• Total Posts
2978345

• 10
• 12
• 22
• 13
• 33