Changeset 95a42df in pugl


Ignore:
Timestamp:
11/11/15 12:41:12 (22 months ago)
Author:
David Robillard <d@…>
Branches:
master
Children:
db28e6c
Parents:
b10540d
Message:

Add API to set window class name

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pugl/pugl.h

    r6abce49 r95a42df  
    154154 
    155155/** 
     156   Set the window class name before creating a window. 
     157*/ 
     158PUGL_API void 
     159puglInitWindowClass(PuglView* view, const char* name); 
     160 
     161/** 
    156162   Set the parent window before creating a window (for embedding). 
    157163*/ 
  • pugl/pugl_internal.h

    r6b4a5a1 r95a42df  
    4848    PuglInternals* impl; 
    4949 
     50    char*            windowClass; 
    5051    PuglNativeWindow parent; 
    5152    PuglContextType  ctx_type; 
     
    115116    view->max_aspect_x = max_x; 
    116117    view->max_aspect_y = max_y; 
     118} 
     119 
     120void 
     121puglInitWindowClass(PuglView* view, const char* name) 
     122{ 
     123    free(view->windowClass); 
     124    view->windowClass = strdup(name); 
    117125} 
    118126 
  • pugl/pugl_win.cpp

    r1175563 r95a42df  
    113113puglCreateWindow(PuglView* view, const char* title) 
    114114{ 
     115    static const TCHAR* DEFAULT_CLASSNAME = "Pugl"; 
     116 
    115117    PuglInternals* impl = view->impl; 
    116118 
     
    119121    } 
    120122 
    121     // FIXME: This is nasty, and pugl should not have static anything. 
    122     // Should class be a parameter?  Does this make sense on other platforms? 
    123     static int wc_count = 0; 
    124     char classNameBuf[256]; 
    125     _snprintf(classNameBuf, sizeof(classNameBuf), "x%d%s", wc_count++, title); 
    126     classNameBuf[sizeof(classNameBuf) - 1] = '\0'; 
    127  
    128     impl->wc.style         = CS_OWNDC; 
    129     impl->wc.lpfnWndProc   = wndProc; 
    130     impl->wc.cbClsExtra    = 0; 
    131     impl->wc.cbWndExtra    = 0; 
    132     impl->wc.hInstance     = 0; 
    133     impl->wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION); 
    134     impl->wc.hCursor       = LoadCursor(NULL, IDC_ARROW); 
    135     impl->wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); 
    136     impl->wc.lpszMenuName  = NULL; 
    137     impl->wc.lpszClassName = strdup(classNameBuf); 
    138  
    139     if (!RegisterClass(&impl->wc)) { 
     123    WNDCLASSEX wc; 
     124    memset(&wc, 0, sizeof(wc)); 
     125    wc.cbSize        = sizeof(wc); 
     126    wc.style         = CS_OWNDC; 
     127    wc.lpfnWndProc   = wndProc; 
     128    wc.hInstance     = GetModuleHandle(NULL); 
     129    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION); // TODO: user-specified icon 
     130    wc.hCursor       = LoadCursor(NULL, IDC_ARROW); 
     131    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); 
     132    wc.lpszClassName = view->windowClass ? view->windowClass : DEFAULT_CLASSNAME; 
     133    if (!RegisterClassEx(&wc)) { 
    140134        free((void*)impl->wc.lpszClassName); 
    141135        free(impl); 
     
    162156    impl->hwnd = CreateWindowEx( 
    163157        WS_EX_TOPMOST, 
    164         classNameBuf, title, 
     158        wc.lpszClassName, title, 
    165159        (view->parent ? WS_CHILD : winFlags), 
    166160        CW_USEDEFAULT, CW_USEDEFAULT, wr.right-wr.left, wr.bottom-wr.top, 
  • pugl_test.c

    rb10540d r95a42df  
    174174 
    175175    PuglView* view = puglInit(NULL, NULL); 
     176    puglInitWindowClass(view, "PuglTest"); 
    176177    puglInitWindowSize(view, 512, 512); 
    177178    puglInitWindowMinSize(view, 256, 256); 
Note: See TracChangeset for help on using the changeset viewer.