#include "stdAfx.h"
#include "MyTree.h"
#pragma comment(lib,"comctl32.lib")
HINSTANCE hInst;
LPCTSTR szWindowClass=_T("POWER_WND"); //窗口类名
LPCTSTR szTitle=_T("树形控件"); //标题名 在标题栏上显示
HWND hMainWnd; //主窗口句柄
HWND hWndTree;
RECT WndRect; //窗口矩形
RECT rcClient;
HTREEITEM hNode[50];
int fScreenX;
int fScreenY;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void TVImageLoad(HWND hwndTV);
ATOM MyRegisterClass()
{
WNDCLASSEX wcex;
wcex.cbSize =sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW ;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = LoadIcon(hInst, (LPCTSTR)IDI_TREE);
wcex.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wcex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);//(HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(hInst, (LPCTSTR)IDI_ICON1);
return RegisterClassEx(&wcex);
}
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
hInst=hInstance;
// MyRegisterClass();
if (!MyRegisterClass ())
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
NULL, MB_ICONERROR) ;
return 0 ;
}
fScreenX=GetSystemMetrics(SM_CXSCREEN);
fScreenY=GetSystemMetrics(SM_CYSCREEN);
SetRect(&WndRect,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
if(!(hMainWnd=CreateWindow(szWindowClass, szTitle, WS_POPUP,0,0,WndRect.right,WndRect.bottom, NULL, NULL, hInst, NULL)))
return FALSE;
/*
if(!InitRegister())
{
DestroyWindow(hMainWnd);
return 0;
}
if(!InitDate() || !InitUI() )
{
DestroyWindow(hMainWnd);
return 0;
}
*/
InitCommonControls();
ShowWindow(hMainWnd, SW_SHOWMAXIMIZED);
UpdateWindow(hMainWnd);
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CLIENT);
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
int i=0;
switch(message)
{
case WM_CREATE:
{
hWndTree = CreateWindow(TEXT("SysTreeView32"),
TEXT("Simple"),
WS_CHILD | WS_VISIBLE | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS
//,rcClient.left,rcClient.top,170,rcClient.bottom-rcClient.top, hWnd, NULL, hInst, 0);
,10,10,1000,1000,hWnd,NULL,hInst,0);
TVImageLoad(hWndTree);
//Root...
TVINSERTSTRUCT tvInst;
tvInst.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvInst.item.iImage = 0;
tvInst.item.iSelectedImage = 2;
tvInst.hInsertAfter = TVI_LAST;
tvInst.hParent = NULL;
for(i=0;i<10;i++)
{
tvInst.item.pszText = TEXT("房间");
hNode[i]= (HTREEITEM)SendMessage(hWndTree, TVM_INSERTITEM, 0, (LPARAM)&tvInst);
// game = game->pnext;
}
tvInst.item.pszText = TEXT("正在下载房间列表");
tvInst.item.iImage = 0;
tvInst.item.iSelectedImage = 2;
tvInst.hParent = hNode[1];
hNode[3] = (HTREEITEM)SendMessage(hWndTree, TVM_INSERTITEM, 0, (LPARAM)&tvInst);
}
return 0;
case WM_SIZE:
hdc = BeginPaint(hWnd,&ps);
GetClientRect(hWnd,&rect);
EndPaint(hWnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}
void TVImageLoad(HWND hwndTV)
{
HIMAGELIST himl; // handle to image list
HICON hIcon;
if ((himl = ImageList_Create(16, 16,
FALSE, 3, 0)) == NULL)
return ;
hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_FATHER));
int g_nOpen = ImageList_AddIcon(himl, hIcon);
DeleteObject(hIcon);
hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_CHILD));
int g_nClosed = ImageList_AddIcon(himl, hIcon);
DeleteObject(hIcon);
hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_TREE));
int g_nDocument = ImageList_AddIcon(himl, hIcon);
DeleteObject(hIcon);
if (ImageList_GetImageCount(himl) < 3)
return ;
TreeView_SetImageList(hwndTV, himl, TVSIL_NORMAL);
}