title: Win32: How to create a ListBox control using the CreateWindowExW() function?
body: <p>I've been through multiple sites, documents and tutorials and they all say the same, that is, any control is nothing more than a window in Win32's API, hence one is able to use the <code>CreateWindowExW()</code> function to create a <code>ListBox</code> control/window over the main application window.</p>
  
  <p>Though I get the concepts of all controls being windows with different <em>dwStyle</em>, I have a hard time finding out how to instantiate, to say so, the <code>ListBox</code> control.</p>
  
  <p>I encountered a tutorial where a dialog is written to have a <code>LISTBOX</code> specified in its declaration as follows:</p>
  
  <pre><code>// resource.h
  #define IDD_MAIN                        101
  #define IDC_TEXT                        1000
  #define IDC_NUMBER                      1001
  #define IDC_LIST                        1002
  #define IDC_ADD                         1003
  #define IDC_CLEAR                       1004
  #define IDC_REMOVE                      1005
  #define IDC_SHOWCOUNT                   1006
  
  // .rc resource file
  IDD_MAIN DIALOG DISCARDABLE  0, 0, 207, 156
      STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
      CAPTION "Controls One"
      FONT 8, "MS Sans Serif"
  BEGIN
      LTEXT           "Add",IDC_STATIC,7,10,14,8
      EDITTEXT        IDC_TEXT,25,7,120,14,ES_AUTOHSCROLL
      EDITTEXT        IDC_NUMBER,150,7,21,14,ES_NUMBER
      LTEXT           "times.",IDC_STATIC,177,10,23,8
      LISTBOX         IDC_LIST,7,25,138,106,LBS_NOINTEGRALHEIGHT | 
                      LBS_EXTENDEDSEL | WS_VSCROLL | WS_TABSTOP
      PUSHBUTTON      "&amp;Add",IDC_ADD,150,30,50,14
      PUSHBUTTON      "&amp;Remove",IDC_REMOVE,150,47,50,14
      PUSHBUTTON      "&amp;Clear",IDC_CLEAR,150,63,50,14
      LTEXT           "This item was added",IDC_STATIC,7,141,66,8
      CTEXT           "-",IDC_SHOWCOUNT,77,141,32,8
      LTEXT           "times",IDC_STATIC,114,141,17,8
  END
  </code></pre>
  
  <p>And using it in his C program like so:</p>
  
  <pre><code>int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
      return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
  }
  </code></pre>
  
  <p>Now, this I am able to do and fully understand the concepts. Aside, I would like to be able to create and design my main application window to add a <code>ListBox</code> control to. This tutorial example doesn't use the <code>CreateWindowExW()</code> function to create the control, instead, it creates a dialog that will actually be the main application window.</p>
  
  <p>1 - <strong>Any clue on how to add a <code>ListBox</code> control to the main window in code?</strong></p>
  
  <p>I thought about creating it while handling the <strong>WM_CREATE</strong> message.</p>
  
  <p>2 - <strong>Is this a good idea?</strong></p>
  
  <p>3 - <strong>What is the best practice/approach in this scenario?</strong></p>