Page 1 of 1

Microsoft : Working With The Header Control Using a header control to show column content Rate Topic: -----

#1 Martyn.Rae  Icon User is offline

  • The programming dinosaur
  • member icon

Reputation: 540
  • View blog
  • Posts: 1,406
  • Joined: 22-August 09

Posted 01 April 2010 - 04:58 AM

Microsoft : Working With The Header Control

Introduction

The header control is an extremely useful control for listboxes, views and your own list-type windows. This tutorial takes a look at how you use it in an application.

The first thing we need to do is to create a frame window that contains a listbox. This will be our base code that we can use to create a header control.

The header control is going to be a chid window of the listbox, and as a result of that we will need to subclass the listbox. This is in order to intercept messages that the header control may send to it's parent - the listbox control.

#include <windows.h>  
#include <CommCtrl.h> 
#include <ctime>  
#include <cstdlib>  
using namespace std;

#pragma comment(lib, "comctl32.lib")

class listbox_control {
    private:
        HINSTANCE instance_handle;
        HWND parent_handle;
        HWND listbox_handle;
        WNDPROC listbox_proc;
    public:
        listbox_control(HINSTANCE instance, HWND parent, int x, int y, int width, int height) 
                      : instance_handle(instance), parent_handle(parent) {
            listbox_handle = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTBOX, NULL,
                                            WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT, 
                                            20, 20, width-40,
                                            height-40, parent_handle, NULL,
                                            instance_handle, NULL);
            listbox_proc = (WNDPROC)SetWindowLongPtr(listbox_handle, GWL_WNDPROC, 
                                                     (LONG)listbox_window_proc);
            SetWindowLongPtr(listbox_handle, GWL_USERDATA, (LONG)this);
        }
        void set_window_size(int width, int height) {
            SetWindowPos(listbox_handle, NULL, 0, 0, width, height, SWP_NOMOVE|SWP_NOZORDER);
        }
        static LRESULT listbox_window_proc(HWND hwnd, UINT message,    
                                           WPARAM wparam, LPARAM lparam) {
            listbox_control * This = (listbox_control *)GetWindowLongPtr(hwnd, GWL_USERDATA);
            return This->listbox_proc(hwnd, message, wparam, lparam);
        }
};

