www.pudn.com > SDK 工具条,分割条,TREE 等控件演示代码.rar > listviewchat.cpp


#include "WinMain.h" 
#include "listviewchat.h" 
#include  
#include "childwindow.h" 
extern HINSTANCE hInst; 
 
extern HWND hwnd; 
 
HWND hListbox; 
 //= NULL;  
 
RECT listboxrect; 
 
 
 
LRESULT AddItem(HWND hwnds, LPSTR lpstr); 
 
BOOL CreateListViewChat(HWND hWnd) 
{ 
GetClientRect(hListbox, &listboxrect);  
hListbox = CreateWindowEx( 
						  //0, 
						  WS_EX_CLIENTEDGE, // Give the list box a sunken border 
                                "Listbox",        // The class name of our lisbox; leave this alone! 
                                "", 
                                WS_CHILD |  
								WS_VISIBLE | 
								LBS_NOTIFY | 
								WS_TABSTOP | 
								WS_VSCROLL, // WS_CHILD - this is a child window 
                                                                                     
                                    
 
					 
                                                                                     
                                                                                                // LBS_NOTIFY - notify the parent window when the user selects an item 
                                                                                                                                                                                       
                                                                                                // WS_TABSTOP - when the user tabs through items let the focus land on this control 
                                                                                                  
                                                                                                 //WS_VSCROLL - give us a vertical scrollbar 
                                                                                               
                                0,0, 
								200, 
								20, // Size and position 
                                hWnd,  //We use the hwnd parameter instead of the hMainWindow because 
                                        // this procedure with this message is invoked before CreateWindowEx 
                                        // returns.  Thus the hMainWindow variable isn't set to the handle 
                                        // yet.  So we just use hwnd for the handle because its the correct 
                                         //window. 
                                       
                                NULL, 
//										 (HMENU)IDL_LISTBOX, // Assign the control id for this window.  It's got to 
                                                     // be converted to HMENU because thats what this parameter  
                                                     // requires. 
                                                    
                                hInst, 
                                NULL); 
                                 
    HFONT  hDefaultFont  = (HFONT) GetStockObject(DEFAULT_GUI_FONT); // Gets the default font object 
       
      SendMessage(hListbox, WM_SETFONT, (WPARAM)hDefaultFont, MAKELPARAM(FALSE, 0));  //See for some reason create 
                                                                                       // window just insists on making 
                                                                                        //our windows look all ugly by 
                                                                                        //giving them a stupid font to 
                                                                                        //start with.  So what we do here 
                                                                                       // is change the font that the 
                                                                                       // control uses to the default one 
                                                                                       // by windows.  
 
      AddItem(hListbox, "Item 1");    // \' 
      AddItem(hListbox, "Item 2");    //  \' 
      AddItem(hListbox, "Item 3");    //   \' 
      AddItem(hListbox, "Item 4");    //    \' 
      AddItem(hListbox, "Item 5");    //     \' 
      AddItem(hListbox, "Item 6");    //      \' 
      AddItem(hListbox, "Item 7");    //       \' 
      AddItem(hListbox, "Item 8");    //        > Add some items to the list box 
      AddItem(hListbox, "Item 9");    //       /' 
      AddItem(hListbox, "Item 10");   //      /' 
      AddItem(hListbox, "Item 11");   //     /' 
      AddItem(hListbox, "Item 12");   //    /' 
      AddItem(hListbox, "Item 13");   //   /' 
      AddItem(hListbox, "Item 14");   //  /' 
      AddItem(hListbox, "Item 15");   // /' 
 
//SetWindowLong(hListbox,  
      //       GWL_EXSTYLE, 
     //       GetWindowLong(hListbox, GWL_EXSTYLE));  
		//	  | WS_EX_LAYERED); 
 
// Make this window 70% alpha 
//SetLayeredWindowAttributes(hListbox, 0, 128,2); 
		//			   LWA_ALPHA); 
 //SetLayeredWindowAttributes(hWnd, 0,"128",2); 
 
	  return 1; 
       
} 
 
LRESULT AddItem(HWND hwnds, LPSTR lpstr)   
{  
  
return SendMessage(hwnds, LB_ADDSTRING, 0, (LPARAM)lpstr); /* This just sends a message to the lb for you 
                                                               Check MSDN for a complete list of commands 
                                                               you may send to listboxes to get information */ 
}