Code:
#define _WIN32_IE 0x0500
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"
HWND hMainWindow = NULL; // main window
//tabs
HWND hTabCntrl = NULL; // our tab control
HWND hTabGenerals = NULL; // view window for tab1
HWND hTabCastles = NULL; // view window for tab2
HWND hTabDivisions = NULL; // view window for tab3
HWND hTabKingdoms = NULL; // view window for tab4
HWND hTabMisc = NULL; // view window for tab5
HINSTANCE hThisInst = NULL;
const char g_szClassName[] = "myWindowClass";
void InitComCtls (void);
void CreateTabControl (void);
void CreateStaticViewTab1 (void);
void CreateStaticViewTab2 (void);
LRESULT CALLBACK WndProc (HWND hMainWindow, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK WndProc(HWND hMainWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_LBUTTONDOWN:
{
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
MessageBox(hMainWindow, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
}
break;
case WM_CLOSE:
DestroyWindow(hMainWindow);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hMainWindow, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hMainWindow;
MSG Msg;
hThisInst = hInstance;
InitComCtls();
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
wc.lpszClassName = g_szClassName;
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hMainWindow = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Dragon Force Edit 2.0",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
1024,
768,
NULL,
NULL,
hInstance,
NULL);
if(hMainWindow == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
CreateTabControl();
ShowWindow(hMainWindow, nCmdShow);
UpdateWindow(hMainWindow);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
void InitComCtls(void)
{
INITCOMMONCONTROLSEX icce;
icce.dwSize = sizeof(INITCOMMONCONTROLSEX);
icce.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icce);
return;
}
void CreateTabControl(void)
{
/* create tab control */
hTabCntrl = CreateWindowEx(
0, // extended style
WC_TABCONTROL, // tab control constant
"", // text/caption
WS_CHILD | WS_VISIBLE, // is a child control, and visible
5, // X position - device units from left
5, // Y position - device units from top
800, // Width - in device units
600, // Height - in device units
hMainWindow, // parent window
NULL, // no menu
hThisInst, // instance
NULL // no extra junk
);
if (hTabCntrl == NULL)
{
// tab creation failed -
// are the correct #defines in your header?
// have you included the common control library?
MessageBox(NULL, "Tab creation failed", "Tab Creation", MB_OK | MB_ICONERROR);
return;
}
/* start adding items to our tab control */
/*
.... etc.
*/