class frame_window {
    private:
        LPWSTR window_class_name;  
        HINSTANCE instance_handle;  
        HCURSOR cursor_arrow;  
        HWND window_handle;
        HWND header_handle;
        RECT client_rectangle;
        listbox_control * listbox;
    public:
        frame_window(LPWSTR window_class_identity) : window_class_name(window_class_identity) {         
            int screen_width = GetSystemMetrics(SM_CXFULLSCREEN);  
            int screen_height = GetSystemMetrics(SM_CYFULLSCREEN);  
            instance_handle = GetModuleHandle(NULL);  
               
            WNDCLASS window_class = { CS_OWNDC, main_window_proc, 0, 0,    
                                      instance_handle, NULL,    
                                      NULL, NULL, NULL,    
                                      window_class_name };   
            
            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
            // Create a standard frame window   
            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
            
            RegisterClass(&window_class);   
            window_handle = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,    
                                           window_class_name,    
                                           L"Header Control Example",   
                                           WS_OVERLAPPEDWINDOW | 
                                           WS_CLIPCHILDREN | WS_CLIPSIBLINGS,   
                                           (screen_width-900)/2, (screen_height-700)/2, 
                                           900, 700, 
                                           NULL, NULL, instance_handle, NULL);
            GetClientRect(window_handle, &client_rectangle);
            int width = client_rectangle.right - client_rectangle.left;
            int height = client_rectangle.bottom - client_rectangle.top;
            listbox = new listbox_control(instance_handle, window_handle, 
                                          20, 20, width-40, height-40);
            SetCursor(LoadCursor(NULL, IDC_ARROW)); 
            SetWindowLongPtr(window_handle, GWL_USERDATA, (LONG)this);  
            ShowWindow(window_handle, SW_SHOW);   
            UpdateWindow(window_handle); 
        }  
        ~frame_window() {  
            UnregisterClass(window_class_name, instance_handle);   
        }  
        
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
        // Windows message processing function   
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
        static LRESULT WINAPI main_window_proc(HWND window_handle, UINT message,    
                                               WPARAM wparam, LPARAM lparam) {  
            frame_window *This = (frame_window *)GetWindowLongPtr(window_handle, GWL_USERDATA);  
            switch ( message ) {  
                case WM_PAINT:   
                {   
                    PAINTSTRUCT paint_structure;   
                    RECT client_rect;   
                    HDC paint_device_context, paint_dc;   
                    HBITMAP bitmap;   
  
                    paint_device_context = BeginPaint(window_handle, &paint_structure);   
                    paint_dc = CreateCompatibleDC(paint_device_context);   
                    GetClientRect(window_handle, &client_rect);   
                    int window_width = client_rect.right - client_rect.left;  
                    int window_height = client_rect.bottom - client_rect.top;  
                    bitmap = CreateBitmap(window_width, window_height, 1, 32, NULL);  
                    HGDIOBJ old_bitmap = SelectObject(paint_dc, bitmap);  
  
                    // Fill the client aread with the user selected face colour  
                    HBRUSH light_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));  
                    FillRect(paint_dc, &paint_structure.rcPaint, light_brush);  
                    DeleteObject(light_brush);
                    BitBlt(paint_device_context, 0, 0,    
                           client_rect.right-client_rect.left,   
                           client_rect.bottom-client_rect.top,   
                           paint_dc, 0, 0, SRCCOPY);   
                    SelectObject(paint_dc, old_bitmap);   
                    DeleteObject(bitmap);   
                    DeleteDC(paint_dc);   
                    EndPaint(window_handle, &paint_structure);   
                    return 0;   
                }   
                case WM_ERASEBKGND:   
                {   
                    return TRUE;   
                }
                case WM_SIZE:   
                {
                   This->listbox->set_window_size(LOWORD(lparam)-40, 
                                                  HIWORD(lparam)-40);
                    InvalidateRect(window_handle, NULL, TRUE);   
                    return 0;   
                }
                case WM_COMMAND:
                {
                    return 0;
                }
                case WM_CLOSE:   
                {   
                    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    // The user wants to close the window   
                    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
           
                    PostQuitMessage(0);   
                    return 0;   
                }   
            }   
            return DefWindowProc(window_handle, message, wparam, lparam);   
        }   
          
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
        // Windows message loop   
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        void run() {  
            MSG window_message;   
            while ( GetMessage(&window_message, NULL, 0, 0) ) {   
                TranslateMessage(&window_message);   
                DispatchMessage(&window_message);   
            }   
        }  
};  
   
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
// Windows main entry point   
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
   
int WINAPI wWinMain(HINSTANCE instance_handle, HINSTANCE, LPWSTR, INT) {  
    frame_window main_window(L"my base window");
    main_window.run();  
    return 0;   
}



Creating a header control

To create a header control, we use the WC_HEADER class with the listbox window handle as it's parent. The code snippet taken from the example at the end of this tutorial shows this.

    header_handle = CreateWindowEx(0, WC_HEADER, NULL,
                                   WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT, 
                                   0, 0, width,
                                   20, parent_handle, NULL,
                                   instance_handle, NULL);



Adding header items to the control

To add items to the control, we use the SendMessage function passing a HDM_INSERTITEM message. The index position of the item is also passed along with a HDITEM structure that obviously needs to be filled out before the message is sent. The code snippet taken from the example at the end of this tutorial shows two header items being added to a header control.

    HDITEM item;
    item.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
    item.cxy = 200;
    item.fmt = HDF_STRING;
    item.pszText = L"Name";
    item.cchTextMax = 4;
    SendMessage(header_handle, HDM_INSERTITEM, 0, (LPARAM)&item);
    item.cxy = width-200;
    item.pszText = L"Status";
    item.cchTextMax = 6;
    SendMessage(header_handle, HDM_INSERTITEM, 1, (LPARAM)&item);



