1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//创建内部工作窗口, 创建失败 ret == NULL, 否则是有效的窗口句柄
//asz_name 窗口类名称 WndProc 窗口过程 asz_wnd_name 窗口名称
//APP关闭时, 需要调用 DestroyWindow() 关闭窗口
inline HWND TfxWorkWindow(const char* asz_name,
                          WNDPROC  WndProc, const char* asz_wnd_name = NULL );    
 
//创建内部工作窗口, 创建失败 ret == NULL, 否则是有效的窗口句柄
//asz_name 窗口类名称 WndProc 窗口过程 asz_wnd_name 窗口名称
//APP关闭时, 需要调用 DestroyWindow() 关闭窗口
HWND TfxWorkWindow(const char* asz_name,
                   WNDPROC  WndProc, const char* asz_wnd_name)
{
    HWND        hWnd=NULL;
    WNDCLASSEX  wcex={0};
 
    //获得当前应用程序的句柄
    HINSTANCE   hInstance = GetModuleHandle(NULL);
    if ( hInstance == NULL ) return NULL;
 
    wcex.cbSize = sizeof(WNDCLASSEX);
 
    //设置回调函数
    wcex.lpfnWndProc    = (WNDPROC)WndProc;
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszClassName  = asz_name;
 
    WNDCLASS wndclass={0};
    if ( GetClassInfo(hInstance, asz_name, &wndclass) == NULL )
        if ( RegisterClassEx(&wcex) == NULL ) return (NULL);
 
    if (  ( asz_wnd_name == NULL ) || (  strcmp(asz_wnd_name, "" ) == 0 ) )
        hWnd = CreateWindow(asz_name, "", WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    else
        hWnd = CreateWindow(asz_name, asz_wnd_name, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
 
    return hWnd;
}