Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why modeless dialog is not working properly?

Status
Not open for further replies.

abhijit123

Programmer
Sep 26, 2002
17
US
Hi

I am a new VC++ programmer and struggling in processing the messages in Modeless Dialogs.Hope someone can help me..

I am developing modeless dialogs for a CAD application(Unigraphics), which has a Win32 API.It has is his own Wizard and start function is other than Win_Main/DLL_Main. I am building a dll...

As the parameter HINSTANCE hInstance is not available directly i am obtaining it through GetModuleHandle(dllName).

I am getting a Handle(hWndUG) of the Unigraphics Window through GetActiveWindow.

The Modeless Dialog is created with
hDialog = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),hWndUG,AboutDlgProc)Function.

The parent window handle used is Unigraphics Window Handle(hWndUG),application handle is hInstance and I am defining a dialog procedure for this dialog.

I have a provision of calling a DLL in Unigrapgics.The Dialog is appearing properly and able to process desired functionality.However though it is a modeless dialog it is behaving like modal dialog and not allowing me to do any functionality in Unigraphics. Even after closing the dialog, I am not able to do anything. I am required to kill the application everytime to come out.


For message processing I am using

while(GetMessage (&msg, NULL, 0, 0))
{
if(hDialog != NULL || IsDialogMessage(hDialog,&msg)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

The dialog procedure code is:

BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG :
return TRUE ;

case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDOK :
case IDCANCEL :
EndDialog (hDlg, 0) ;
return TRUE ;
case IDC_BUTTON1:
return TRUE;
default:
return FALSE;
}
break ;
}
return FALSE ;
}



Can anyone tell me what is the problem.Hope to hear from you..

Thanks
Abhijit
 
First i think that you are tring to use VC, so use it:

Create a class derived from CDialog / Named Derivate/and all
functions you need.
In main Window class crate member var of type Derivate

Now you can use member func:
Create( nID, CWnd* pParentWnd =NULL)
**NULL means that parent window is set to the main aplication window.

Class Derivate encapsulates all functions like OnOK, OnButton1, OnCancel. So, i think that if you do all of that you'll not have any problems with no modal dialogs(modal too).
Of cource you can create no modal dialog by API func too, but you mast create another thread for this dialog.
 
Thanks for your suggestions. I tried to implement the same however the dialog created vanishes automatically after it is created.See the code below:

Dialog test = new Dialog();
BOOL isDialogCreated = test.Create();// Create is a member function in Dialog

CString temp = "test";
if(isDialogCreated == TRUE)
temp = "Created";
else
temp = "Not created";

MessageBox(hWndUG,temp,"Message",0);
if i dont use the message box the dialog comes and goes automatically. But with message box the dialog is displayed and it processes all the messages.. But if click ok on message box dialog also goes of.

what may be the reason..








 
From what I understand of your code above:

"test" is a variable of type Dialog, not of type Dialog *, therefore "= new Dialog" does not do anything (I am surprised you don't get a compiler error there).

"test" is a local variable. Therefore, as soon as it goes out of scope (at the end of the function in which it is declared), it is destroyed (and your Dialog receives the WM_DESTROY message), thus the dialog disapears. Make "test" a global variable, or a member variable if you are using classes.

I hope this helps,

Vincent
 
Thanks for the tip.. in two days i have realized how important these discussions forums are..

Your tip has worked to an extent that dialog is appearing .. But the problem is that when i try to do anything(mouse movement on dialog/click) on dialog/parent application the entire application gets closed..

What should be the problem?
 
Can you send me a part of your code to my email, Iwant to take a look. My Mail is aaamil13@hotmail.com
 

You need to learn what you're doing. I'm not trying to be mean, I'm trying to be helpful. If you can't even get a dialog box to show up how long do you think it will take you to get the application working? Make sure you understand object oriented programming, VC++, MFC, and how to use Visual Studio correctly. You'll save yourself lots of time. By looking at your code I can see you are making things harder then they need to be. Take advantage of what OOP has to offer.

Good luck,

Brother C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top