Getting and setting header information

You can get or set the information held by a header item by using the SendMessage function passing a HDM_GETITEM and HDM_SETITEM message with the index of the item you want and a HDITEM structure. Remember that the mask in this structure needs to contain the appropriate flags for the information you want when sending the HDM_GETITEM message. Similarly mask must contain the appropriate flags for the information you want to set, along with the fields in the structure that correspond to those flags for the HDM_SETITEM message.

Code Example

The following code example displays a frame window with a self-created list-type window that is populated with data. The header control is used to display the column header information, and the divider between the two columns can be moved varying the size of the two columns.

#include <windows.h>  
#include <CommCtrl.h> 
#include <ctime>  
#include <cstdlib>  
using namespace std;

#pragma comment(lib, "comctl32.lib")

class header_control {
    private:
        HINSTANCE instance_handle;
        HWND parent_handle;
        HWND header_handle;
        RECT client_rect;
    public:
        header_control(HINSTANCE instance, HWND parent) 
                     : instance_handle(instance), parent_handle(parent) {
            GetClientRect(parent_handle, &client_rect);
            int width = client_rect.right-client_rect.left;
            header_handle = CreateWindowEx(0, WC_HEADER, NULL,
                                           WS_CHILD | WS_VISIBLE | HDS_BUTTONS, 
                                           0, 0, width,
                                           20, parent_handle, NULL,
                                           instance_handle, NULL);
            HDITEM item;
            item.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
            item.cxy = 200;
            item.fmt = HDF_STRING;
            item.pszText = L"Name";
            item.cchTextMax = 4;
            SendMessage(header_handle, HDM_INSERTITEM, 0, (LPARAM)&item);
            item.cxy = width-200;
            item.pszText = L"Status";
            item.cchTextMax = 6;
            SendMessage(header_handle, HDM_INSERTITEM, 1, (LPARAM)&item);
        }
        void set_window_size() {
            GetClientRect(parent_handle, &client_rect);
            int width = client_rect.right-client_rect.left;
            HDITEM item;
            item.mask = HDI_WIDTH;
            item.cxy = width-200;
            SendMessage(header_handle, HDM_SETITEM, 1, (LPARAM)&item);
            SetWindowPos(header_handle, NULL, 0, 0, width, 20, SWP_NOMOVE|SWP_NOZORDER);
        }
        HWND get_handle() { return header_handle; };
};

