<p>So, I am a total beginner in any kind of <code>Windows</code> related programming. I have been playing around with the <code>Windows</code> <code>API</code> and came across a couple of examples on how to initialize create windows and such. </p>

<p>One example creates a regular window (I abbreviated some of the code):</p>

<pre><code>int WINAPI WinMain( [...] )
{

    [...]

    // Windows Class setup
    wndClass.cbSize = sizeof( wndClass );
    wndClass.style  = CS_HREDRAW | CS_VREDRAW;
    [...]    

    // Register class
    RegisterClassEx( &amp;wndClass );

    // Create window
    hWnd = CreateWindow( szAppName, "Win32 App",
                         WS_OVERLAPPEDWINDOW,
                         0, 0, 512, 384,
                         NULL, NULL, hInstance, NULL );
    [...]
}
</code></pre>

<p>The second example creates a dialog box (no abbreviations except the WinMain arguments):</p>

<pre><code>int WINAPI WinMain( [...] )
{
    // Create dialog box
    DialogBox(hInstance, 
              MAKEINTRESOURCE(IDD_MAIN_DLG), 
              NULL, 
              (DLGPROC)DialogProc);
}
</code></pre>

<p>The second example does not contain any call to the register function. It just creates the DialogBox with its DialogProc process attached. </p>

<p>This works fine, but I am wondering if there is a benefit of registering the window class and then creating the dialog box (if this is at all possible). </p>

[{'answer_id': 36986, 'author': 'Mark Biek', 'author_id': 305, 'author_profile': 'https://Stackoverflow.com/users/305', 'pm_score': 0, 'selected': False, 'text': "<p>I've always done it exactly the way you're describing.  I'm curious to see if there's a more accepted approach.</p>\n"}, {'answer_id': 36988, 'author': 'Chris Karcher', 'author_id': 2773, 'author_profile': 'https://Stackoverflow.com/users/2773', 'pm_score': 2, 'selected': False, 'text': "<blockquote>\n  <p><em>is there a more standard pattern for doing stuff like this?</em></p>\n</blockquote>\n\n<p>No, it sounds like you're using the right approach.</p>\n\n<p>If the dialog returns DialogResult.OK, assume that all the necessary properties in the dialog are valid.</p>\n"}, {'answer_id': 36993, 'author': 'flipdoubt', 'author_id': 470, 'author_profile': 'https://Stackoverflow.com/users/470', 'pm_score': 4, 'selected': True, 'text': "<p>I would say exposing properties on your custom dialog is the idiomatic way to go because that is how standard dialogs (like the Select/OpenFileDialog) do it. Someone could argue it is more explicit and intention revealing to have a ShowBirthdayDialog() method that returns the result you're looking for, but following the framework's pattern is probably the wise way to go.</p>\n"}, {'answer_id': 37008, 'author': 'Murph', 'author_id': 1070, 'author_profile': 'https://Stackoverflow.com/users/1070', 'pm_score': 2, 'selected': False, 'text': "<p>For me sticking with the Dialog returning the standard dialog responses and then accessing the results via properties is the way to go.</p>\n\n<p>Two good reasons from where I sit:</p>\n\n<ol>\n<li>Consistency - you're always doing the same thing with a dialog and the very nature of the question suggests that patterns are good (-: Although equally the question is whether this is a good pattern?</li>\n<li>It allows for return of multiple values from the dialog - ok there's whole new discussion here too but applied pragmatism means that this is what one wants in some circumstances its not always appropriate or desirable to package values up just so that you can pass them back in all in one go.</li>\n</ol>\n\n<p>The flow of logic is nice too:</p>\n\n<pre><code>if (Dialog == Ok)\n{\n    // Do Stuff with the entered values\n}\nelse\n{\n    // Respond appropriately to the user cancelling the dialog\n}\n</code></pre>\n\n<p>Its a good question - we're supposed to question stuff like this - but for me the current pattern is a decent one.</p>\n\n<p>Murph</p>\n"}, {'answer_id': 37037, 'author': 'Mark Brackett', 'author_id': 2199, 'author_profile': 'https://Stackoverflow.com/users/2199', 'pm_score': 1, 'selected': False, 'text': "<p>For modal input dialogs, I typically overload ShowDialog and pass out params for the data I need.</p>\n\n<pre><code>DialogResult ShowDialog(out datetime birthday)\n</code></pre>\n\n<p>I generally find that it's easier to discover and understand vs mixing my properties with the 100+ that the Form class exposes.</p>\n\n<p>For forms, I normally have a Controller and a IView interface that uses readonly properties to pass data.</p>\n"}]
['https://Stackoverflow.com/questions/36991', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2386/']