Thread: win32 listbox as mainwindow

  1. #1
    Registered User
    Join Date
    Jan 2008

    win32 listbox as mainwindow


    im trying to build a phonebook program with C language so:
    im looking for a way to make my main window a list box


    making the list box a child window but i want it to resize to the parent window`s size always

    right now it just opens as a window and wont get any text in it...

    im not gonna post the entire code, just a small one with initialzing a window coz this is where im stuck right now....
    would appreciat any help you can give me!

    #include <windows.h>
    #include <string.h>
    //#include <direct.h>
    #define  MAXPATH     256
    #define  MAXREAD    8192
    WNDPROC fnOldList ;
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
         static char szAppName[] = "Head" ;
         HWND        hwnd ;
         MSG         msg ;
         WNDCLASSEX  wndclass ;
    	 HDC         hdc ;
      //   int         i ;
         TEXTMETRIC  tm ;
    	 wndclass.cbSize        = sizeof (wndclass) ;         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1) ;
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;
    	 wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
         RegisterClassEx (&wndclass) ;
    			   hdc = GetDC (NULL) ;
                   GetTextMetrics (hdc, &tm) ;
                   ReleaseDC (NULL, hdc) ;
    	 hwnd = CreateWindow (szAppName, "listbox",
    				   tm.tmAveCharWidth, tm.tmHeight * 3,
    				   tm.tmAveCharWidth * 90 + GetSystemMetrics (SM_CXVSCROLL),
    				   tm.tmHeight * 25,
    				   NULL, NULL, hInstance, NULL) ;
       /*  hwnd = CreateWindow (szAppName, "File Head",
                              WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              NULL, NULL, hInstance, NULL) ;/**/
         ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;
         while (GetMessage (&msg, NULL, 0, 0))
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         return msg.wParam ;
    LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
         HDC             hdc ;
         switch (iMsg)
              case WM_CREATE :
       /*            hdc = GetDC (hwnd) ;
             //      SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
                   GetTextMetrics (hdc, &tm) ;
                   ReleaseDC (hwnd, hdc) ;
    			    SendMessage (hwnd, LB_ADDSTRING, 0, (LPARAM) "a msg") ;
                   hwndList = CreateWindow ("listbox", NULL,
                                  WS_CHILDWINDOW | WS_VISIBLE | LBS_STANDARD,
                                  tm.tmAveCharWidth, tm.tmHeight * 3,
                                  tm.tmAveCharWidth * 13 +
                                       GetSystemMetrics (SM_CXVSCROLL),
                                  tm.tmHeight * 10,
                                  hwnd, (HMENU) 1,
                                  (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
                                  NULL) ;
      return 0 ;
              case WM_DESTROY :
                   PostQuitMessage (0) ;
                   return 0 ;
         return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
    Last edited by robig2; 01-08-2008 at 03:13 AM.

  2. #2
    Registered User
    Join Date
    Jan 2008
    hmm, it seems ive posted this message on the wrong forum. can an admin please move it to windows programming?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Join Date
    Jan 2002
    making the list box a child window
    This is the preferred approach. Create the main, parent window in your WinMain function and create the child listbox control in its WM_CREATE handler.
    i want it to resize to the parent window`s size always
    Handle the parent's WM_SIZE message and use MoveWindow with the listbox control's handle - there's a description of a similar issue in this recent thread which should be of some help in this regard.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Jan 2008
    IT WORKS!!!

    after i posted that question ive changed it to a child manu and then ive tried sending the list handle WM_SIZE messages but that didnt work, then ive found SetWindowPos() but that didnt work either...

    Thank you so much! ive been busting my brains on this all day.... and now i can finaly move on

  6. #6
    Registered User
    Join Date
    Jan 2008
    I have a list box as my main window, with also a File, Tools etc menu on it. I just open up a dialog as the main 'window' without all that extra window crap, then used Visual Studio to make a List Box... Easy enough?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ListBox Extra Data Storage
    By Welder in forum Windows Programming
    Replies: 1
    Last Post: 11-01-2007, 01:46 PM
  2. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  3. cant load dialog with listbox, help
    By terracota in forum Windows Programming
    Replies: 2
    Last Post: 11-22-2004, 07:11 PM
  4. How to cast a ListBox item to an int for a switch statment?
    By Swaine777 in forum C++ Programming
    Replies: 8
    Last Post: 09-26-2004, 08:52 PM
  5. Getting FULL filename from listbox
    By Garfield in forum Windows Programming
    Replies: 8
    Last Post: 01-27-2002, 08:28 AM