class viewlist_control {
    private:
        HINSTANCE instance_handle;
        wchar_t * window_class_name;
        HWND parent_handle;
        HWND viewlist_handle;
        WNDPROC viewlist_proc;
        header_control * header;
        int item_count;
        wchar_t ** item_strings;
    public:
        viewlist_control(HINSTANCE instance, HWND parent, int x, int y, int width, int height) 
                       : instance_handle(instance), parent_handle(parent), window_class_name(L"MyViewList class"),
                         item_count(-1), item_strings(NULL) {
            WNDCLASS window_class = { CS_OWNDC, (WNDPROC)view_window_proc, 0, 0,    
                        instance_handle, NULL,    
                        NULL, NULL, NULL,    
                        window_class_name };   

            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
            // Create a standard frame window   
            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
            
            RegisterClass(&window_class);   
            viewlist_handle = CreateWindowEx(WS_EX_CLIENTEDGE, window_class_name, NULL,
                                            WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | 
                                            WS_VSCROLL, 
                                            20, 20, width-40,
                                            height-40, parent_handle, NULL,
                                            instance_handle, NULL);
            SetWindowLongPtr(viewlist_handle, GWL_USERDATA, (LONG)this);
            header = new header_control(instance, viewlist_handle);
        }
        void set_window_size(int width, int height) {
            SetWindowPos(viewlist_handle, NULL, 0, 0, width, height, SWP_NOMOVE|SWP_NOZORDER);
            header->set_window_size();
        }
        static LRESULT view_window_proc(HWND hwnd, UINT message,    
                                        WPARAM wparam, LPARAM lparam) {
            viewlist_control * This = (viewlist_control *)GetWindowLongPtr(hwnd, GWL_USERDATA);
            switch ( message ) {
                case WM_PAINT:
                {
                    PAINTSTRUCT paint_structure;   
                    RECT client_rect;   
                    HDC paint_device_context, paint_dc;   
                    HBITMAP bitmap;   
  
                    paint_device_context = BeginPaint(hwnd, &paint_structure);   
                    paint_dc = CreateCompatibleDC(paint_device_context);   
                    GetClientRect(hwnd, &client_rect);   
                    int window_width = client_rect.right - client_rect.left;  
                    int window_height = client_rect.bottom - client_rect.top;  
                    bitmap = CreateBitmap(window_width, window_height, 1, 32, NULL);  
                    HGDIOBJ old_bitmap = SelectObject(paint_dc, bitmap);  
  
                    // Fill the client aread with the user selected face colour  
                    HBRUSH light_brush = CreateSolidBrush(RGB(255, 252, 223));  
                    FillRect(paint_dc, &paint_structure.rcPaint, light_brush);
                    DeleteObject(light_brush);

                    // Get the width of the first column
                    HDITEM item;
                    item.mask = HDI_WIDTH;
                    SendMessage(This->header->get_handle(), HDM_GETITEM, 0, (LPARAM)&item);

                    SetBkColor(paint_dc, RGB(255, 252, 223));
                    SetTextColor(paint_dc, RGB(0, 0, 0));
                    int ix;
                    int visible_items = window_height/20;
                    SCROLLINFO scroll_info;
                    scroll_info.cbSize = sizeof(SCROLLINFO);
                    scroll_info.fMask = SIF_POS | SIF_PAGE | SIF_RANGE;
                    GetScrollInfo(This->viewlist_handle, SB_VERT, &scroll_info);
                    int start = scroll_info.nPos;
                    int end = start + visible_items;
                    if ( end > This->item_count ) end = This->item_count;

                    for ( ix = start; ix < end; ix++ ) {
                        RECT rcItem = { 5, ((ix-start)+1)*20, item.cxy-1, ((ix-start)+2)*20 };
                        int length = 0;
                        wchar_t * s = This->item_strings[ix];
                        while ( *s++ != 0x09 ) length++;
                        DrawText(paint_dc, This->item_strings[ix], 
                                 length, &rcItem, 
                                 DT_SINGLELINE | DT_LEFT);
                        rcItem.left = item.cxy+7;
                        rcItem.right = window_width;
                        DrawText(paint_dc, s, 
                                 wcslen(s), &rcItem, 
                                 DT_SINGLELINE | DT_LEFT);
                    }
                    
                    MoveToEx(paint_dc, item.cxy-1, 0, NULL);
                    LineTo(paint_dc, item.cxy-1, window_height);

                    BitBlt(paint_device_context, 0, 0,    
                           client_rect.right-client_rect.left,   
                           client_rect.bottom-client_rect.top,   
                           paint_dc, 0, 0, SRCCOPY);   
                    SelectObject(paint_dc, old_bitmap);   
                    DeleteObject(bitmap);   
                    DeleteDC(paint_dc);   
                    EndPaint(hwnd, &paint_structure);   
                    return 0;
                }
                case WM_NOTIFY:
                {
                    NMHEADER * header_item = (NMHEADER *)lparam;
                    if ( header_item->hdr.code == HDN_ITEMCHANGED ) {
                        if ( header_item->iItem != 0 ) return 0;
                        if ( (header_item->pitem->mask&HDI_WIDTH) ) {
                            RECT client_rect;
                            GetClientRect(This->viewlist_handle, &client_rect);
                            int width = client_rect.right-client_rect.left;
                            HDITEM item;
                            item.mask = HDI_WIDTH;
                            item.cxy = width - header_item->pitem->cxy;
                            SendMessage(This->header->get_handle(), HDM_SETITEM, 1, (LPARAM)&item);
                            InvalidateRect(This->viewlist_handle, NULL, TRUE);
                        }
                    }
                    if ( header_item->hdr.code == HDN_BEGINTRACK ) {
                        if ( header_item->iItem != 0 ) return 1;
                    }
                    return 0;
                }
                case WM_ERASEBKGND:   
                {   
                    return TRUE;   
                }
                case WM_VSCROLL:
                {
                    SCROLLINFO scroll_info;
                    scroll_info.cbSize = sizeof(SCROLLINFO);
                    scroll_info.fMask = SIF_POS | SIF_PAGE | SIF_RANGE;
                    GetScrollInfo(This->viewlist_handle, SB_VERT, &scroll_info);
                    switch ( LOWORD(wparam) ) {
                        case SB_LINEDOWN:
                            if ( scroll_info.nPos != scroll_info.nMax ) scroll_info.nPos++;
                            break;
                        case SB_LINEUP:
                            if ( scroll_info.nPos != 0 ) scroll_info.nPos--;
                            break;
                        case SB_PAGEDOWN:
                            scroll_info.nPos += scroll_info.nPage;
                            if ( scroll_info.nPos > scroll_info.nMax ) {
                                scroll_info.nPos = scroll_info.nMax - scroll_info.nPage;
                            }
                            if ( scroll_info.nPos < 0 ) scroll_info.nPos = 0;
                            break;
                        case SB_PAGEUP:
                            scroll_info.nPos -= scroll_info.nPage;
                            if ( scroll_info.nPos < 0 ) scroll_info.nPos = 0;
                            break;
                        case SB_THUMBPOSITION:
                        case SB_THUMBTRACK:
                            scroll_info.nPos = HIWORD(wparam);
                            break;
                    }
                    SetScrollInfo(This->viewlist_handle, SB_VERT, &scroll_info, TRUE);
                    InvalidateRect(This->viewlist_handle, NULL, TRUE);
                    return 0;
                }
            }
            return DefWindowProc(hwnd, message, wparam, lparam);
        }

