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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Createwindow (Beginner)

Status
Not open for further replies.

Chimpster

Technical User
Apr 14, 2003
1
GB
Hi, i was wondering how i can use a dialog from my resource as the main window.

I have the callback etc just need to know howto draw my dialog as the parent.

Many Thanks.
 
Chimpster,

Are you following a tutorial from a book or something? If not you should be, trying to guess your way into developing C++ Windows applications will be a slo process.

If you are using a tutorial resource, doesn't it cover that topic in detail?

-pete
 
Just create the dialog before the main message loop, e.g.
Code:
int WINAPI WinMain(HINSTANCE hinst,
                   HINSTANCE hprev,
                   LPSTR cmd,
                   int show)
{
  MSG msg;

  CreateDialog(hinst, (templatename), 0, (dlgproc));
  
  while (GetMessage(&msg, 0, 0, 0))
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
}
The dialog box has to end the program by using PostQuitMessage() function.
Hope that helps.
Adonai :)
 
>> The dialog box has to end the program by using PostQuitMessage() function.

Not really. If all you want is a modal dialog as your main window, you don't need a message loop. But call DialogBox(...) instead of CreateDialog, this will make the dialog modal.

DialogBox doesn't return until the dialog is over. Then after that, simply return a value in WinMain.

Then, your program will be done.
 
Quite True, apatterno.
I used the CreateDialog for a few reasons though.
1) It is close to the CreateWindowEx, and with the message loop it would probably be more easy to convert a simple 'main window' application to a 'main dialog' application.
2) Using the DialogBox() function is OK, but if you wanted to create another dialog or window, you would have to end the main dialog first.

A very good point though. I suppose it depends on what the dialog box is going to do.
Adonai :)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top