Question about creating a specific child window type

This is a discussion on Question about creating a specific child window type within the Windows Programming forums, part of the Platform Specific Boards category; I'm looking to include a child window in my program that works similar to the way a window works when ...

  1. #1
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728

    Question about creating a specific child window type

    I'm looking to include a child window in my program that works similar to the way a window works when you view a folder in Details mode. I want to have a number of columns that can be resized, contains headers, and can be populated with text that can be selected and highlighted similar to a listbox. Being able to sort by column isn't necessary. If you open a Windows folder in details mode you'll see more or less what I'm going for just by looking at the working section of the window, not the details section to the left or the menu buttons up top.

    Is there a template or an easy way to create something like this, or do I need to figure out how to code all the details and nuances myself?

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Brilliant, thanks!

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Having problems trying to create this listview box. MSDN says to use such identifies as WC_LISTVIEW and LVS_REPORT but these are showing up as undeclared identifies in MSVC++ 6.0, is there some header I'm missing or are there updated versions of these?

  5. #5
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Did you #include <commctrl.h> ?

  6. #6
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Thanks, that did the trick!

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

  8. #8
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Thanks for the help guys but I'm still having a couple of problems. I'm very new to playing with multiple windows unfortunately so I'm not sure what I'm doing wrong. Basically what I'm doing is when the user chooses a menu option (ID VIEW_QUEUE) a window opens up that contains a viewlist. For some reason, all that is opening up is a blank standard window with nothing on it. What am I doing wrong? I'm just copying and pasting from the example you gave anonytmouse. The code works fine if I place it in the main window, but when I try to call it from the subwindow I just get white nothing. Sorry for the mess of code, theres a lot of gunk in there from me simply testing out random things like process execution and threads. The problem process is at the very bottom in ViewQueueProc.
    Code:
    #include<windows.h>
    #include<math.h>
    #include<time.h>
    #include<process.h>
    #include<queue>
    #include<commctrl.h>
    #include "resource.h"
    #include <stdio.h>
    #pragma comment(lib, "gdi32.lib")
    #pragma comment(lib, "comctl32.lib")
    
    using namespace std;
    
    TCHAR szAppName[]=TEXT("Assessment Runner");
    
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    LRESULT APIENTRY ViewQueueProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    BOOL CALLBACK MainDialogProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
    {
    	HMENU hMenu;
    	srand(time(NULL));
    	HWND hwnd;   // handle to a window
    	MSG msg;   // message
    	WNDCLASS wndclass;  // window class we are declaring
    
    	INITCOMMONCONTROLSEX icc = { 0 };
    
    	icc.dwSize = sizeof(icc);
    	icc.dwICC = ICC_LISTVIEW_CLASSES;
    	InitCommonControlsEx(&icc);
    
    	// Now we set the attributes for our window
    	wndclass.style=CS_HREDRAW | CS_VREDRAW;  // Style, in this case can be redrawn
    	wndclass.lpfnWndProc=WndProc;  // window process name - handles message calls
    	wndclass.cbClsExtra=0;  // Extra space for the window
    	wndclass.cbWndExtra=0;  // ditto
    	wndclass.hInstance=hInstance;  // program instance name passed to WinMain
    	wndclass.hIcon=LoadIcon(NULL, IDI_APPLICATION);  // Load icon for the tray
    	wndclass.hCursor=LoadCursor(NULL, IDC_ARROW);  // Load icon for the mouse arrow
    	wndclass.hbrBackground=(HBRUSH) GetStockObject(WHITE_BRUSH);  // Load background color
    	wndclass.lpszMenuName=NULL;  // Set menu - none here
    	wndclass.lpszClassName=szAppName;  // Sets window name, taken from above
    
    	hMenu=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1));
    
    	if (!RegisterClass(&wndclass))
    	{
    		MessageBox(NULL, TEXT("Error running program!"), szAppName, MB_ICONERROR);
    		return 0;
    	}
    
    
    
    	hwnd=CreateWindow(szAppName, TEXT("Assessment Runer"), WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenu,
    		hInstance, NULL);  // Create the window!  Name, Title, Style, x Position, y Position
    	                       // X size, Y size, parent window handle, window menu handle, 
    						   // program instance handle, creation parameters(passing variables)
    
    
    	ShowWindow(hwnd, iCmdShow);  // now show the window!
    	UpdateWindow(hwnd);   // update it
    
    	while (GetMessage(&msg, NULL, 0, 0))  // gets message from mouse and keyboard, always non
    		                                  // zero until you quit the window
    	{
    		TranslateMessage(&msg);           // translates message from message queue (mouse/keyboard/etc)
    		DispatchMessage(&msg);			  // sends to WndProc to translate and tell what to do!
    	}
    
    	return msg.wParam;
    
    }
    
    
    void Thread (PVOID pvoid)
    {
    	char child1[] = "c:\\debug\\test.exe";
    
    	MessageBox(NULL, TEXT("Before executing program Thread!"), szAppName, MB_ICONERROR);
    	
    	system(child1);
    
    	MessageBox(NULL, TEXT("After executing program Thread!"), szAppName, MB_ICONERROR);
    	
    	_endthread();
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static HWND hwndViewQueue;
    	static HINSTANCE hInstance;
    	WNDCLASS wndclass;
    
    	switch (message)
    	{
    	case WM_CREATE:
    		hInstance=((LPCREATESTRUCT) lParam)->hInstance;
    
    	case WM_COMMAND:
    		switch (LOWORD(wParam))
    		{
    		case ID_TEST_TEST:
    			DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, MainDialogProc);
    			break;
    		case RUN_QUEUE:
    			MessageBox(NULL, TEXT("Before Thread!"), szAppName, MB_ICONERROR);
    			_beginthread(Thread, 0, NULL);
    			break;
    		case VIEW_QUEUE:
    			wndclass.style=CS_HREDRAW|CS_VREDRAW;
    			wndclass.lpfnWndProc=ViewQueueProc;
    			wndclass.cbClsExtra=0;
    			wndclass.cbWndExtra=0;
    			wndclass.hInstance=hInstance;
    			wndclass.hIcon=NULL;
    			wndclass.hCursor=LoadCursor(NULL, IDC_ARROW); 
    			wndclass.hbrBackground=(HBRUSH) GetStockObject(WHITE_BRUSH);
    			wndclass.lpszMenuName=NULL;
    			wndclass.lpszClassName=WC_LISTVIEW;
    
    			RegisterClass(&wndclass);
    
    			hwndViewQueue=CreateWindow(WC_LISTVIEW, NULL, WS_OVERLAPPEDWINDOW , 
    				200, 200, 300, 300, hwnd, 0, hInstance, NULL);
    
    			ShowWindow(hwndViewQueue, SW_SHOWNORMAL);  // now show the window!
    			UpdateWindow(hwnd);   // update it
    
      		
    			break;
    
    		}
    
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	}
    
    	return DefWindowProc(hwnd, message, wParam, lParam);
    }
    
    
    
    
    
    BOOL CALLBACK MainDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static HWND hwndCombo, hwndList;
    
    	switch (message)
    	{
    	case WM_INITDIALOG:
    		hwndCombo=GetDlgItem(hDlg, IDC_COMBO1);
    		SendMessage(hwndCombo, CB_ADDSTRING,0,(LPARAM) "Test");
    		SendMessage(hwndCombo, CB_ADDSTRING,0,(LPARAM) "Test2");
    		SendMessage(hwndCombo, CB_ADDSTRING,0,(LPARAM) "Test3");
    		SendMessage(hwndCombo, CB_ADDSTRING,0,(LPARAM) "Test4");
    		return TRUE;
    
    
    	case WM_COMMAND:
    		switch (LOWORD (wParam))
    		{
    		case IDC_COMBO1:
    			return TRUE;
    		case IDOK:
    			EndDialog(hDlg, TRUE);
    			return TRUE;
    		}
    		break;
    	}
    
    	return FALSE;
    }
    
    LRESULT APIENTRY ViewQueueProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	HWND hListView;
    	static HINSTANCE hInstance;
    
        LVCOLUMN lvc = { 0 };
        LVITEM   lv  = { 0 };
    	switch (message)
    	{
    	case WM_CREATE:
    		hInstance=((LPCREATESTRUCT) lParam)->hInstance;
    
            hListView = CreateWindow(WC_LISTVIEW,
                                     NULL,
                                     WS_CHILD | WS_VISIBLE | LVS_REPORT,
                                     10,
                                     10,
                                     500,
                                     500,
                                     hwnd,
                                     (HMENU) 500,
                                     hInstance,
                                     NULL);
    
    	    ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
    
            lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH  | LVCF_FMT;
            lvc.fmt  = LVCFMT_LEFT;
    
            /* Add four columns to the list-view (first column contains check box). */
            lvc.iSubItem = 0;
            lvc.cx       = 50;
            lvc.pszText  = TEXT("Record");
            ListView_InsertColumn(hListView, 0, &lvc);
    
            lvc.iSubItem = 1;
            lvc.cx       = 100;
            lvc.pszText  = TEXT("Name");
            ListView_InsertColumn(hListView, 1, &lvc);
    
            lvc.iSubItem = 2;
            lvc.cx       = 70;
            lvc.pszText  = TEXT("Episodes");
            ListView_InsertColumn(hListView, 2, &lvc);
    
            lvc.iSubItem = 3;
            lvc.cx       = 150;
            lvc.pszText  = TEXT("Any Good?");
            ListView_InsertColumn(hListView, 3, &lvc);
    
            /* Add some rows. */
            lv.iItem = 0;
            ListView_InsertItem(hListView, &lv);
            ListView_SetItemText(hListView, 0, 0, TEXT("Duh"));
            ListView_SetItemText(hListView, 0, 1, TEXT("Friends"));
            ListView_SetItemText(hListView, 0, 2, TEXT("500"));
            ListView_SetItemText(hListView, 0, 3, TEXT("Alright"));
    
            lv.iItem = 1;
            ListView_InsertItem(hListView, &lv);
            ListView_SetItemText(hListView, 1, 0, TEXT("Duh again"));
            ListView_SetItemText(hListView, 1, 1, TEXT("Survivor"));
            ListView_SetItemText(hListView, 1, 2, TEXT("970,000"));
            ListView_SetItemText(hListView, 1, 3, TEXT("Please, not again"));
                        
            break;
    		
    
    	case WM_DESTROY:
    		return 0;
    
    	}
    	
    	return DefWindowProc(hwnd, message, wParam, lParam);
    }

  9. #9
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Nevermind, accidentally left the window style as WC_LISTVIEW

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Parent not repainting Bitmp after child window closes
    By CodeX in forum Windows Programming
    Replies: 5
    Last Post: 10-05-2006, 01:03 AM
  3. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21