        void add_item(wchar_t * string) {
            if ( (++item_count) % 10 == 0 ) {
                if ( item_count == 0 ) {
                    item_strings = new wchar_t *[10];
                }
                else {
                    wchar_t ** temp = new wchar_t *[item_count+10];
                    memcpy(temp, item_strings, sizeof(wchar_t *)*item_count);
                    delete [] item_strings;
                    item_strings = temp;
                }
            }
            item_strings[item_count] = string;
            RECT client_rect;
            GetClientRect(viewlist_handle, &client_rect);
            
            SCROLLINFO scroll_info;
            scroll_info.cbSize = sizeof(SCROLLINFO);
            scroll_info.fMask = SIF_POS | SIF_PAGE | SIF_RANGE;
            scroll_info.nPos = 0;
            scroll_info.nMin = 0;
            scroll_info.nMax = item_count-1;
            scroll_info.nPage = (client_rect.bottom-client_rect.top)/20;
            SetScrollInfo(viewlist_handle, SB_VERT, &scroll_info, TRUE);
            InvalidateRect(viewlist_handle, NULL, TRUE);
        }
};

class frame_window {
    private:
        LPWSTR window_class_name;  
        HINSTANCE instance_handle;  
        HCURSOR cursor_arrow;  
        HWND window_handle;
        HWND header_handle;
        RECT client_rectangle;
        viewlist_control * listbox;
    public:
        frame_window(LPWSTR window_class_identity) : window_class_name(window_class_identity) {         
            int screen_width = GetSystemMetrics(SM_CXFULLSCREEN);  
            int screen_height = GetSystemMetrics(SM_CYFULLSCREEN);  
            instance_handle = GetModuleHandle(NULL);  
               
            WNDCLASS window_class = { CS_OWNDC, main_window_proc, 0, 0,    
                                      instance_handle, NULL,    
                                      NULL, NULL, NULL,    
                                      window_class_name };   
            
            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
            // Create a standard frame window   
            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
            
            RegisterClass(&window_class);   
            window_handle = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,    
                                           window_class_name,    
                                           L"Header Control Example",   
                                           WS_OVERLAPPEDWINDOW | 
                                           WS_CLIPCHILDREN | WS_CLIPSIBLINGS,   
                                           (screen_width-900)/2, (screen_height-700)/2, 
                                           900, 700, 
                                           NULL, NULL, instance_handle, NULL);
            SetWindowLongPtr(window_handle, GWL_USERDATA, (LONG)this);  
            GetClientRect(window_handle, &client_rectangle);
            int width = client_rectangle.right - client_rectangle.left;
            int height = client_rectangle.bottom - client_rectangle.top;
            listbox = new viewlist_control(instance_handle, window_handle, 
                                           20, 20, width-40, height-40);
            SetCursor(LoadCursor(NULL, IDC_ARROW)); 
            ShowWindow(window_handle, SW_SHOW);   
            UpdateWindow(window_handle); 
        }  
        ~frame_window() {  
            UnregisterClass(window_class_name, instance_handle);   
        }  
        
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
        // Windows message processing function   
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
        static LRESULT WINAPI main_window_proc(HWND window_handle, UINT message,    
                                               WPARAM wparam, LPARAM lparam) {  
            frame_window *This = (frame_window *)GetWindowLongPtr(window_handle, GWL_USERDATA);  
            switch ( message ) {  
                case WM_PAINT:   
                {   
                    PAINTSTRUCT paint_structure;   
                    RECT client_rect;   
                    HDC paint_device_context, paint_dc;   
                    HBITMAP bitmap;   
  
                    paint_device_context = BeginPaint(window_handle, &paint_structure);   
                    paint_dc = CreateCompatibleDC(paint_device_context);   
                    GetClientRect(window_handle, &client_rect);   
                    int window_width = client_rect.right - client_rect.left;  
                    int window_height = client_rect.bottom - client_rect.top;  
                    bitmap = CreateBitmap(window_width, window_height, 1, 32, NULL);  
                    HGDIOBJ old_bitmap = SelectObject(paint_dc, bitmap);  
  
                    // Fill the client aread with the user selected face colour  
                    HBRUSH light_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));  
                    FillRect(paint_dc, &paint_structure.rcPaint, light_brush);  
                    DeleteObject(light_brush);
                    BitBlt(paint_device_context, 0, 0,    
                           client_rect.right-client_rect.left,   
                           client_rect.bottom-client_rect.top,   
                           paint_dc, 0, 0, SRCCOPY);   
                    SelectObject(paint_dc, old_bitmap);   
                    DeleteObject(bitmap);   
                    DeleteDC(paint_dc);   
                    EndPaint(window_handle, &paint_structure);   
                    return 0;   
                }   
                case WM_ERASEBKGND:   
                {   
                    return TRUE;   
                }
                case WM_SIZE:   
                {
                    This->listbox->set_window_size(LOWORD(lparam)-40, 
                                                   HIWORD(lparam)-40);
                    InvalidateRect(window_handle, NULL, TRUE);   
                    return 0;   
                }
                case WM_COMMAND:
                {
                    return 0;
                }
                case WM_CLOSE:   
                {   
                    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    // The user wants to close the window   
                    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
           
                    PostQuitMessage(0);   
                    return 0;   
                }   
            }   
            return DefWindowProc(window_handle, message, wparam, lparam);   
        }
          
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
        // Windows message loop   
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        void run() {  
            MSG window_message;   
            while ( GetMessage(&window_message, NULL, 0, 0) ) {   
                TranslateMessage(&window_message);   
                DispatchMessage(&window_message);   
            }   
        } 

        void add_item(wchar_t * string) {
            listbox->add_item(string);
        }
};  
   
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
// Windows main entry point   
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
   
int WINAPI wWinMain(HINSTANCE instance_handle, HINSTANCE, LPWSTR, INT) {  
    frame_window main_window(L"my base window");
    main_window.add_item(L"mark.bottomley\tExpert");
    main_window.add_item(L"megamu\tExpert");
    main_window.add_item(L"Bench\tExpert");
    main_window.add_item(L"Cerolobo\tExpert");
    main_window.add_item(L"CyanBlue\tExpert");
    main_window.add_item(L"DilutedImage\tExpert");
    main_window.add_item(L"g00se\tExpert");
    main_window.add_item(L"gregoryH\tExpert");
    main_window.add_item(L"ajwsurfer\tMentor");
    main_window.add_item(L"baavgai\tMentor");
    main_window.add_item(L"CTphpnwb\tMentor");
    main_window.add_item(L"Dogstopper\tMentor");
    main_window.add_item(L"eclipsed4utoo\tMentor");
    main_window.add_item(L"Gloin\tMentor");
    main_window.add_item(L"gregwhitworth\tExpert");
    main_window.add_item(L"GWatt\tExpert");
    main_window.add_item(L"KevinADC\tExpert");
    main_window.add_item(L"mostyfriedman\tExpert");
    main_window.add_item(L"n8wxs\tExpert");
    main_window.add_item(L"perfectly.insane\tExpert");
    main_window.add_item(L"letthecolorsrumble\tExpert");
    main_window.add_item(L"lockdown\tExpert");
    main_window.add_item(L"Martyn.Rae\tMentor");
    main_window.add_item(L"Martyr2\tMentor");
    main_window.add_item(L"pbl\tMentor");
    main_window.add_item(L"PennyBoki\tMentor");
    main_window.add_item(L"Programmist\tMentor");
    main_window.add_item(L"macosxnerd101\tExpert");
    main_window.add_item(L"mocker\tExpert");
    main_window.add_item(L"MorphiusFaydal\tExpert");
    main_window.add_item(L"thava\tExpert");
    main_window.add_item(L"Ancient Dragon\tExpert");
    main_window.add_item(L"EdwinNameless\tExpert");
    main_window.add_item(L"erik.price\tExpert");
    main_window.add_item(L"wildgoose\tExpert");
    main_window.add_item(L"FlashM\tExpert");
    main_window.add_item(L"Fuzzyness\tExpert");
    main_window.add_item(L"Arbitrator\tExpert");
    main_window.add_item(L"malkiri\tExpert");
    main_window.add_item(L"red01\tExpert");
    main_window.add_item(L"MentalFloss\tExpert");
    main_window.add_item(L"japanir\tExpert");
    main_window.add_item(L"joeyadms\tExpert");
    main_window.add_item(L"mikeblas\tExpert");
    main_window.add_item(L"reyco1\tExpert");
    main_window.add_item(L"RodgerB\tExpert");
    main_window.add_item(L"runtime error\tExpert");
    main_window.add_item(L"ScottAdams\tExpert");
    main_window.add_item(L"ShaneK\tExpert");
    main_window.add_item(L"SwiftStriker00\tExpert");
    main_window.add_item(L"horace\tExpert");
    main_window.add_item(L"janotte\tExpert");
    main_window.add_item(L"akozlik\tExpert");
    main_window.add_item(L"Voodoo Doll\tExpert");
    main_window.add_item(L"WolfCoder\tExpert");
    main_window.run();  
    return 0;   
}



Is This A Good Question/Topic? 1
  • +

Replies To: Microsoft : Working With The Header Control

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Posted 07 April 2010 - 10:50 AM

Thanks for this, it's always difficult to find solid examples of the more obscure controls of the Windows API. Great job :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1