void Game_Genie_Window_CreateChildWindows(HWND hWnd)
{
	// Description labels.
	HWND lblInfoTitle, lblInfo;
	
	// Strings
	const char* strInfoTitle = "Information about Game Genie / Patch codes";
	const char* strInfo =
			"Both Game Genie codes and Patch codes are supported.\n"
			"Check the box next to the code to activate it.\n"
			"Syntax for Game Genie codes: XXXX-YYYY\n"
			"Syntax for Patch codes: AAAAAA-DDDD (address-data)";
	
	// Info Title
	lblInfoTitle = CreateWindow(WC_STATIC, strInfoTitle,
				    WS_CHILD | WS_VISIBLE | SS_LEFT,
				    8, 8, 256, 16, hWnd, NULL, ghInstance, NULL);
	SetWindowFont(lblInfoTitle, fntTitle, TRUE);
	
	// Info
	lblInfo = CreateWindow(WC_STATIC, strInfo,
			       WS_CHILD | WS_VISIBLE | SS_LEFT,
			       8, 24, wndWidth-16, 68, hWnd, NULL, ghInstance, NULL);
	SetWindowFont(lblInfo, fntMain, TRUE);
	
	// Code and Name boxes, plus "Add Code" button.
	HWND lblCode, btnAddCode;
	HWND lblName;
	
	// Code label
	lblCode = CreateWindow(WC_STATIC, "Code",
			       WS_CHILD | WS_VISIBLE | SS_LEFT,
			       8, 24+68+8, 32, 16, hWnd, NULL, ghInstance, NULL);
	SetWindowFont(lblCode, fntMain, TRUE);
	
	// Code entry
	gg_txtCode = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, NULL,
				    WS_CHILD | WS_VISIBLE | WS_TABSTOP | SS_LEFT | ES_AUTOHSCROLL,
				    8+32+8, 24+68+8, wndWidth - (8+32+8+64+8+8+16), 20,
				    hWnd, NULL, ghInstance, NULL);
	SetWindowFont(gg_txtCode, fntMain, TRUE);
	gg_txtCode_oldProc = (WNDPROC)SetWindowLongPtr(gg_txtCode, GWL_WNDPROC, (LONG_PTR)Game_Genie_TextBox_WndProc);
	
	// Name label
	lblName = CreateWindow(WC_STATIC, "Name",
			       WS_CHILD | WS_VISIBLE | SS_LEFT,
			       8, 24+68+8+24, 32, 16,
			       hWnd, NULL, ghInstance, NULL);
	SetWindowFont(lblName, fntMain, TRUE);
	
	// Name entry
	gg_txtName = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, NULL,
				    WS_CHILD | WS_VISIBLE | WS_TABSTOP | SS_LEFT | ES_AUTOHSCROLL,
				    8+32+8, 24+68+8+24, wndWidth - (8+32+8+64+8+8+16), 20,
				    hWnd, NULL, ghInstance, NULL);
	SetWindowFont(gg_txtName, fntMain, TRUE);
	gg_txtName_oldProc = (WNDPROC)SetWindowLongPtr(gg_txtName, GWL_WNDPROC, (LONG_PTR)Game_Genie_TextBox_WndProc);
	
	// Add Code
	btnAddCode = CreateWindow(WC_BUTTON, "&Add Code",
				  WS_CHILD | WS_VISIBLE | WS_TABSTOP,
				  wndWidth - (64+8+16), 24+68+8, 63+16, 20,
				  hWnd, IDC_BTN_ADD, ghInstance, NULL);
	SetWindowFont(btnAddCode, fntMain, TRUE);
	
	// ListView
	gg_lstvCodes = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, "",
				      WS_CHILD | WS_VISIBLE | WS_TABSTOP | LVS_REPORT,
				      8, 24+68+8+24+24, wndWidth - (8+8), 128,
				      hWnd, NULL, ghInstance, NULL);
	SetWindowFont(gg_lstvCodes, fntMain, TRUE);
	SendMessage(gg_lstvCodes, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
	
	// Create the ListView columns.
	LV_COLUMN lvCol;
	memset(&lvCol, 0, sizeof(lvCol));
	lvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
	
	// Code
	lvCol.pszText = "Code";
	lvCol.cx = 128;
	SendMessage(gg_lstvCodes, LVM_INSERTCOLUMN, 0, (LPARAM)&lvCol);
	
	// Name
	lvCol.pszText = "Name";
	lvCol.cx = 256;
	SendMessage(gg_lstvCodes, LVM_INSERTCOLUMN, 1, (LPARAM)&lvCol);
	
	// Buttons
	const int btnTop = 24+68+8+24+24+128+8;
	HWND btnOK, btnApply, btnCancel, btnDeactivateAll, btnDelete;
	
	btnOK = CreateWindow(WC_BUTTON, "&OK", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON,
			     8, btnTop, 75, 23,
			     hWnd, (HMENU)IDC_BTN_OK, ghInstance, NULL);
	SetWindowFont(btnOK, fntMain, TRUE);
	
	btnApply = CreateWindow(WC_BUTTON, "&Apply", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
				8+75+8, btnTop, 75, 23,
				hWnd, (HMENU)IDC_BTN_APPLY, ghInstance, NULL);
	SetWindowFont(btnApply, fntMain, TRUE);
	
	btnCancel = CreateWindow(WC_BUTTON, "&Cancel", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
				 8+75+8+75+8, btnTop, 75, 23,
				 hWnd, (HMENU)IDC_BTN_CANCEL, ghInstance, NULL);
	SetWindowFont(btnCancel, fntMain, TRUE);
	
	btnDelete = CreateWindow(WC_BUTTON, "&Delete", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
				 8+75+8+75+8+75+8, btnTop, 75, 23,
				 hWnd, (HMENU)IDC_BTN_DELETE, ghInstance, NULL);
	SetWindowFont(btnDelete, fntMain, TRUE);
	
	btnDeactivateAll = CreateWindow(WC_BUTTON, "Deac&tivate All", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
					8+75+8+75+8+75+8+75+8, btnTop, 75+16, 23,
					hWnd, (HMENU)IDC_BTN_DEACTIVATEALL, ghInstance, NULL);
	SetWindowFont(btnDeactivateAll, fntMain, TRUE);
	
	// Set focus to the Code textbox.
	SetFocus(gg_txtCode);
}
Пример #2
1
Файл: win.cpp Проект: roybai/poe
DWORD WINAPI _WinMain(LPVOID lpParam) 
{ 
    HWND hwnd; 
    MSG messages; 
    WNDCLASSEX wincl; 
/*
    wincl.hInstance = hInstance; 
    wincl.lpszClassName = szClassName; 
    wincl.lpfnWndProc = WindowProcedure; 
    wincl.style = CS_DBLCLKS; 
    wincl.cbSize = sizeof (WNDCLASSEX); 
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; 
	MessageBox(NULL,"AA","AA",MB_OK); 
*/
		wincl.cbSize = sizeof(wincl);          // size of structure 
    wincl.style = CS_HREDRAW | 
        CS_VREDRAW;                    // redraw if size changes 
    wincl.lpfnWndProc = WndProc;     // points to window procedure 
    wincl.cbClsExtra = 0;                // no extra class memory 
    wincl.cbWndExtra = 0;                // no extra window memory 
    wincl.hInstance = _hinst;         // handle to instance 
    wincl.hIcon = LoadIcon(NULL, 
        IDI_APPLICATION);              // predefined app. icon 
    wincl.hCursor = LoadCursor(NULL, 
        IDC_ARROW);                    // predefined arrow 
    wincl.hbrBackground     = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  //  wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;             // white background brush 
    wincl.lpszMenuName =  "MainMenu";    // name of menu resource 
    wincl.lpszClassName = "MainWClass";  // name of window class 
	wincl.hIconSm = NULL; 

char	buf[100];

//sprintf(buf,"%d",_hinst);
//	MessageBox(NULL,buf,"11",MB_OK); 
    if (!RegisterClassEx (&wincl)) 
        return 0; 

    hwnd = CreateWindowEx ( 
          0, 
          szClassName,        /* Classname */ 
          "MainWClass",      /* Title Text */ 
          WS_OVERLAPPEDWINDOW, /* default window */ 
//          CW_USEDEFAULT,      /* Windows decides the position */ 
 //         CW_USEDEFAULT,      /* where the window ends up on the screen */ 
 0,
 0,
          640,                /* The programs width */ 
          400,                /* and height in pixels */ 
          HWND_DESKTOP,        /* The window is a child-window to desktop */ 
          NULL,                /* No menu */ 
          _hinst,      /* Program Instance handler */ 
          NULL                /* No Window Creation data */ 
          ); 
	if(!hwnd)
	{
			long lError;
		   lError   =   ::GetLastError(); 
			sprintf(buf,"%d, %d",hwnd,lError);
			MessageBox(NULL,buf,"22",MB_OK); 
			return 0;
	}

	_hwnd=hwnd;
    /* Make the window visible on the screen */ 
    ShowWindow (hwnd, SW_SHOWNORMAL); 
    UpdateWindow(hwnd); 

    /* Run the message loop. It will run until GetMessage() returns 0 */ 
    while (GetMessage (&messages, NULL, 0, 0)) 
    { 
        /* Translate virtual-key messages into character messages */ 
        TranslateMessage(&messages); 
        /* Send message to WindowProcedure */ 
        DispatchMessage(&messages); 
    } 

    /* The program return-value is 0 - The value that PostQuitMessage() gave */ 
    return messages.wParam; 
} 
Пример #3
0
boolean wf_post_connect(freerdp* instance)
{
	rdpGdi* gdi;
	wfInfo* wfi;
	rdpCache* cache;
	wfContext* context;
	int width, height;
	wchar_t win_title[64];
	rdpSettings* settings;

	settings = instance->settings;
	context = (wfContext*) instance->context;
	cache = instance->context->cache;
	wfi = context->wfi;

	wfi->dstBpp = 32;
	width = settings->width;
	height = settings->height;

	if (wfi->sw_gdi)
	{
		gdi_init(instance, CLRCONV_ALPHA | CLRBUF_32BPP, NULL);
		gdi = instance->context->gdi;
		wfi->hdc = gdi->primary->hdc;
		wfi->primary = wf_image_new(wfi, width, height, wfi->dstBpp, gdi->primary_buffer);
	}
	else
	{
		wf_gdi_register_update_callbacks(instance->update);
		wfi->srcBpp = instance->settings->color_depth;
		wfi->primary = wf_image_new(wfi, width, height, wfi->dstBpp, NULL);

		wfi->hdc = gdi_GetDC();
		wfi->hdc->bitsPerPixel = wfi->dstBpp;
		wfi->hdc->bytesPerPixel = wfi->dstBpp / 8;

		wfi->hdc->alpha = wfi->clrconv->alpha;
		wfi->hdc->invert = wfi->clrconv->invert;

		wfi->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND));
		wfi->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0);
		wfi->hdc->hwnd->invalid->null = 1;

		wfi->hdc->hwnd->count = 32;
		wfi->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * wfi->hdc->hwnd->count);
		wfi->hdc->hwnd->ninvalid = 0;
	}

	if (strlen(wfi->window_title) > 0)
		_snwprintf(win_title, sizeof(win_title), L"%S", wfi->window_title);
	else if (settings->port == 3389)
		_snwprintf(win_title, sizeof(win_title) / sizeof(win_title[0]), L"%S - FreeRDP", settings->hostname);
	else
		_snwprintf(win_title, sizeof(win_title) / sizeof(win_title[0]), L"%S:%d - FreeRDP", settings->hostname, settings->port);

	if (wfi->hwnd == 0)
	{
		wfi->hwnd = CreateWindowEx((DWORD) NULL, g_wnd_class_name, win_title,
				0, 0, 0, 0, 0, NULL, NULL, g_hInstance, NULL);

		SetWindowLongPtr(wfi->hwnd, GWLP_USERDATA, (LONG_PTR) wfi);
	}

	if (wfi->fullscreen)
	{
		SetWindowLongPtr(wfi->hwnd, GWL_STYLE, WS_POPUP);
		SetWindowPos(wfi->hwnd, HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
	}
	else
	{
		POINT diff;
		RECT rc_client, rc_wnd;

		SetWindowLongPtr(wfi->hwnd, GWL_STYLE, WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX);
		/* Now resize to get full canvas size and room for caption and borders */
		SetWindowPos(wfi->hwnd, HWND_TOP, 10, 10, width, height, SWP_FRAMECHANGED);
		GetClientRect(wfi->hwnd, &rc_client);
		GetWindowRect(wfi->hwnd, &rc_wnd);
		diff.x = (rc_wnd.right - rc_wnd.left) - rc_client.right;
		diff.y = (rc_wnd.bottom - rc_wnd.top) - rc_client.bottom;
		SetWindowPos(wfi->hwnd, HWND_TOP, -1, -1, width + diff.x, height + diff.y, SWP_NOMOVE | SWP_FRAMECHANGED);
	}

	BitBlt(wfi->primary->hdc, 0, 0, width, height, NULL, 0, 0, BLACKNESS);
	wfi->drawing = wfi->primary;

	ShowWindow(wfi->hwnd, SW_SHOWNORMAL);
	UpdateWindow(wfi->hwnd);

	if (wfi->sw_gdi)
	{
		instance->update->BeginPaint = wf_sw_begin_paint;
		instance->update->EndPaint = wf_sw_end_paint;
	}
	else
	{
		instance->update->BeginPaint = wf_hw_begin_paint;
		instance->update->EndPaint = wf_hw_end_paint;
	}

	pointer_cache_register_callbacks(instance->update);

	if (wfi->sw_gdi != True)
	{
		brush_cache_register_callbacks(instance->update);
		bitmap_cache_register_callbacks(instance->update);
		offscreen_cache_register_callbacks(instance->update);
	}

	wf_register_graphics(instance->context->graphics);

	freerdp_channels_post_connect(instance->context->channels, instance);

	return True;
}
Пример #4
0
/*	This Code Creates Our OpenGL Window.  Parameters Are:
 *	lpszTitle		- Title to Appear at the Top of the Window
 *	hWndParent		- Parent HWND where the screne will be drawn
 *	nZBuffer		- Number of Bits to Use for Z-Buffer (16/32)
 */
bool CGL::Create(char* lpszTitle, HWND hWndParent, int nZBuffer=16) : m_bFullScreen(false)
{
	GLuint		PixelFormat;							// Holds The Results After Searching For A Match
	WNDCLASS	wc;										// Windows Class Structure
	DWORD		dwExStyle;								// Window Extended Style
	DWORD		dwStyle;								// Window Style
	RECT		rectWindow;								// Grabs Rectangle Upper Left / Lower Right Values
	int			nWidth,
				nHeight;

	// Get window size
	GetClientRect(hWndParent, &rectWindow);
	nWidth  = rectWindow.right-rectWindow.left;
	nHeight = rectWindow.bottom-rectWindow.top;

	m_hInstance			= GetModuleHandle(NULL);		// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) WndProc;			// WndProc Handles Messages
	wc.cbClsExtra		= 0;							// No Extra Window Data
	wc.cbWndExtra		= 0;							// No Extra Window Data
	wc.hInstance		= m_hInstance;					// Set The Instance
	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);	// Load The Default Icon
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);	// Load The Arrow Pointer
	wc.hbrBackground	= NULL;							// No Background Required For GL
	wc.lpszMenuName		= NULL;							// We Don't Want A Menu
	wc.lpszClassName	= "OpenGL";						// Set The Class Name

	if (!RegisterClass(&wc))							// Attempt To Register The Window Class
	{
		MessageBox(m_hWnd,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}
	
	dwExStyle = WS_EX_APPWINDOW;						// Window Extended Style
	//dwStyle = WS_OVERLAPPEDWINDOW;					// Windows Style
	dwStyle = WS_DISABLED | WS_VISIBLE | WS_CHILD;		// Windows Style

	AdjustWindowRectEx(&rectWindow, dwStyle, false, dwExStyle);		// Adjust Window To true Requested Size

	// Create The Window
	if (!(m_hWnd=CreateWindowEx(dwExStyle,				// Extended Style For The Window
								"OpenGL",				// Class Name
								lpszTitle,				// Window Title
								dwStyle |				// Defined Window Style
								WS_CLIPSIBLINGS |		// Required Window Style
								WS_CLIPCHILDREN,		// Required Window Style
								0, 0,					// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,					// No Parent Window
								NULL,					// No Menu
								m_hInstance,			// Instance
								NULL)))					// Dont Pass Anything To WM_CREATE
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	static	PIXELFORMATDESCRIPTOR pfd =					// pfd Tells Windows How We Want Things To Be
	{
		sizeof(PIXELFORMATDESCRIPTOR),					// Size Of This Pixel Format Descriptor
		1,												// Version Number
		PFD_DRAW_TO_WINDOW |							// Format Must Support Window
		PFD_SUPPORT_OPENGL |							// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,								// Must Support Double Buffering
		PFD_TYPE_RGBA,									// Request An RGBA Format
		nBits,											// Select Our Color Depth
		0, 0, 0, 0, 0, 0,								// Color Bits Ignored
		0,												// No Alpha Buffer
		0,												// Shift Bit Ignored
		0,												// No Accumulation Buffer
		0, 0, 0, 0,										// Accumulation Bits Ignored
		nZBuffer,										// 16/32Bit Z-Buffer (Depth Buffer)  
		0,												// No Stencil Buffer
		0,												// No Auxiliary Buffer
		PFD_MAIN_PLANE,									// Main Drawing Layer
		0,												// Reserved
		0, 0, 0											// Layer Masks Ignored
	};
	
	if (!(m_hDC=GetDC(m_hWnd)))							// Did We Get A Device Context?
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	if (!(PixelFormat=ChoosePixelFormat(m_hDC,&pfd)))	// Did Windows Find A Matching Pixel Format?
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	if(!SetPixelFormat(m_hDC,PixelFormat,&pfd))			// Are We Able To Set The Pixel Format?
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	if (!(hRC=wglCreateContext(m_hDC)))					// Are We Able To Get A Rendering Context?
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	if(!wglMakeCurrent(m_hDC,hRC))						// Try To Activate The Rendering Context
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	ShowWindow(m_hWnd, SW_SHOW);						// Show The Window
	SetForegroundWindow(m_hWnd);						// Slightly Higher Priority
	SetFocus(m_hWnd);									// Sets Keyboard Focus To The Window
	Resize(nWidth, nHeight);							// Set Up Our Perspective GL Screen

	if (!Init())										// Initialize Our Newly Created GL Window
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	return true;										// Success
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	RECT rect;
	COLORREF colorText = RGB(0, 0, 255); // задаём цвет текста
	
	switch (message)
	{

	case WM_COMMAND:

	case BN_CLICKED:

		if (LOWORD(wParam) == ID_BUTTON1)
		{
			
			GetClientRect(hWnd, &rect);
			edit1 = CreateWindowEx(
				WS_EX_CLIENTEDGE,
				L"edit",
				L"Нажмите правую клавишу мыши",
				WS_CHILD | WS_VISIBLE | EM_FMTLINES,
				rect.right / 4,									/*координаты по X*/
				rect.bottom / 4,								/*координаты по Y*/
				rect.right / 2,									/*Ширина окошка*/
				rect.bottom / 2,
				hWnd,
				(HMENU)ID_EDIT1,
				hinst,
				NULL);
		
		}
		
		break;

	case WM_RBUTTONDOWN:
			
			ShowWindow(edit1, SW_HIDE);
			break;

	case WM_CREATE:

		GetClientRect(hWnd, &rect);
				
		button1 = CreateWindowEx(
			WS_EX_CLIENTEDGE,
			L"button",
			L"Показать",
			WS_CHILD | WS_VISIBLE,
			rect.right / 2 - ARRAYSIZE(L"Показать") * 4 - 10,		/*координаты по X*/
			rect.bottom - 30,						/*координаты по Y*/
			ARRAYSIZE(L"Показать") * 10,						/*Ширина окошка*/
			25,
			hWnd,
			(HMENU)ID_BUTTON1,
			hinst,
			NULL);

		
		break;

	case WM_PAINT:

		hdc = BeginPaint(hWnd, &ps); // инициализируем контекст устройства
		GetClientRect(hWnd, &rect); // получаем ширину и высоту области для рисования
		SetTextColor(hdc, colorText); // устанавливаем цвет контекстного устройства
		
		
				DrawText(hdc, L"В в е д и т е   т е к с т", -1, &rect, DT_SINGLELINE | DT_CENTER); // рисуем текст
			
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;
	}

	return 0;
}
Пример #6
0
INT_PTR SettingsVideo::ProcMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
    HWND hwndTemp;
    switch(message)
    {
        case WM_INITDIALOG:
            {
                LocalizeWindow(hwnd);

                //--------------------------------------------

                HWND hwndToolTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL, WS_POPUP|TTS_NOPREFIX|TTS_ALWAYSTIP,
                    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                    hwnd, NULL, hinstMain, NULL);

                TOOLINFO ti;
                zero(&ti, sizeof(ti));
                ti.cbSize = sizeof(ti);
                ti.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
                ti.hwnd = hwnd;

                SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, 500);
                SendMessage(hwndToolTip, TTM_SETDELAYTIME, TTDT_AUTOPOP, 8000);

                //--------------------------------------------

                hwndTemp = GetDlgItem(hwnd, IDC_MONITOR);

                App->monitors.Clear();
                EnumDisplayMonitors(NULL, NULL, (MONITORENUMPROC)MonitorInfoEnumProc, (LPARAM)&App->monitors);

                for(UINT i=0; i<App->monitors.Num(); i++)
                    SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)IntString(i+1).Array());

                int monitorID = LoadSettingComboInt(hwndTemp, TEXT("Video"), TEXT("Monitor"), 0, App->monitors.Num()-1);
                if(monitorID > (int)App->monitors.Num())
                    monitorID = 0;

                //--------------------------------------------

                SendMessage(GetDlgItem(hwnd, IDC_USECUSTOM), BM_SETCHECK, BST_CHECKED, 0);
                EnableWindow(GetDlgItem(hwnd, IDC_MONITOR), FALSE);

                //--------------------------------------------

                int cx, cy;
                if(!AppConfig->HasKey(TEXT("Video"), TEXT("BaseWidth")) || !AppConfig->HasKey(TEXT("Video"), TEXT("BaseHeight")))
                {
                    cx = App->monitors[monitorID].rect.right  - App->monitors[monitorID].rect.left;
                    cy = App->monitors[monitorID].rect.bottom - App->monitors[monitorID].rect.top;
                    AppConfig->SetInt(TEXT("Video"), TEXT("BaseWidth"),  cx);
                    AppConfig->SetInt(TEXT("Video"), TEXT("BaseHeight"), cy);
                }
                else
                {
                    cx = AppConfig->GetInt(TEXT("Video"), TEXT("BaseWidth"));
                    cy = AppConfig->GetInt(TEXT("Video"), TEXT("BaseHeight"));

                    if(cx < 128)        cx = 128;
                    else if(cx > 4096)  cx = 4096;

                    if(cy < 128)        cy = 128;
                    else if(cy > 4096)  cy = 4096;
                }


                hwndTemp = GetDlgItem(hwnd, IDC_SIZEX);
                editProc = (FARPROC)GetWindowLongPtr(hwndTemp, GWLP_WNDPROC);
                SetWindowLongPtr(hwndTemp, GWLP_WNDPROC, (LONG_PTR)ResolutionEditSubclassProc);
                SetWindowText(hwndTemp, IntString(cx).Array());

                hwndTemp = GetDlgItem(hwnd, IDC_SIZEY);
                SetWindowLongPtr(hwndTemp, GWLP_WNDPROC, (LONG_PTR)ResolutionEditSubclassProc);
                SetWindowText(hwndTemp, IntString(cy).Array());

                //--------------------------------------------

                hwndTemp = GetDlgItem(hwnd, IDC_DISABLEAERO);

                if(OSGetVersion() == 8)
                    EnableWindow(hwndTemp, FALSE);

                BOOL bDisableAero = AppConfig->GetInt(TEXT("Video"), TEXT("DisableAero"), 0);
                SendMessage(hwndTemp, BM_SETCHECK, bDisableAero ? BST_CHECKED : 0, 0);

                ti.lpszText = (LPWSTR)Str("Settings.Video.DisableAeroTooltip");
                ti.uId = (UINT_PTR)hwndTemp;
                SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);

                //--------------------------------------------

                BOOL bUnlockFPS = AppConfig->GetInt(TEXT("Video"), TEXT("UnlockFPS"));
                int topFPS = bUnlockFPS ? 120 : 60;

                hwndTemp = GetDlgItem(hwnd, IDC_FPS);
                SendMessage(hwndTemp, UDM_SETRANGE32, 10, topFPS);

                int fps = AppConfig->GetInt(TEXT("Video"), TEXT("FPS"), 30);
                if(!AppConfig->HasKey(TEXT("Video"), TEXT("FPS")))
                {
                    AppConfig->SetInt(TEXT("Video"), TEXT("FPS"), 30);
                    fps = 30;
                }
                else if(fps < 10)
                {
                    AppConfig->SetInt(TEXT("Video"), TEXT("FPS"), 10);
                    fps = 10;
                }
                else if(fps > topFPS)
                {
                    AppConfig->SetInt(TEXT("Video"), TEXT("FPS"), topFPS);
                    fps = topFPS;
                }

                SendMessage(hwndTemp, UDM_SETPOS32, 0, fps);

                //--------------------------------------------

                hwndTemp = GetDlgItem(hwnd, IDC_DOWNSCALE);
                RefreshDownscales(hwndTemp, cx, cy);

                ti.lpszText = (LPWSTR)Str("Settings.Video.DownscaleTooltip");
                ti.uId = (UINT_PTR)hwndTemp;
                SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);

                //--------------------------------------------

                ShowWindow(GetDlgItem(hwnd, IDC_INFO), SW_HIDE);
                SetChangedSettings(false);

                return TRUE;
            }

        case WM_COMMAND:
            {
                bool bDataChanged = false;

                switch(LOWORD(wParam))
                {
                    case IDC_MONITOR:
                        {
                            if(HIWORD(wParam) != CBN_SELCHANGE)
                                break;

                            int sel = (int)SendMessage(GetDlgItem(hwnd, IDC_MONITOR), CB_GETCURSEL, 0, 0);
                            if(sel != CB_ERR)
                            {
                                if(sel >= (int)App->monitors.Num())
                                    sel = 0;

                                MonitorInfo &monitor = App->monitors[sel];

                                int cx, cy;
                                cx = monitor.rect.right  - monitor.rect.left;
                                cy = monitor.rect.bottom - monitor.rect.top;

                                SetWindowText(GetDlgItem(hwnd, IDC_SIZEX), IntString(cx).Array());
                                SetWindowText(GetDlgItem(hwnd, IDC_SIZEY), IntString(cy).Array());
                            }
                            break;
                        }

                    case IDC_USECUSTOM:
                        SendMessage(GetDlgItem(hwnd, IDC_SIZEX), EM_SETREADONLY, FALSE, 0);
                        SendMessage(GetDlgItem(hwnd, IDC_SIZEY), EM_SETREADONLY, FALSE, 0);
                        EnableWindow(GetDlgItem(hwnd, IDC_MONITOR), FALSE);
                        break;

                    case IDC_USEMONITOR:
                        {
                            SendMessage(GetDlgItem(hwnd, IDC_SIZEX), EM_SETREADONLY, TRUE, 0);
                            SendMessage(GetDlgItem(hwnd, IDC_SIZEY), EM_SETREADONLY, TRUE, 0);
                            EnableWindow(GetDlgItem(hwnd, IDC_MONITOR), TRUE);

                            int sel = (int)SendMessage(GetDlgItem(hwnd, IDC_MONITOR), CB_GETCURSEL, 0, 0);
                            if(sel != CB_ERR)
                            {
                                if(sel >= (int)App->monitors.Num())
                                    sel = 0;

                                MonitorInfo &monitor = App->monitors[sel];

                                int cx, cy;
                                cx = monitor.rect.right  - monitor.rect.left;
                                cy = monitor.rect.bottom - monitor.rect.top;

                                SetWindowText(GetDlgItem(hwnd, IDC_SIZEX), IntString(cx).Array());
                                SetWindowText(GetDlgItem(hwnd, IDC_SIZEY), IntString(cy).Array());
                            }
                            break;
                        }

                    case IDC_SIZEX:
                    case IDC_SIZEY:
                        {
                            if(HIWORD(wParam) != EN_CHANGE)
                                break;

                            String strInt = GetEditText((HWND)lParam);
                            int iVal = strInt.ToInt();

                            int cx = GetEditText(GetDlgItem(hwnd, IDC_SIZEX)).ToInt();
                            int cy = GetEditText(GetDlgItem(hwnd, IDC_SIZEY)).ToInt();

                            if(cx < 128)        cx = 128;
                            else if(cx > 4096)  cx = 4096;

                            if(cy < 128)        cy = 128;
                            else if(cy > 4096)  cy = 4096;

                            RefreshDownscales(GetDlgItem(hwnd, IDC_DOWNSCALE), cx, cy);

                            bDataChanged = true;
                            break;
                        }

                    case IDC_DISABLEAERO:
                        if(HIWORD(wParam) == BN_CLICKED)
                            bDataChanged = true;
                        break;

                    case IDC_FPS_EDIT:
                        if(HIWORD(wParam) == EN_CHANGE)
                            bDataChanged = true;
                        break;

                    case IDC_DOWNSCALE:
                        if(HIWORD(wParam) == CBN_SELCHANGE)
                            bDataChanged = true;
                        break;
                }

                if(bDataChanged)
                {
                    ShowWindow(GetDlgItem(hwnd, IDC_INFO), SW_SHOW);
                    SetChangedSettings(true);
                }
                break;
            }
    }
    return FALSE;
}
Пример #7
0
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	char const * class_name = "Pong";
	char const * window_title = "Adolf Hitler Pong";

	WNDCLASSEX window_class;
	window_class.cbSize = sizeof(window_class);
	window_class.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
	window_class.lpfnWndProc = &window_procedure;
	window_class.cbClsExtra = 0;
	window_class.cbWndExtra = 0;
	window_class.hInstance = hInstance;
	window_class.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HITLER));
	window_class.hCursor = LoadCursor(0, IDC_ARROW);
	window_class.hbrBackground = reinterpret_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
	window_class.lpszMenuName = 0;
	window_class.lpszClassName = class_name;
	window_class.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HITLER));
	RegisterClassEx(&window_class);

	HWND window_handle = CreateWindowEx(0, class_name, window_title, WS_POPUP | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, window_width, window_height, 0, 0, hInstance, 0);
	//SetTimer(window_handle, 0, 1000 / fps, 0);

	std::string arguments(lpCmdLine);
	if(!arguments.empty())
	{
		if(arguments[0] == '"' && arguments.length() >= 2)
		{
			arguments.erase(arguments.begin());
			arguments.erase(arguments.end() - 1);
		}
		bool success = game.load_demo(arguments);
		if(!success)
		{
			MessageBox(window_handle, "Unable to load demo file", "Demo playback error", MB_OK | MB_ICONERROR);
			SendMessage(window_handle, WM_DESTROY, 0, 0);
			return 0;
		}
	}
	else
		game.start_game();

	nil::ini ini;
	if(ini.load("pong.ini"))
	{
		game.set_demo_level_limit(ini.number<unsigned>("demo_level_limit", 3));
		SetThreadPriority(GetCurrentThread(), ini.number<int>("thread_priority", 0));
	}

	LARGE_INTEGER frequency_struct;
	QueryPerformanceFrequency(&frequency_struct);
	unsigned long long divisor = frequency_struct.QuadPart / fps;
	unsigned long long last_state = 0ull;
	while(run)
	{
		MSG message;
		while(PeekMessage(&message, window_handle, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&message);
			DispatchMessage(&message);
		}

		LARGE_INTEGER counter;
		QueryPerformanceCounter(&counter);
		unsigned long long current_state = counter.QuadPart / divisor;
		if(last_state < current_state)
		{
			game.invalidate(window_handle);
			game.process_frame(window_handle);
			last_state = current_state;
		}
		//Sleep(20);
	}

	return 0;
}
Пример #8
0
BOOL CreateWindowGL (GL_Window* window)									// This Code Creates Our OpenGL Window
{
	DWORD windowStyle = WS_OVERLAPPEDWINDOW;							// Define Our Window Style
	DWORD windowExtendedStyle = WS_EX_APPWINDOW;						// Define The Window's Extended Style

	PIXELFORMATDESCRIPTOR pfd =											// pfd Tells Windows How We Want Things To Be
	{
		sizeof (PIXELFORMATDESCRIPTOR),									// Size Of This Pixel Format Descriptor
		1,																// Version Number
		PFD_DRAW_TO_WINDOW |											// Format Must Support Window
		PFD_SUPPORT_OPENGL |											// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,												// Must Support Double Buffering
		PFD_TYPE_RGBA,													// Request An RGBA Format
		window->init.bitsPerPixel,										// Select Our Color Depth
		0, 0, 0, 0, 0, 0,												// Color Bits Ignored
		0,																// No Alpha Buffer
		0,																// Shift Bit Ignored
		0,																// No Accumulation Buffer
		0, 0, 0, 0,														// Accumulation Bits Ignored
		16,																// 16Bit Z-Buffer (Depth Buffer)  
		0,																// No Stencil Buffer
		0,																// No Auxiliary Buffer
		PFD_MAIN_PLANE,													// Main Drawing Layer
		0,																// Reserved
		0, 0, 0															// Layer Masks Ignored
	};

	RECT windowRect = {0, 0, window->init.width, window->init.height};	// Define Our Window Coordinates

	GLuint PixelFormat;													// Will Hold The Selected Pixel Format

	if (window->init.isFullScreen == TRUE)								// Fullscreen Requested, Try Changing Video Modes
	{
		if (ChangeScreenResolution (window->init.width, window->init.height, window->init.bitsPerPixel) == FALSE)
		{
			// Fullscreen Mode Failed.  Run In Windowed Mode Instead
			MessageBox (HWND_DESKTOP, "Mode Switch Failed.\nRunning In Windowed Mode.", "Error", MB_OK | MB_ICONEXCLAMATION);
			window->init.isFullScreen = FALSE;							// Set isFullscreen To False (Windowed Mode)
		}
		else															// Otherwise (If Fullscreen Mode Was Successful)
		{
			ShowCursor (FALSE);											// Turn Off The Cursor
			windowStyle = WS_POPUP;										// Set The WindowStyle To WS_POPUP (Popup Window)
			windowExtendedStyle |= WS_EX_TOPMOST;						// Set The Extended Window Style To WS_EX_TOPMOST
		}																// (Top Window Covering Everything Else)
	}
	else																// If Fullscreen Was Not Selected
	{
		// Adjust Window, Account For Window Borders
		AdjustWindowRectEx (&windowRect, windowStyle, 0, windowExtendedStyle);
	}

	// Create The OpenGL Window
	window->hWnd = CreateWindowEx (windowExtendedStyle,					// Extended Style
								   window->init.application->className,	// Class Name
								   window->init.title,					// Window Title
								   windowStyle,							// Window Style
								   0, 0,								// Window X,Y Position
								   windowRect.right - windowRect.left,	// Window Width
								   windowRect.bottom - windowRect.top,	// Window Height
								   HWND_DESKTOP,						// Desktop Is Window's Parent
								   0,									// No Menu
								   window->init.application->hInstance, // Pass The Window Instance
								   window);

	if (window->hWnd == 0)												// Was Window Creation A Success?
	{
		return FALSE;													// If Not Return False
	}

	window->hDC = GetDC (window->hWnd);									// Grab A Device Context For This Window
	if (window->hDC == 0)												// Did We Get A Device Context?
	{
		// Failed
		DestroyWindow (window->hWnd);									// Destroy The Window
		window->hWnd = 0;												// Zero The Window Handle
		return FALSE;													// Return False
	}

	PixelFormat = ChoosePixelFormat (window->hDC, &pfd);				// Find A Compatible Pixel Format
	if (PixelFormat == 0)												// Did We Find A Compatible Format?
	{
		// Failed
		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
		window->hDC = 0;												// Zero The Device Context
		DestroyWindow (window->hWnd);									// Destroy The Window
		window->hWnd = 0;												// Zero The Window Handle
		return FALSE;													// Return False
	}

	if (SetPixelFormat (window->hDC, PixelFormat, &pfd) == FALSE)		// Try To Set The Pixel Format
	{
		// Failed
		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
		window->hDC = 0;												// Zero The Device Context
		DestroyWindow (window->hWnd);									// Destroy The Window
		window->hWnd = 0;												// Zero The Window Handle
		return FALSE;													// Return False
	}

	window->hRC = wglCreateContext (window->hDC);						// Try To Get A Rendering Context
	if (window->hRC == 0)												// Did We Get A Rendering Context?
	{
		// Failed
		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
		window->hDC = 0;												// Zero The Device Context
		DestroyWindow (window->hWnd);									// Destroy The Window
		window->hWnd = 0;												// Zero The Window Handle
		return FALSE;													// Return False
	}

	// Make The Rendering Context Our Current Rendering Context
	if (wglMakeCurrent (window->hDC, window->hRC) == FALSE)
	{
		// Failed
		wglDeleteContext (window->hRC);									// Delete The Rendering Context
		window->hRC = 0;												// Zero The Rendering Context
		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
		window->hDC = 0;												// Zero The Device Context
		DestroyWindow (window->hWnd);									// Destroy The Window
		window->hWnd = 0;												// Zero The Window Handle
		return FALSE;													// Return False
	}

	ShowWindow (window->hWnd, SW_NORMAL);								// Make The Window Visible
	window->isVisible = TRUE;											// Set isVisible To True

	//ReshapeGL (window->init.width, window->init.height);				// Reshape Our GL Window

	ZeroMemory (window->keys, sizeof (Keys));							// Clear All Keys

	window->lastTickCount = GetTickCount ();							// Get Tick Count

	return TRUE;														// Window Creating Was A Success
																		// Initialization Will Be Done In WM_CREATE
}
Пример #9
0
void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
{
	WNDCLASSEX wc;
	DEVMODE dmScreenSettings;
	int posX, posY;


	// Get an external pointer to this object.	
	ApplicationHandle = this;

	// Get the instance of this application.
	m_hinstance = GetModuleHandle(NULL);

	// Give the application a name.
	m_applicationName = L"Engine";

	// Setup the windows class with default settings.
	wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = m_hinstance;
	wc.hIcon		 = LoadIcon(NULL, IDI_WINLOGO);
	wc.hIconSm       = wc.hIcon;
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = m_applicationName;
	wc.cbSize        = sizeof(WNDCLASSEX);
	
	// Register the window class.
	RegisterClassEx(&wc);

	// Determine the resolution of the clients desktop screen.
	screenWidth  = GetSystemMetrics(SM_CXSCREEN);
	screenHeight = GetSystemMetrics(SM_CYSCREEN);

	// Setup the screen settings depending on whether it is running in full screen or in windowed mode.
	if(FULL_SCREEN)
	{
		// If full screen set the screen to maximum size of the users desktop and 32bit.
		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
		dmScreenSettings.dmSize       = sizeof(dmScreenSettings);
		dmScreenSettings.dmPelsWidth  = (unsigned long)screenWidth;
		dmScreenSettings.dmPelsHeight = (unsigned long)screenHeight;
		dmScreenSettings.dmBitsPerPel = 32;			
		dmScreenSettings.dmFields     = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

		// Change the display settings to full screen.
		ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);

		// Set the position of the window to the top left corner.
		posX = posY = 0;
	}
	else
	{
		// If windowed then set it to 800x600 resolution.
		screenWidth  = 800;
		screenHeight = 600;

		// Place the window in the middle of the screen.
		posX = (GetSystemMetrics(SM_CXSCREEN) - screenWidth)  / 2;
		posY = (GetSystemMetrics(SM_CYSCREEN) - screenHeight) / 2;
	}

	// Create the window with the screen settings and get the handle to it.
	m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName, 
						    WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
						    posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);

	// Bring the window up on the screen and set it as main focus.
	ShowWindow(m_hwnd, SW_SHOW);
	SetForegroundWindow(m_hwnd);
	SetFocus(m_hwnd);

	// Hide the mouse cursor.
	ShowCursor(false);

	return;
}
Пример #10
0
//************************************
// Method:    CreateWindow
// FullName:  QuackWin::CreateWindow
// Access:    public 
// Returns:   bool
// Qualifier:
// Parameter: int width
// Parameter: int height
// Parameter: int colorBits
//************************************
bool QuackWin::B_CreateWindow(int width, int height, int colorBits) {
	if (!classRegistered) {
		WNDCLASS wc;

		memset(&wc, 0, sizeof(wc));

		wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
		wc.lpfnWndProc = (WNDPROC)wndproc;
		wc.cbClsExtra = 0;
		wc.cbWndExtra = sizeof(void*)+sizeof(int);
		wc.hInstance = GetModuleHandle(NULL);
		//wc.hIcon = LoadIcon(hinstOpenGL, MAKEINTRESOURCE(IDI_ICON1));
		wc.hCursor = LoadCursor(NULL, IDC_ARROW);
		wc.hbrBackground = NULL;
		wc.lpszMenuName = 0;
		wc.lpszClassName = WINDOW_CLASS_NAME;

		if (!RegisterClass(&wc)) {
			// TODO: Add safe error here
			// unable to register class
		}
		classRegistered = true;
	}

	// create HWND
	if (!hWnd) {
		hWnd = CreateWindowEx(
			WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
			WINDOW_CLASS_NAME,
			"Quack",
			WS_VISIBLE | WS_OVERLAPPEDWINDOW,
			0,
			0,
			width,
			height,
			NULL,
			NULL,
			hinstOpenGL,
			this
			);

		if (!hWnd) {
			// error creating the window
		}

		ShowWindow(hWnd, SW_SHOW);
		UpdateWindow(hWnd);
	}

	if (!(hDC = GetDC(hWnd))) {
		ShowWindow(hWnd, SW_HIDE);
		DestroyWindow(hWnd);
		hWnd = NULL;
		return false;
	}

	// Create OpenGL Context
	if (!MakeContext()) {
		ShowWindow(hWnd, SW_HIDE);
		DestroyWindow(hWnd);
		hWnd = NULL;

		return false;
	}

	SetForegroundWindow(hWnd);
	SetFocus(hWnd);

	return true;
}
Пример #11
0
bool InitGLCapture()
{
    static HWND hwndOpenGLSetupWindow = NULL;
    bool bSuccess = false;

    if(!hwndOpenGLSetupWindow)
    {
        WNDCLASSEX windowClass;

        ZeroMemory(&windowClass, sizeof(windowClass));

        windowClass.cbSize = sizeof(windowClass);
        windowClass.style = CS_OWNDC;
        windowClass.lpfnWndProc = DefWindowProc;
        windowClass.lpszClassName = TEXT("OBSOGLHookClass");
        windowClass.hInstance = hinstMain;

        if(RegisterClassEx(&windowClass))
        {
            hwndOpenGLSetupWindow = CreateWindowEx (0,
                TEXT("OBSOGLHookClass"),
                TEXT("OBS OpenGL Context Window"),
                WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
                0, 0,
                1, 1,
                NULL,
                NULL,
                hinstMain,
                NULL
                );
        }
    }

    HMODULE hGL = GetModuleHandle(TEXT("opengl32.dll"));
    if(hGL && hwndOpenGLSetupWindow)
    {
        pglReadBuffer       = (GLREADBUFFERPROC)        GetProcAddress(hGL, "glReadBuffer");
        pglReadPixels       = (GLREADPIXELSPROC)        GetProcAddress(hGL, "glReadPixels");
        pglGetError         = (GLGETERRORPROC)          GetProcAddress(hGL, "glGetError");
        pwglSwapLayerBuffers= (WGLSWAPLAYERBUFFERSPROC) GetProcAddress(hGL, "wglSwapLayerBuffers");
        pwglSwapBuffers=      (WGLSWAPBUFFERSPROC)      GetProcAddress(hGL, "wglSwapBuffers");
        pwglDeleteContext   = (WGLDELETECONTEXTPROC)    GetProcAddress(hGL, "wglDeleteContext");
        pwglGetProcAddress  = (WGLGETPROCADDRESSPROC)   GetProcAddress(hGL, "wglGetProcAddress");
        pwglMakeCurrent     = (WGLMAKECURRENTPROC)      GetProcAddress(hGL, "wglMakeCurrent");
        pwglCreateContext   = (WGLCREATECONTEXTPROC)    GetProcAddress(hGL, "wglCreateContext");

        if( !pglReadBuffer || !pglReadPixels || !pglGetError || !pwglSwapLayerBuffers || !pwglSwapBuffers ||
            !pwglDeleteContext || !pwglGetProcAddress || !pwglMakeCurrent || !pwglCreateContext)
        {
            return false;
        }

        HDC hDC = GetDC(hwndOpenGLSetupWindow);
        if(hDC)
        {
            PIXELFORMATDESCRIPTOR pfd;
            ZeroMemory(&pfd, sizeof(pfd));
            pfd.nSize = sizeof(pfd);
            pfd.nVersion = 1;
            pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_GENERIC_ACCELERATED;
            pfd.iPixelType = PFD_TYPE_RGBA;
            pfd.cColorBits = 32;
            pfd.cDepthBits = 32;
            pfd.cAccumBits = 32;
            pfd.iLayerType = PFD_MAIN_PLANE;
            SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd);

            HGLRC hGlrc = jimglCreateContext(hDC);
            if(hGlrc)
            {
                jimglMakeCurrent(hDC, hGlrc);

                pglBufferData       = (GLBUFFERDATAARBPROC)     jimglGetProcAddress("glBufferData");
                pglDeleteBuffers    = (GLDELETEBUFFERSARBPROC)  jimglGetProcAddress("glDeleteBuffers");
                pglGenBuffers       = (GLGENBUFFERSARBPROC)     jimglGetProcAddress("glGenBuffers");
                pglMapBuffer        = (GLMAPBUFFERPROC)         jimglGetProcAddress("glMapBuffer");
                pglUnmapBuffer      = (GLUNMAPBUFFERPROC)       jimglGetProcAddress("glUnmapBuffer");
                pglBindBuffer       = (GLBINDBUFFERPROC)        jimglGetProcAddress("glBindBuffer");

                UINT lastErr = GetLastError();

                if(pglBufferData && pglDeleteBuffers && pglGenBuffers && pglMapBuffer && pglUnmapBuffer && pglBindBuffer)
                {
                    glHookSwapBuffers.Hook((FARPROC)SwapBuffers, (FARPROC)SwapBuffersHook);
                    glHookSwapLayerBuffers.Hook((FARPROC)jimglSwapLayerBuffers, (FARPROC)wglSwapLayerBuffersHook);
                    glHookwglSwapBuffers.Hook((FARPROC)jimglSwapBuffers, (FARPROC)wglSwapBuffersHook);
                    glHookDeleteContext.Hook((FARPROC)jimglDeleteContext, (FARPROC)wglDeleteContextHook);
                    bSuccess = true;
                }

                jimglMakeCurrent(NULL, NULL);

                jimglDeleteContext(hGlrc);

                ReleaseDC(hwndOpenGLSetupWindow, hDC);

                if(bSuccess)
                {
                    glHookSwapBuffers.Rehook();
                    glHookSwapLayerBuffers.Rehook();
                    glHookwglSwapBuffers.Rehook();
                    glHookDeleteContext.Rehook();

                    DestroyWindow(hwndOpenGLSetupWindow);
                    hwndOpenGLSetupWindow = NULL;

                    UnregisterClass(TEXT("OBSOGLHookClass"), hinstMain);
                }
            }

            if(hwndOpenGLSetupWindow)
                ReleaseDC(hwndOpenGLSetupWindow, hDC);
        }
    }

    return bSuccess;
}
Пример #12
0
void khm_create_standard_toolbar(HWND rebar) {
    HWND hwtb;
    SIZE sz;
    HBITMAP hbm_blank;
    HIMAGELIST hiList;
    REBARBANDINFO rbi;
    khui_menu_def * def;
    khui_action * act;
    khui_action_ref * aref;
    int idx_blank;

    def = khui_find_menu(KHUI_TOOLBAR_STANDARD);

    if (!def) {
#ifdef DEBUG
        assert(FALSE);
#endif
        return;
    }

    hwtb = CreateWindowEx(0 ,
                          TOOLBARCLASSNAME,
                          (LPWSTR) NULL,
                          WS_CHILD |
                          TBSTYLE_FLAT |
                          TBSTYLE_AUTOSIZE |
                          TBSTYLE_TOOLTIPS |
                          CCS_NORESIZE |
                          CCS_NOPARENTALIGN |
                          CCS_ADJUSTABLE |
                          CCS_NODIVIDER,
                          0, 0, 0, 0, rebar,
                          (HMENU) NULL, khm_hInstance,
                          NULL);

    if(!hwtb) {
#ifdef DEBUG
        assert(FALSE);
#endif
        return;
    }

#if (_WIN32_IE >= 0x0501)
    SendMessage(hwtb, TB_SETEXTENDEDSTYLE, 0,
                TBSTYLE_EX_MIXEDBUTTONS | TBSTYLE_EX_DRAWDDARROWS);
#endif

    hiList = ImageList_Create(
        KHUI_TOOLBAR_IMAGE_WIDTH,
        KHUI_TOOLBAR_IMAGE_HEIGHT,
        ILC_MASK,
        (int) khui_action_list_length(def->items),
        3);

    hbm_blank = LoadImage(khm_hInstance,
                          MAKEINTRESOURCE(IDB_TB_BLANK),
                          IMAGE_BITMAP,
                          KHUI_TOOLBAR_IMAGE_WIDTH,
                          KHUI_TOOLBAR_IMAGE_HEIGHT, 0);
    idx_blank = ImageList_AddMasked(hiList, hbm_blank, RGB(0,0,0));

    khui_hwnd_standard_toolbar = hwtb;
    khui_tb_blank = idx_blank;

    def = khui_find_menu(KHUI_TOOLBAR_STANDARD);

    aref = def->items;

    SendMessage(hwtb,
        TB_BUTTONSTRUCTSIZE,
        sizeof(TBBUTTON),
        0);

    SendMessage(hwtb,
        TB_SETBITMAPSIZE,
        0,
        MAKELONG(KHUI_TOOLBAR_IMAGE_WIDTH,KHUI_TOOLBAR_IMAGE_HEIGHT));

    SendMessage(hwtb,
        TB_SETIMAGELIST,
        0,
        (LPARAM) hiList);

    SendMessage(hwtb,
        TB_SETBUTTONSIZE,
        0,
        MAKELONG(KHUI_TOOLBAR_IMAGE_WIDTH,KHUI_TOOLBAR_IMAGE_HEIGHT));

    while(aref && aref->action != KHUI_MENU_END) {
        if(aref->action == KHUI_MENU_SEP) {
            khui_add_action_to_toolbar(hwtb,
                                       NULL,
                                       KHUI_TOOLBAR_ADD_SEP,
                                       hiList);
        } else {
            act = khui_find_action(aref->action);
            khui_add_action_to_toolbar(hwtb,
                                       act,
                                       KHUI_TOOLBAR_ADD_BITMAP |
                                       ((aref->flags & KHUI_ACTIONREF_SUBMENU)?
                                        KHUI_TOOLBAR_ADD_DROPDOWN: 0),
                                       hiList);
        }
        aref ++;
    }

    SendMessage(hwtb,
                TB_AUTOSIZE,
                0,0);

    SendMessage(hwtb,
                TB_GETMAXSIZE,
                0,
                (LPARAM) &sz);

    sz.cy += 5;

    ZeroMemory(&rbi, sizeof(rbi));

    rbi.cbSize = sizeof(rbi);
    rbi.fMask =
        RBBIM_ID |
        RBBIM_CHILD |
        RBBIM_CHILDSIZE |
        RBBIM_IDEALSIZE |
        RBBIM_SIZE |
        RBBIM_STYLE;
    rbi.fStyle =
        RBBS_USECHEVRON |
        RBBS_BREAK;
    rbi.hwndChild = hwtb;

    rbi.wID = KHUI_TOOLBAR_STANDARD;
    rbi.cx = sz.cx;
    rbi.cxMinChild = sz.cx;
    rbi.cyMinChild = sz.cy;
    rbi.cyChild = rbi.cyMinChild;
    rbi.cyMaxChild = rbi.cyMinChild;
    rbi.cyIntegral = rbi.cyMinChild;

    rbi.cxIdeal = rbi.cx;

    SendMessage(rebar,
        RB_INSERTBAND,
        0,
        (LPARAM) &rbi);
}
Пример #13
0
bool WINDOW::InitExtended()
{
	//Put up dialog box and find out which number of samples to use
	DialogBox(hInstance, MAKEINTRESOURCE(IDD_RESOLUTION), HWND_DESKTOP, SelectModeProc);

	//Create a rect structure for the size/position of the window
	RECT windowRect;
	windowRect.left=0;
	windowRect.right=(long)width;
	windowRect.top=0;
	windowRect.bottom=(long)height;


	//Window class structure
	WNDCLASS wc;

	//Fill in window class struct
	wc.style=			CS_HREDRAW | CS_VREDRAW | CS_OWNDC;		//Style - redraw on move, own DC
	wc.lpfnWndProc=		(WNDPROC) WndProc;						//Wndproc handles messages
	wc.cbClsExtra=		0;
	wc.cbWndExtra=		0;
	wc.hInstance=		hInstance;								//Handle to instance
	wc.hIcon=			LoadIcon(NULL, IDI_WINLOGO);			//Load windows logo icon
	wc.hCursor=			LoadCursor(NULL, IDC_ARROW);			//Load standard cursor
	wc.hbrBackground=	NULL;									//No background required
	wc.lpszMenuName=	NULL;									//No Menu
	wc.lpszClassName=	"OpenGL";								//class name

	//Register window class
	if(!RegisterClass(&wc))
	{
		LOG::Instance()->OutputError("Unable to register window class");
		return false;
	}
	else
		LOG::Instance()->OutputSuccess("Window Class Registered");


	//Switch to fullscreen if required
	if(fullscreen)
	{
		DEVMODE screenSettings;	//device mode
		memset(&screenSettings, 0, sizeof(screenSettings));

		screenSettings.dmSize=sizeof(screenSettings);

		//Set size & color bits
		screenSettings.dmPelsWidth=width;
		screenSettings.dmPelsHeight=height;
		screenSettings.dmBitsPerPel=redBits+greenBits+blueBits+alphaBits;
		screenSettings.dmFields= DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

		//Try to change to full screen
		if(ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			//If failed, ask whether to run in window
			char * errorText="The Requested Full Screen Mode Is Not Supported By\n Your Video Card. Use Windowed Mode Instead?";
			if(MessageBox(NULL, errorText, title, MB_YESNO | MB_ICONEXCLAMATION)==IDYES)
				fullscreen=false;
			else
			{
				LOG::Instance()->OutputError("Requested full screen mode not supported, quitting...");
				return false;
			}
		}
	}


	//Set window style & extended style
	DWORD style, exStyle;
	if(fullscreen)
	{
		exStyle=WS_EX_APPWINDOW;
		style=WS_POPUP | WS_VISIBLE;	//no border

		//Hide cursor
		ShowCursor(false);
	}
	else
	{
		exStyle=WS_EX_CLIENTEDGE;
		style=WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_VISIBLE;
	}


	//Adjust the window size so that client area is the size requested
	AdjustWindowRectEx(&windowRect, style, false, exStyle);



	//Create Window
	if(!(hWnd=CreateWindowEx(	exStyle,									//window style
								"OpenGL",									//class name
								title,
								WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style,	//style
								0, 0,										//position
								windowRect.right-windowRect.left,			//width
								windowRect.bottom-windowRect.top,			//height
								NULL, NULL,
								hInstance,
								NULL)))
	{
		Shutdown();
		LOG::Instance()->OutputError("Unable to create window");
		return false;
	}



	//Get DC
	if(!(hDC=GetDC(hWnd)))
	{
		//if failed,
		Shutdown();
		LOG::Instance()->OutputError("Cannot get the Device Context");
		return false;
	}
	else
		LOG::Instance()->OutputSuccess("DC Created");


		
	

	//Set a list of attributes for our pixel format
	int attributes[26];

	attributes[0]	=	WGL_RED_BITS_ARB;		//bits
	attributes[1]	=	redBits;
	attributes[2]	=	WGL_GREEN_BITS_ARB;
	attributes[3]	=	greenBits;
	attributes[4]	=	WGL_BLUE_BITS_ARB;
	attributes[5]	=	blueBits;
	attributes[6]	=	WGL_ALPHA_BITS_ARB;
	attributes[7]	=	alphaBits;
	attributes[8]	=	WGL_DEPTH_BITS_ARB;
	attributes[9]	=	depthBits;
	attributes[10]	=	WGL_STENCIL_BITS_ARB;
	attributes[11]	=	stencilBits;
	
	attributes[12]	=	WGL_DRAW_TO_WINDOW_ARB;	//required to be true
	attributes[13]	=	true;
	attributes[14]	=	WGL_SUPPORT_OPENGL_ARB;
	attributes[15]	=	true;
	attributes[16]	=	WGL_DOUBLE_BUFFER_ARB;
	attributes[17]	=	true;
	
	attributes[18]	=	WGL_ACCELERATION_ARB;	//required to be FULL_ACCELERATION_ARB
	attributes[19]	=	WGL_FULL_ACCELERATION_ARB;

	//Set antialias attributes
	if(numSamples>0)
	{
		attributes[20]	=	WGL_SAMPLE_BUFFERS_ARB;	//Multisample
		attributes[21]	=	true;
		attributes[22]	=	WGL_SAMPLES_ARB;
		attributes[23]	=	numSamples;
	}
	else
	{
		attributes[20]	=	0;
		attributes[21]	=	0;
		attributes[22]	=	0;
		attributes[23]	=	0;
	}

	//End the list with (0, 0)
	attributes[24]=0;
	attributes[25]=0;

	//Find the best pixelformat matching out requirements
	unsigned int numFormats;
	int pixelFormat;

	float fAttribs[]={0.0f, 0.0f};

	if(!wglChoosePixelFormatARB(hDC, attributes, fAttribs, 1, &pixelFormat, &numFormats))
	{
		LOG::Instance()->OutputError("Unable to find a suitable pixel format");
		return false;
	}

	//Set pixel format
	if(!SetPixelFormat(hDC, pixelFormat, NULL))
	{
		//if failed,
		Shutdown();
		LOG::Instance()->OutputError("Cannot set the pixel format");
		return false;
	}
	else
		LOG::Instance()->OutputSuccess("Pixel format set");
	
	//Create context
	if(!(hRC=wglCreateContext(hDC)))
	{
		//if failed,
		Shutdown();
		LOG::Instance()->OutputError("Unable to Create context");
		return false;
	}
	else
		LOG::Instance()->OutputSuccess("Context Created");

	//Make current
	if(!MakeCurrent())
	{
		Shutdown();
		return false;
	}
	else
		LOG::Instance()->OutputSuccess("GL rendering context made current");



	//Show window
	ShowWindow(hWnd, SW_SHOW);
	SetForegroundWindow(hWnd);
	SetFocus(hWnd);

	//Set Swap interval
	wglSwapIntervalEXT(vSync ? 1 : 0);



	//Update class variables
	glGetIntegerv(GL_RED_BITS, &redBits);
	glGetIntegerv(GL_GREEN_BITS, &greenBits);
	glGetIntegerv(GL_BLUE_BITS, &blueBits);
	glGetIntegerv(GL_ALPHA_BITS, &alphaBits);
	glGetIntegerv(GL_DEPTH_BITS, &depthBits);
	glGetIntegerv(GL_STENCIL_BITS, &stencilBits);

	//Output these parameters
	LOG::Instance()->OutputNewLine();
	LOG::Instance()->OutputSuccess("Window Created!");
	LOG::Instance()->OutputNewLine();
	LOG::Instance()->OutputSuccess("Window Size: (%d, %d)", width, height);
	LOG::Instance()->OutputSuccess("Color Buffer Bits (R, G, B, A): (%d, %d, %d, %d)",
							redBits, greenBits, blueBits, alphaBits);
	LOG::Instance()->OutputSuccess("Depth Buffer Bits: %d", depthBits);
	LOG::Instance()->OutputSuccess("Stencil Buffer Bits: %d", stencilBits);
	LOG::Instance()->OutputNewLine();

	return true;
}
Пример #14
0
/****************************************************************************
 *                                                                          *
 * Function: CreateHypCtrl                                                  *
 *                                                                          *
 * Purpose : Create Hyperlink control.                                      *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/
HWND CreateHypCtrl(HWND hWndParent, HYPCTRL* pHc, int x, int y, int width, int height)
{
	HYPCTRL* pHcWnd;
	HWND hWndHyperlink;
	RECT rect;
	LOGFONT lf;
	HFONT hFontParent, hFontNormal, hFontHover;

	// some error checking
	if (hInst == NULL) return (HWND) NULL;
	if (hWndParent == NULL) return (HWND) NULL;

	if (pHc->cbFn == NULL) {
		// if the hyperlink opens a normal link, require the szLink member
		if (pHc->szLink == NULL) return (HWND) NULL;
	} else {
		// if the hyperlink calls a callback function, require the szText member
		if (pHc->szText == NULL) return (HWND) NULL;
	}

	hWndHyperlink = CreateWindow(lpszClassname,
						NULL,
						WS_CHILD,
						x, y, width, height,
						hWndParent,
						NULL,
						hInst,
						NULL);

	if (!hWndHyperlink) return (HWND) NULL;

	// alloc some space to hold all hyperlink stuff
	if ((pHcWnd = GlobalAllocPtr(GPTR, sizeof(HYPCTRL))) == NULL) {
		DestroyWindow(hWndHyperlink);
		return (HWND) NULL;
	}
	CopyMemory(pHcWnd, pHc, sizeof(HYPCTRL));

	// copy the text entries from HYPCTRL
	if (pHcWnd->cbFn == NULL) {
		if (pHcWnd->szLink != NULL) {
			if ((pHcWnd->szLink = (LPTSTR) GlobalAllocPtr(GPTR, STRBYTESIZE(pHc->szLink))) == NULL) {
				if (pHcWnd) GlobalFreePtr(pHcWnd);
				DestroyWindow(hWndHyperlink);
				return (HWND) NULL;
			}
			CopyMemory(pHcWnd->szLink, pHc->szLink, STRBYTESIZE(pHc->szLink));
		}
	}

	if (pHcWnd->szText != NULL) {
		if ((pHcWnd->szText = GlobalAllocPtr(GPTR, STRBYTESIZE(pHc->szText))) == NULL) {
			if (pHcWnd->szLink) GlobalFreePtr(pHcWnd->szLink);
			if (pHcWnd) GlobalFreePtr(pHcWnd);
			DestroyWindow(hWndHyperlink);
			return (HWND) NULL;
		}
		CopyMemory(pHcWnd->szText, pHc->szText, STRBYTESIZE(pHc->szText));
	} else {
		// no callback function and no szText given so we use szLink as text
		if(pHcWnd->cbFn == NULL) pHcWnd->szText = pHcWnd->szLink;
	}

	if (pHcWnd->szTooltip != NULL) {
		if ((pHcWnd->szTooltip = GlobalAllocPtr(GPTR, STRBYTESIZE(pHc->szTooltip))) == NULL) {
			if (pHcWnd->szLink) GlobalFreePtr(pHcWnd->szLink);
			if (pHcWnd->szText) GlobalFreePtr(pHcWnd->szText);
			if (pHcWnd) GlobalFreePtr(pHcWnd);
			DestroyWindow(hWndHyperlink);
			return (HWND) NULL;
		}
		CopyMemory(pHcWnd->szTooltip, pHc->szTooltip, STRBYTESIZE(pHc->szTooltip));
	}

	// save a pointer to the structure in the window extra space
	SetWindowLong(hWndHyperlink, WND_HYPSTRUCT, (LONG) (pHcWnd));
	SetWindowWord(hWndHyperlink, WND_ISHOVER, (WORD) FALSE);

	// create the fonts for the control
	hFontParent = (HFONT) SendMessage(GetParent(hWndHyperlink), WM_GETFONT, 0, 0);

	if (hFontParent != NULL) {
		GetObject(hFontParent, sizeof(LOGFONT), &lf);

		switch (pHcWnd->ulStyle) {
			case ulHover:
				hFontNormal = CreateFontIndirect(&lf);
				lf.lfUnderline = (BYTE) TRUE;
				hFontHover  = CreateFontIndirect(&lf);
				break;
			case ulAlways:
				lf.lfUnderline = (BYTE) TRUE;
				hFontNormal = CreateFontIndirect(&lf);
				hFontHover  = CreateFontIndirect(&lf);
				break;
			case ulNone:
				hFontNormal = CreateFontIndirect(&lf);
				hFontHover  = CreateFontIndirect(&lf);
				break;
			}
			// save the fonts in the window extra space
			SetWindowLong(hWndHyperlink, WND_FONTN, (LONG) hFontNormal);
			SetWindowLong(hWndHyperlink, WND_FONTH, (LONG) hFontHover);
	} else {
		// use the system font
		SetWindowLong(hWndHyperlink, WND_FONTN, (LONG) NULL);
		SetWindowLong(hWndHyperlink, WND_FONTH, (LONG) NULL);
	}

	GetClientRect(hWndHyperlink, &rect);

	// adjust window size to fit the text
	if (pHcWnd->bAutoSize) {
		PAINTSTRUCT ps;
		HDC hdc;
		SIZE size;

		hdc	= BeginPaint(hWndHyperlink, &ps);
 		SelectObject(hdc, (HFONT) GetWindowLong(hWndHyperlink, WND_FONTN));
		GetTextExtentPoint32(hdc, pHcWnd->szText, GetStringLength(pHcWnd->szText), &size);
		rect.right	= size.cx - rect.left;
		rect.bottom	= size.cy - rect.top;
		EndPaint(hWndHyperlink, &ps);

		SetWindowPos(hWndHyperlink,
			0,
			0, 0, size.cx, size.cy,
			SWP_NOMOVE | SWP_NOZORDER);
	}

	// save window size in the window extra space
	SetWindowLong(hWndHyperlink, WND_LEFT, (LONG) (rect.left));
	SetWindowLong(hWndHyperlink, WND_TOP, (LONG) (rect.top));
	SetWindowLong(hWndHyperlink, WND_RIGHT, (LONG) (rect.right));
	SetWindowLong(hWndHyperlink, WND_BOTTOM, (LONG) (rect.bottom));

	// create tooltip if requested
	if (pHcWnd->szTooltip != NULL) {
    	HWND hWndTT;
    	TOOLINFO ti;

    	hWndTT = CreateWindowEx(WS_EX_TOPMOST,
    		TOOLTIPS_CLASS,
    		NULL,
    		WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		hWndHyperlink,
    		NULL,
    		hInst,
    		NULL);
    				
    	if (!hWndTT) return FALSE;

    	SetWindowPos(hWndTT,
    		HWND_TOPMOST,
    		0, 0, 0, 0,
    		SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

    	ti.cbSize      = sizeof(TOOLINFO);
    	ti.uFlags      = TTF_SUBCLASS;
    	ti.hwnd        = hWndHyperlink;
    	ti.hinst       = hInst;
    	ti.uId         = 0;
    	ti.lpszText    = pHcWnd->szTooltip; // get text for tooltip
    	ti.rect.left   = (LONG) GetWindowLong(hWndHyperlink, WND_LEFT);
    	ti.rect.top    = (LONG) GetWindowLong(hWndHyperlink, WND_TOP);
    	ti.rect.right  = (LONG) GetWindowLong(hWndHyperlink, WND_RIGHT);
    	ti.rect.bottom = (LONG) GetWindowLong(hWndHyperlink, WND_BOTTOM);

    	// add tooltip
    	SendMessage(hWndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
	}

	// show the window
	ShowWindow(hWndHyperlink, SW_NORMAL);
	UpdateWindow(hWndHyperlink);

	return hWndHyperlink;
}
Пример #15
0
qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
{
#ifdef __WXWINDOWS__
	glw_state.hWnd = *(HWND*) ri.Vid_GetWindowPtr();
#else
	WNDCLASS		wc;
	RECT			r;
	cvar_t			*vid_xpos, *vid_ypos;
	int				stylebits;
	int				x, y, w, h;
	int				exstyle;

	/* Register the frame class */
    wc.style         = 0;
    wc.lpfnWndProc   = (WNDPROC)glw_state.wndproc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = glw_state.hInstance;
    wc.hIcon         = 0;
    wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
	wc.hbrBackground = (void *)COLOR_GRAYTEXT;
    wc.lpszMenuName  = 0;
    wc.lpszClassName = WINDOW_CLASS_NAME;

    if (!RegisterClass (&wc) )
		ri.Sys_Error (ERR_FATAL, "Couldn't register window class");

	if (fullscreen)
	{
		exstyle = WS_EX_TOPMOST;
		stylebits = WS_POPUP|WS_VISIBLE;
	}
	else
	{
		exstyle = 0;
		stylebits = WINDOW_STYLE;
	}

	r.left = 0;
	r.top = 0;
	r.right  = width;
	r.bottom = height;

	AdjustWindowRect (&r, stylebits, FALSE);

	w = r.right - r.left;
	h = r.bottom - r.top;

	if (fullscreen)
	{
		x = 0;
		y = 0;
	}
	else
	{
		vid_xpos = ri.Cvar_Get ("vid_xpos", "0", 0);
		vid_ypos = ri.Cvar_Get ("vid_ypos", "0", 0);
		x = vid_xpos->value;
		y = vid_ypos->value;
	}

	glw_state.hWnd = CreateWindowEx (
		 exstyle, 
		 WINDOW_CLASS_NAME,
		 "Quake 2",
		 stylebits,
		 x, y, w, h,
		 NULL,
		 NULL,
		 glw_state.hInstance,
		 NULL);
#endif // ndef __WXWINDOWS__

	if (!glw_state.hWnd)
		ri.Sys_Error (ERR_FATAL, "Couldn't create window");
	
	ShowWindow( glw_state.hWnd, SW_SHOW );
	UpdateWindow( glw_state.hWnd );

	// init all the gl stuff for the window
	if (!GLimp_InitGL ())
	{
		ri.Con_Printf( PRINT_ALL, "VID_CreateWindow() - GLimp_InitGL failed\n");
		return false;
	}

	SetForegroundWindow( glw_state.hWnd );
	SetFocus( glw_state.hWnd );

	// let the sound and input subsystems know about the new window
	ri.Vid_NewWindow (width, height);

	return true;
}
Пример #16
0
BOOL CreateAppWindow(const char* title, int width, int height, int bits, bool fullscreenflag)
{
    windowWidth  = width;
    windowHeight = height;
    windowName   = title;

	GLuint		PixelFormat;			// Holds The Results After Searching For A Match
	WNDCLASS	wc;						// Windows Class Structure
	DWORD		dwExStyle;				// Window Extended Style
	DWORD		dwStyle;				// Window Style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	WindowRect.left=(long)0;			// Set Left Value To 0
	WindowRect.right=(long)width;		// Set Right Value To Requested Width
	WindowRect.top=(long)0;				// Set Top Value To 0
	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height

	gFullscreen=fullscreenflag;			// Set The Global Fullscreen Flag
    
    HICON hIcon = (HICON)LoadImage(0,IDI_WINLOGO,IMAGE_ICON,0,0,LR_SHARED);

	hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) WndProc;					// WndProc Handles Messages
	wc.cbClsExtra		= 0;									// No Extra Window Data
	wc.cbWndExtra		= 0;									// No Extra Window Data
	wc.hInstance		= hInstance;							// Set The Instance
	wc.hIcon			= 0;
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
	wc.hbrBackground	= NULL;									// No Background Required For GL
	wc.lpszMenuName		= NULL;									// We Don't Want A Menu
	wc.lpszClassName	= "OpenGL";								// Set The Class Name

	if (!RegisterClass(&wc))									// Attempt To Register The Window Class
	{
		MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;											// Return FALSE
	}
	
	if (gFullscreen)												// Attempt Fullscreen Mode?
	{
		DEVMODE dmScreenSettings;								// Device Mode
		memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
		dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
		dmScreenSettings.dmPelsWidth	= width;				// Selected Screen Width
		dmScreenSettings.dmPelsHeight	= height;				// Selected Screen Height
		dmScreenSettings.dmBitsPerPel	= bits;					// Selected Bits Per Pixel
		dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
		if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			// If The Mode Fails, Offer Two Options.  Quit Or Use Windowed Mode.
			if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
			{
				gFullscreen=FALSE;		// Windowed Mode Selected.  Fullscreen = FALSE
			}
			else
			{
				// Pop Up A Message Box Letting User Know The Program Is Closing.
				MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
				return FALSE;									// Return FALSE
			}
		}
	}

	if (gFullscreen)												// Are We Still In Fullscreen Mode?
	{
		dwExStyle=WS_EX_APPWINDOW;								// Window Extended Style
		dwStyle=WS_POPUP;										// Windows Style
		ShowCursor(FALSE);										// Hide Mouse Pointer
	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style
	}

	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);		// Adjust Window To True Requested Size

	// Create The Window
	if (!(hWnd=CreateWindowEx(	dwExStyle,							// Extended Style For The Window
								"OpenGL",							// Class Name
								title,								// Window Title
								dwStyle |							// Defined Window Style
								WS_CLIPSIBLINGS |					// Required Window Style
								WS_CLIPCHILDREN,					// Required Window Style
								0, 0,								// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,								// No Parent Window
								NULL,								// No Menu
								hInstance,							// Instance
								NULL)))								// Dont Pass Anything To WM_CREATE
	{
		CloseWindow();								// Reset The Display
		MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
	{
		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
		1,											// Version Number
		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,							// Must Support Double Buffering
		PFD_TYPE_RGBA,								// Request An RGBA Format
		bits,										// Select Our Color Depth
		0, 0, 0, 0, 0, 0,							// Color Bits Ignored
		0,											// No Alpha Buffer
		0,											// Shift Bit Ignored
		0,											// No Accumulation Buffer
		0, 0, 0, 0,									// Accumulation Bits Ignored
		16,											// 16Bit Z-Buffer (Depth Buffer)  
		0,											// No Stencil Buffer
		0,											// No Auxiliary Buffer
		PFD_MAIN_PLANE,								// Main Drawing Layer
		0,											// Reserved
		0, 0, 0										// Layer Masks Ignored
	};
	
	if (!(hDC=GetDC(hWnd)))							// Did We Get A Device Context?
	{
		CloseWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))	// Did Windows Find A Matching Pixel Format?
	{
		CloseWindow();								// Reset The Display
		MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if(!SetPixelFormat(hDC,PixelFormat,&pfd))		// Are We Able To Set The Pixel Format?
	{
		CloseWindow();								// Reset The Display
		MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if (!(hRC=wglCreateContext(hDC)))				// Are We Able To Get A Rendering Context?
	{
		CloseWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if(!wglMakeCurrent(hDC,hRC))					// Try To Activate The Rendering Context
	{
		CloseWindow();								// Reset The Display
		MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	ShowWindow(hWnd,SW_SHOW);						// Show The Window
	SetForegroundWindow(hWnd);						// Slightly Higher Priority
	SetFocus(hWnd);									// Sets Keyboard Focus To The Window
	ReSizeGLScene(width, height);					// Set Up Our Perspective GL Screen

	if (!InitGL())									// Initialize Our Newly Created GL Window
	{
		CloseWindow();								// Reset The Display
		MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	return TRUE;									// Success
}
Пример #17
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow)
{

	int iResult;

	// Initialize Winsock first
	iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
	if (iResult != 0) {
		MessageBoxA(NULL, "Unable to initialize Winsock!", "Error!", MB_ICONERROR | MB_OK);
		return 1;
	}

	HWND hwnd;
	MSG Msg;

	hDefaultFont = GetStockObject(DEFAULT_GUI_FONT);
	gHBRBackground = CreateSolidBrush(RGB(0, 0xCC, 0));

	wc.lpfnWndProc = WndProc;
	wc.hInstance = hInstance;

	if (!RegisterClassEx(&wc))
	{
		MessageBoxA(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	hwnd = CreateWindowEx(0, wc.lpszClassName, L"cREST", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 
		MASTER_WIDTH, MASTER_HEIGHT, NULL, NULL, hInstance, NULL);

	if (hwnd == NULL)
	{
		MessageBoxA(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	while (GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		//Checks for thread communications
		//TODO: move these out of the main msg loop
		if (Msg.message == SET_RESPONSE_TEXT) {
			if (Msg.lParam == THREAD_STATUS_CONNECTING) {
				SendMessage(vControls[AREA_RESPONSE], WM_SETTEXT, NULL, (LPARAM)L"Connecting to server...");
			} else if (Msg.lParam == THREAD_STATUS_WAITING) {
				SendMessage(vControls[AREA_RESPONSE], WM_SETTEXT, NULL, (LPARAM)L"Waiting for server response...");
			} else if (Msg.lParam == THREAD_STATUS_RECEIVING_RESPONSE) {
				SendMessage(vControls[AREA_RESPONSE], WM_SETTEXT, NULL, (LPARAM)L"Receiving server response...");
			} else if (Msg.lParam == THREAD_STATUS_DONE && gThreadBool) {
				SendMessage(vControls[AREA_RESPONSE], WM_SETTEXT, NULL, (LPARAM)gThreadResponse.c_str());
				gThreadBool = false;
				gCanSend = true;
			};
		}
		//Send the request whenever ENTER is pressed, regardless of keyboard focus
		if (Msg.message == WM_KEYUP && Msg.wParam == VK_RETURN) {
			SendMessage(hwnd, WM_COMMAND, (WPARAM)IDC_SEND_BUTTON, NULL); //Emulate clicking the SEND button
		}
		//Shut the beeper up when pressing ENTER
		if (Msg.message == WM_KEYDOWN && Msg.wParam == VK_RETURN) {
			continue;
		}
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}
Пример #18
0
bool InitializeWindow(HINSTANCE hInstance, const RenderParams& renderParams, HWND* hwndOut)
{
	WNDCLASSEX wc;
	DEVMODE dmScreenSettings;
	int posX, posY;

	OutputDebugString("Initializing Window...\n");

	// Setup the windows class with default settings.
	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wc.lpfnWndProc = &WindowProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(nullptr, IDI_WINLOGO);
	wc.hIconSm = wc.hIcon;
	wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.lpszMenuName = nullptr;
	wc.lpszClassName = WINDOW_CLASS_NAME;
	wc.cbSize = sizeof(WNDCLASSEX);

	OutputDebugString("Registering Window Class...\n");

	// Register the window class.
	RegisterClassEx(&wc);

	int windowWidth = renderParams.Extent.Width;
	int windowHeight = renderParams.Extent.Height;

	// Setup the screen settings depending on whether it is running in full screen or in windowed mode.
	if (!renderParams.Windowed)
	{
		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
		dmScreenSettings.dmSize = sizeof(dmScreenSettings);
		dmScreenSettings.dmPelsWidth = (unsigned long)GetSystemMetrics(SM_CXSCREEN);
		dmScreenSettings.dmPelsHeight = (unsigned long)GetSystemMetrics(SM_CXSCREEN);
		dmScreenSettings.dmBitsPerPel = 32;
		dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

		// Change the display settings to full screen.
		ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);

		// Set the position of the window to the top left corner.
		posX = 0;
		posY = 0;
	}
	else
	{
		// Place the window in the middle of the screen.
		posX = (GetSystemMetrics(SM_CXSCREEN) - windowWidth) / 2;
		posY = (GetSystemMetrics(SM_CYSCREEN) - windowHeight) / 2;

		RECT r = { 0, 0, windowWidth, windowHeight };
		AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);

		windowWidth = r.right - r.left;
		windowHeight = r.bottom - r.top;
	}

	DWORD windowStyle = 0;
	if (!renderParams.Windowed)
		windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP;
	else
		windowStyle = WS_OVERLAPPEDWINDOW;

	OutputDebugString("Creating Window...\n");

	// Create the window with the screen settings and get the handle to it.
	*hwndOut = CreateWindowEx(WS_EX_APPWINDOW, WINDOW_CLASS_NAME, APPLICATION_NAME,
		windowStyle,
		posX, posY, windowWidth, windowHeight, nullptr, nullptr, hInstance, nullptr);
	ShowWindow(*hwndOut, SW_HIDE);

	if (hwndOut == nullptr)
		return false;

	return true;
}
Пример #19
0
LRESULT CALLBACK IORegView_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	CIORegView* wnd = (CIORegView*)GetWindowLongPtr(hWnd, DWLP_USER);
	if ((wnd == NULL) && (uMsg != WM_CREATE))
		return DefWindowProc(hWnd, uMsg, wParam, lParam);

	switch (uMsg)
	{
	case WM_CREATE:
		{
			RECT rc;
			SIZE fontsize;

			// Retrieve the CIORegView instance passed upon window creation
			// and match it to the window
			wnd = (CIORegView*)((CREATESTRUCT*)lParam)->lpCreateParams;
			SetWindowLongPtr(hWnd, DWLP_USER, (LONG)wnd);

			// Create the fixed-pitch font
			wnd->hFont = CreateFont(16, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 
				OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, GetFontQuality(), FIXED_PITCH, "Courier New");

			// Create the vertical scrollbar
			// The sizing and positioning of the scrollbar is done in WM_SIZE messages
			wnd->vsbWidth = GetSystemMetrics(SM_CXVSCROLL);
			wnd->hScrollbar = CreateWindow("Scrollbar", "",
				WS_CHILD | WS_VISIBLE | WS_DISABLED | SBS_VERT,
				0, 0, 0, 0, hWnd, NULL, hAppInst, NULL);

			// Create the rebar that will hold all the controls
			wnd->hRebar = CreateWindowEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL, 
				WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CCS_NODIVIDER | RBS_VARHEIGHT | RBS_BANDBORDERS, 
				0, 0, 0, 0, hWnd, NULL, hAppInst, NULL);

			// Create the CPU combobox and fill it
			wnd->hCPUCombo = CreateWindow("ComboBox", "",
				WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST, 
				0, 0, 0, 50, wnd->hRebar, (HMENU)IDC_CPU, hAppInst, NULL);

			SendMessage(wnd->hCPUCombo, WM_SETFONT, (WPARAM)wnd->hFont, TRUE);
			SendMessage(wnd->hCPUCombo, CB_ADDSTRING, 0, (LPARAM)"ARM9");
			SendMessage(wnd->hCPUCombo, CB_ADDSTRING, 0, (LPARAM)"ARM7");
			SendMessage(wnd->hCPUCombo, CB_SETCURSEL, 0, 0);

			// Create the reg combobox and fill it
			wnd->hRegCombo = CreateWindow("ComboBox", "",
				WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST, 
				0, 0, 0, 400, wnd->hRebar, (HMENU)IDC_IOREG, hAppInst, NULL);

			SendMessage(wnd->hRegCombo, WM_SETFONT, (WPARAM)wnd->hFont, TRUE);
			SendMessage(wnd->hRegCombo, CB_SETDROPPEDWIDTH, 300, 0);
			wnd->ChangeCPU(ARMCPU_ARM9);
			SendMessage(wnd->hRegCombo, CB_SETCURSEL, 0, 0);

			// Add all those nice controls to the rebar
			REBARBANDINFO rbBand = { 80 };

			rbBand.fMask = RBBIM_STYLE | RBBIM_TEXT | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE;
			rbBand.fStyle = RBBS_CHILDEDGE | RBBS_NOGRIPPER;

			GetWindowRect(wnd->hCPUCombo, &rc);
			rbBand.lpText = "CPU: ";
			rbBand.hwndChild = wnd->hCPUCombo;
			rbBand.cxMinChild = 0;
			rbBand.cyMinChild = rc.bottom - rc.top;
			rbBand.cx = 100;
			SendMessage(wnd->hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);

			GetWindowRect(wnd->hRegCombo, &rc);
			rbBand.lpText = "Registers: ";
			rbBand.hwndChild = wnd->hRegCombo;
			rbBand.cxMinChild = 0;
			rbBand.cyMinChild = rc.bottom - rc.top;
			rbBand.cx = 0;
			SendMessage(wnd->hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);

			GetWindowRect(wnd->hRebar, &rc);
			wnd->rebarHeight = rc.bottom - rc.top;

			GetFontSize(hWnd, wnd->hFont, &fontsize);
			wnd->lineheight = kYMargin + fontsize.cy + kYMargin + 1;
		}
		return 0;

	case WM_CLOSE:
		CloseToolWindow(wnd);
		return 0;

	case WM_SIZE:
		{
			RECT rc;

			// Resize and reposition the controls
			SetWindowPos(wnd->hRebar, NULL, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, SWP_NOZORDER | SWP_NOMOVE);

			GetClientRect(hWnd, &rc);
			SetWindowPos(wnd->hScrollbar, NULL, rc.right-wnd->vsbWidth, wnd->rebarHeight, wnd->vsbWidth, rc.bottom-wnd->rebarHeight, SWP_NOZORDER);

			// Keep the first rebar band width to a reasonable value
			SendMessage(wnd->hRebar, RB_SETBANDWIDTH, 0, 100);

			GetClientRect(hWnd, &rc);
			wnd->maxlines = (rc.bottom - wnd->rebarHeight) / wnd->lineheight;

			wnd->UpdateScrollbar();
			wnd->Refresh();
		}
		return 0;

	case WM_PAINT:
		IORegView_Paint(wnd, hWnd, wParam, lParam);
		return 0;

	case WM_VSCROLL:
		{
			int pos = SendMessage(wnd->hScrollbar, SBM_GETPOS, 0, 0);
			int minpos, maxpos;

			SendMessage(wnd->hScrollbar, SBM_GETRANGE, (WPARAM)&minpos, (LPARAM)&maxpos);

			switch(LOWORD(wParam))
			{
			case SB_LINEUP:
				pos = max(minpos, pos - 1);
				break;
			case SB_LINEDOWN:
				pos = min(maxpos, pos + 1);
				break;
			case SB_PAGEUP:
				pos = max(minpos, pos - wnd->lineheight);
				break;
			case SB_PAGEDOWN:
				pos = min(maxpos, pos + wnd->lineheight);
				break;
			case SB_THUMBTRACK:
			case SB_THUMBPOSITION:
				{
					SCROLLINFO si;
					
					ZeroMemory(&si, sizeof(si));
					si.cbSize = sizeof(si);
					si.fMask = SIF_TRACKPOS;

					SendMessage(wnd->hScrollbar, SBM_GETSCROLLINFO, 0, (LPARAM)&si);
					pos = si.nTrackPos;
				}
				break;
			}

			SendMessage(wnd->hScrollbar, SBM_SETPOS, pos, TRUE);
			wnd->yoff = -pos;
			wnd->Refresh();
		}
		return 0;

	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDC_CPU:
			switch (HIWORD(wParam))
			{
			case CBN_SELCHANGE:
			case CBN_CLOSEUP:
				{
					int cpu = SendMessage(wnd->hCPUCombo, CB_GETCURSEL, 0, 0);
					if (cpu != wnd->CPU) 
					{
						wnd->ChangeCPU(cpu);
						wnd->Refresh();
					}
				}
				break;
			}
			break;

		case IDC_IOREG:
			switch (HIWORD(wParam))
			{
			case CBN_SELCHANGE:
			case CBN_CLOSEUP:
				{
					int reg = SendMessage(wnd->hRegCombo, CB_GETCURSEL, 0, 0);
					if (reg != wnd->Reg) 
					{
						wnd->ChangeReg(reg);
						wnd->Refresh();
					}
				}
				break;
			}
			break;
		}
		return 0;
	}

	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
Пример #20
0
/*****************************************************************************
 * Win32VoutCreateWindow: create a window for the video.
 *****************************************************************************
 * Before creating a direct draw surface, we need to create a window in which
 * the video will be displayed. This window will also allow us to capture the
 * events.
 *****************************************************************************/
static int Win32VoutCreateWindow( event_thread_t *p_event )
{
    vout_display_t *vd = p_event->vd;
    HINSTANCE  hInstance;
    HMENU      hMenu;
    RECT       rect_window;
    WNDCLASS   wc;                            /* window class components */
    TCHAR      vlc_path[MAX_PATH+1];
    int        i_style, i_stylex;

    msg_Dbg( vd, "Win32VoutCreateWindow" );

    /* Get this module's instance */
    hInstance = GetModuleHandle(NULL);

    #ifdef MODULE_NAME_IS_direct3d
    if( !p_event->use_desktop )
    {
    #endif
        /* If an external window was specified, we'll draw in it. */
        p_event->parent_window = vout_display_NewWindow(vd, &p_event->wnd_cfg );
        if( p_event->parent_window )
            p_event->hparent = (HWND) p_event->parent_window->handle.hwnd;			// sunqueen modify
        else
            p_event->hparent = NULL;
    #ifdef MODULE_NAME_IS_direct3d
    }
    else
    {
        p_event->parent_window = NULL;
        p_event->hparent = GetDesktopHandle(vd);
    }
    #endif
    p_event->cursor_arrow = LoadCursor(NULL, IDC_ARROW);
    p_event->cursor_empty = EmptyCursor(hInstance);

    /* Get the Icon from the main app */
    p_event->vlc_icon = NULL;
    if( GetModuleFileName( NULL, vlc_path, MAX_PATH ) )
    {
        p_event->vlc_icon = ExtractIcon( hInstance, vlc_path, 0 );
    }

    /* Fill in the window class structure */
    wc.style         = CS_OWNDC|CS_DBLCLKS;          /* style: dbl click */
    wc.lpfnWndProc   = (WNDPROC)WinVoutEventProc;       /* event handler */
    wc.cbClsExtra    = 0;                         /* no extra class data */
    wc.cbWndExtra    = 0;                        /* no extra window data */
    wc.hInstance     = hInstance;                            /* instance */
    wc.hIcon         = p_event->vlc_icon;       /* load the vlc big icon */
    wc.hCursor       = p_event->is_cursor_hidden ? p_event->cursor_empty :
                                                   p_event->cursor_arrow;
    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);  /* background color */			// sunqueen modify
    wc.lpszMenuName  = NULL;                                  /* no menu */
    wc.lpszClassName = p_event->class_main;       /* use a special class */

    /* Register the window class */
    if( !RegisterClass(&wc) )
    {
        if( p_event->vlc_icon )
            DestroyIcon( p_event->vlc_icon );

        msg_Err( vd, "Win32VoutCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
        return VLC_EGENERIC;
    }

    /* Register the video sub-window class */
    wc.lpszClassName = p_event->class_video;
    wc.hIcon = 0;
    wc.hbrBackground = NULL; /* no background color */
    if( !RegisterClass(&wc) )
    {
        msg_Err( vd, "Win32VoutCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
        return VLC_EGENERIC;
    }

    /* When you create a window you give the dimensions you wish it to
     * have. Unfortunatly these dimensions will include the borders and
     * titlebar. We use the following function to find out the size of
     * the window corresponding to the useable surface we want */
    rect_window.left   = 10;
    rect_window.top    = 10;
    rect_window.right  = rect_window.left + p_event->wnd_cfg.width;
    rect_window.bottom = rect_window.top  + p_event->wnd_cfg.height;

    if( var_GetBool( vd, "video-deco" ) )
    {
        /* Open with window decoration */
        AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );
        i_style = WS_OVERLAPPEDWINDOW|WS_SIZEBOX|WS_VISIBLE|WS_CLIPCHILDREN;
        i_stylex = 0;
    }
    else
    {
        /* No window decoration */
        AdjustWindowRect( &rect_window, WS_POPUP, 0 );
        i_style = WS_POPUP|WS_VISIBLE|WS_CLIPCHILDREN;
        i_stylex = 0; // WS_EX_TOOLWINDOW; Is TOOLWINDOW really needed ?
                      // It messes up the fullscreen window.
    }

    if( p_event->hparent )
    {
        i_style = WS_VISIBLE|WS_CLIPCHILDREN|WS_CHILD;
        i_stylex = 0;

        /* allow user to regain control over input events if requested */
        bool b_mouse_support = var_InheritBool( vd, "mouse-events" );
        bool b_key_support = var_InheritBool( vd, "keyboard-events" );
        if( !b_mouse_support && !b_key_support )
            i_style |= WS_DISABLED;
    }

    p_event->i_window_style = i_style;

    /* Create the window */
    p_event->hwnd =
        CreateWindowEx( WS_EX_NOPARENTNOTIFY | i_stylex,
                    p_event->class_main,             /* name of window class */
                    _T(VOUT_TITLE) _T(" (VLC Video Output)"),  /* window title */
                    i_style,                                 /* window style */
                    (!p_event->wnd_cfg.x) ? (UINT)CW_USEDEFAULT :
                        (UINT)p_event->wnd_cfg.x,   /* default X coordinate */
                    (!p_event->wnd_cfg.y) ? (UINT)CW_USEDEFAULT :
                        (UINT)p_event->wnd_cfg.y,   /* default Y coordinate */
                    rect_window.right - rect_window.left,    /* window width */
                    rect_window.bottom - rect_window.top,   /* window height */
                    p_event->hparent,                       /* parent window */
                    NULL,                          /* no menu in this window */
                    hInstance,            /* handle of this program instance */
                    (LPVOID)p_event );           /* send vd to WM_CREATE */

    if( !p_event->hwnd )
    {
        msg_Warn( vd, "Win32VoutCreateWindow create window FAILED (err=%lu)", GetLastError() );
        return VLC_EGENERIC;
    }

    InitGestures( p_event->hwnd, &p_event->p_gesture );

    if( p_event->hparent )
    {
        LONG i_style;

        /* We don't want the window owner to overwrite our client area */
        i_style = GetWindowLong( p_event->hparent, GWL_STYLE );

        if( !(i_style & WS_CLIPCHILDREN) )
            /* Hmmm, apparently this is a blocking call... */
            SetWindowLong( p_event->hparent, GWL_STYLE,
                           i_style | WS_CLIPCHILDREN );

        /* Create our fullscreen window */
        p_event->hfswnd =
            CreateWindowEx( WS_EX_APPWINDOW, p_event->class_main,
                            _T(VOUT_TITLE) _T(" (VLC Fullscreen Video Output)"),
                            WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_SIZEBOX,
                            CW_USEDEFAULT, CW_USEDEFAULT,
                            CW_USEDEFAULT, CW_USEDEFAULT,
                            NULL, NULL, hInstance, NULL );
    }
    else
    {
        p_event->hfswnd = NULL;
    }

    /* Append a "Always On Top" entry in the system menu */
    hMenu = GetSystemMenu( p_event->hwnd, FALSE );
    AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
    AppendMenu( hMenu, MF_STRING | MF_UNCHECKED,
                       IDM_TOGGLE_ON_TOP, _T("Always on &Top") );

    /* Create video sub-window. This sub window will always exactly match
     * the size of the video, which allows us to use crazy overlay colorkeys
     * without having them shown outside of the video area. */
    /* FIXME vd->source.i_width/i_height seems wrong */
    p_event->hvideownd =
    CreateWindow( p_event->class_video, _T(""),   /* window class */
        WS_CHILD,                   /* window style, not visible initially */
        0, 0,
        vd->source.i_width,          /* default width */
        vd->source.i_height,        /* default height */
        p_event->hwnd,               /* parent window */
        NULL, hInstance,
        (LPVOID)p_event );    /* send vd to WM_CREATE */

    if( !p_event->hvideownd )
        msg_Warn( vd, "can't create video sub-window" );
    else
        msg_Dbg( vd, "created video sub-window" );

    /* Now display the window */
    ShowWindow( p_event->hwnd, SW_SHOW );

    return VLC_SUCCESS;
}
Пример #21
0
HWND CreateButton(TCHAR *Titel, int x0, int y0, int w, int h, int ID, HWND hW, HINSTANCE hInst)
{
	return CreateWindowEx(WS_EX_PALETTEWINDOW, L"BUTTON", Titel,
		WS_VISIBLE | WS_CHILD,
		x0, y0, w, h, hW, (HMENU)ID, hInst, NULL);
}
Пример #22
0
INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR szCmdLine, int iCmdShow)
{
    WNDCLASSEX winClass ;

    winClass.lpszClassName = "MaterialOnly";
    winClass.cbSize        = sizeof(WNDCLASSEX);
    winClass.style         = CS_HREDRAW | CS_VREDRAW;
    winClass.lpfnWndProc   = MsgProc;
    winClass.hInstance     = hInstance;
    winClass.hIcon	       = NULL ;
    winClass.hIconSm	   = NULL ;
    winClass.hCursor       = LoadCursor(NULL, IDC_ARROW) ;
    winClass.hbrBackground = NULL ;
    winClass.lpszMenuName  = NULL ;
    winClass.cbClsExtra    = 0;
    winClass.cbWndExtra    = 0;

    RegisterClassEx (&winClass) ;

    HWND hWnd = CreateWindowEx(NULL,
                               winClass.lpszClassName,		// window class name
                               "MaterialOnly",			// window caption
                               WS_OVERLAPPEDWINDOW, 		// window style
                               32,							// initial x position
                               32,							// initial y position
                               600,						// initial window width
                               600,						// initial window height
                               NULL,						// parent window handle
                               NULL,						// window menu handle
                               hInstance,					// program instance handle
                               NULL) ;						// creation parameters

    // Create window failed
    if(hWnd == NULL)
    {
        MessageBoxA(hWnd, "Create Window failed!", "Error", 0) ;
        return -1 ;
    }

    // Initialize Direct3D
    if( SUCCEEDED(InitD3D(hWnd)))
    {
        // Show the window
        ShowWindow( hWnd, SW_SHOWDEFAULT );
        UpdateWindow( hWnd );

        MSG msg ;
        ZeroMemory( &msg, sizeof(msg) );
        PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );

        // Get last time
        static DWORD lastTime = timeGetTime();

        while (msg.message != WM_QUIT)
        {
            if(PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) != 0)
            {
                TranslateMessage (&msg) ;
                DispatchMessage (&msg) ;
            }
            else // Render the game if there is no message to process
            {
                // Get current time
                DWORD currTime  = timeGetTime();

                // Calculate time elapsed
                float timeDelta = (currTime - lastTime) * 0.001f;

                // Render
                Render(timeDelta) ;

                // Update last time to current time for next loop
                lastTime = currTime;
            }
        }
    }

    UnregisterClass(winClass.lpszClassName, hInstance) ;
    return 0;
}
Пример #23
0
int WINAPI WinMain(	HINSTANCE hinstance,
					HINSTANCE hprevinstance,
					LPSTR lpcmdline,
					int ncmdshow)
{

WNDCLASSEX winclass; // this will hold the class we create
HWND	   hwnd;	 // generic window handle
MSG		   msg;		 // generic message
HDC        hdc;      // graphics device context

// first fill in the window class stucture
winclass.cbSize         = sizeof(WNDCLASSEX);
winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                          CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc	= WindowProc;
winclass.cbClsExtra		= 0;
winclass.cbWndExtra		= 0;
winclass.hInstance		= hinstance;
winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor		= LoadCursor(NULL, IDC_ARROW); 
winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName	= NULL;
winclass.lpszClassName	= WINDOW_CLASS_NAME;
winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

// save hinstance in global
hinstance_app = hinstance;

// register the window class
if (!RegisterClassEx(&winclass))
	return(0);

// create the window
if (!(hwnd = CreateWindowEx(NULL,                  // extended style
                            WINDOW_CLASS_NAME,     // class
						    "DirectDraw 8-Bit Blitting Demo", // title
						    WS_POPUP | WS_VISIBLE,
					 	    0,0,	  // initial x,y
						    SCREEN_WIDTH,SCREEN_HEIGHT,  // initial width, height
						    NULL,	  // handle to parent 
						    NULL,	  // handle to menu
						    hinstance,// instance of this application
						    NULL)))	// extra creation parms
return(0);

// save main window handle
main_window_handle = hwnd;

// initialize game here
Game_Init();

// enter main event loop
while(TRUE)
	{
    // test if there is a message in queue, if so get it
	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
	   { 
	   // test if this is a quit
       if (msg.message == WM_QUIT)
           break;
	
	   // translate any accelerator keys
	   TranslateMessage(&msg);

	   // send the message to the window proc
	   DispatchMessage(&msg);
	   } // end if
    
       // main game processing goes here
       Game_Main();
       
	} // end while

// closedown game here
Game_Shutdown();

// return to Windows like this
return(msg.wParam);

} // end WinMain
Пример #24
0
void ChangeInfoData::BeginListEdit(int iItem, RECT *rc, int iSetting, WORD wVKey)
{
  int j,n;
  POINT pt;
  int itemHeight;
  char str[MAX_PATH];

  if (dataListEdit)
    dataListEdit->EndListEdit(0);

  pt.x=pt.y=0;
  ClientToScreen(hwndList,&pt);
  OffsetRect(rc,pt.x,pt.y);
  InflateRect(rc,-2,-2);
  rc->left-=2;
  iEditItem = iItem;
  ListView_RedrawItems(hwndList, iEditItem, iEditItem);
  UpdateWindow(hwndList);

  dataListEdit = this;
  hwndListEdit = CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TOPMOST, _T("LISTBOX"), _T(""), WS_POPUP|WS_BORDER|WS_VSCROLL, rc->left, rc->bottom, rc->right - rc->left, 150, NULL, NULL, hInst, NULL);
  SendMessage(hwndListEdit, WM_SETFONT, (WPARAM)hListFont, 0);
  itemHeight = SendMessage(hwndListEdit, LB_GETITEMHEIGHT, 0, 0);

  FieldNamesItem *list = (FieldNamesItem*)setting[iSetting].pList;

  if (list == countryField)
  { // some country codes were changed leaving old details uknown, convert it for the user
    if (settingData[iSetting].value == 420) settingData[iSetting].value = 42; // conversion of obsolete codes (OMG!)
    else if (settingData[iSetting].value == 421) settingData[iSetting].value = 4201;
    else if (settingData[iSetting].value == 102) settingData[iSetting].value = 1201;
  }

  n = ListBoxAddStringUtf(hwndListEdit, "Unspecified");
  for (j=0; ; j++)
    if (!list[j].text)
    {
      SendMessage(hwndListEdit, LB_SETITEMDATA, n, j);
      if ((settingData[iSetting].value == 0 && list[j].code == 0)
       || (setting[iSetting].dbType != DBVT_ASCIIZ && settingData[iSetting].value == list[j].code))
        SendMessage(hwndListEdit, LB_SETCURSEL, n, 0);
      break;
    }

  for (j=0; list[j].text; j++) 
  {
    n = ListBoxAddStringUtf(hwndListEdit, list[j].text);
    SendMessage(hwndListEdit, LB_SETITEMDATA, n, j);
    if ((setting[iSetting].dbType == DBVT_ASCIIZ && (!strcmpnull((char*)settingData[iSetting].value, list[j].text))
     || (setting[iSetting].dbType == DBVT_ASCIIZ && (!strcmpnull((char*)settingData[iSetting].value, ICQTranslateUtfStatic(list[j].text, str, MAX_PATH))))
     || ((char*)settingData[iSetting].value == NULL && list[j].code == 0))
     || (setting[iSetting].dbType != DBVT_ASCIIZ && settingData[iSetting].value == list[j].code))
      SendMessage(hwndListEdit, LB_SETCURSEL, n, 0);
  }
  SendMessage(hwndListEdit, LB_SETTOPINDEX, SendMessage(hwndListEdit, LB_GETCURSEL, 0, 0) - 3, 0);
  int listCount = SendMessage(hwndListEdit, LB_GETCOUNT, 0, 0);
  if (itemHeight * listCount < 150)
    SetWindowPos(hwndListEdit, 0, 0, 0, rc->right - rc->left, itemHeight * listCount + GetSystemMetrics(SM_CYBORDER) * 2, SWP_NOZORDER|SWP_NOMOVE);
  OldListEditProc = (WNDPROC)SetWindowLongPtr(hwndListEdit, GWLP_WNDPROC, (LONG_PTR)ListEditSubclassProc);
  if (MyAnimateWindow = (BOOL (WINAPI*)(HWND,DWORD,DWORD))GetProcAddress(GetModuleHandleA("user32"), "AnimateWindow")) 
  {
    BOOL enabled;

    SystemParametersInfo(SPI_GETCOMBOBOXANIMATION, 0, &enabled, FALSE);
    if (enabled) MyAnimateWindow(hwndListEdit, 200, AW_SLIDE|AW_ACTIVATE|AW_VER_POSITIVE);
  }
  ShowWindow(hwndListEdit, SW_SHOW);
  SetFocus(hwndListEdit);
  if (wVKey)
    PostMessage(hwndListEdit, WM_KEYDOWN, wVKey, 0);
}
Пример #25
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) {
    PAINTSTRUCT Ps;
	switch(msg) {
    case WM_CREATE: {

		    /**
		    * Create AddFood Button
            */
            HFONT hFont = CreateFont(30,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
                CLIP_DEFAULT_PRECIS,NULL, VARIABLE_PITCH,TEXT("Impact"));

            HWND hButtonAddFood = CreateWindowEx(NULL,
                "BUTTON",
                "ADD FOOD",
                WS_TABSTOP|WS_VISIBLE|
                WS_CHILD|BS_DEFPUSHBUTTON|BS_TOP,
                10,
                150,
                100,
                25,
                hWnd,
                (HMENU)BUTTON_ADD_FOOD,
                GetModuleHandle(NULL),
                NULL);

            /**
            * Create button ShowFoodNumber
            */
            HWND hShowFoodNumber = CreateWindowEx(NULL,
                "BUTTON",
                "Funny",
                WS_TABSTOP|WS_VISIBLE|
                WS_CHILD|BS_DEFPUSHBUTTON|BS_TOP,
                10,
                180,
                300,
                40,
                hWnd,
                (HMENU)BUTTON_DISPLAY_FOOD_NR,
                GetModuleHandle(NULL),
                NULL);
            SendMessage (hShowFoodNumber, WM_SETFONT, WPARAM (hFont), TRUE);

            /**
            * Draw Food List (In a input box)
            */


            hFoodList = CreateWindowEx(WS_EX_CLIENTEDGE,
                "EDIT",
                "",
                WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_READONLY|
                ES_MULTILINE,
                10,
                40,
                300,
                100,
                hWnd,
                (HMENU)INPUT_TEXT_SHOW_FOOD,
                GetModuleHandle(NULL),
                NULL);


            /**
            * Draw main Input food field
            */

            hInputFood = CreateWindowEx(
                (DWORD)NULL,
                TEXT("edit"),
                "",
                WS_VISIBLE | WS_CHILD | WS_BORDER,
                120,
                150,
                190,
                25,
                hWnd,
                (HMENU)INPUT_TEXT_ADD_FOOD,
                GetModuleHandle(NULL),
                NULL);
        }
        break;

		case WM_PAINT: {
            HDC hdc = BeginPaint(hWnd, &Ps);
            RECT rect;
            /**
            * Draw Text
            */

            // Second Text
            char foodNrMessage[256] = "Number : ";
            char nr[50];
            strcat(foodNrMessage, itoa(foodNumber, nr, 10));
            SetBkMode(hdc, TRANSPARENT);
            SetRect(&updateRect, 210, 10, 300, 30);
            DrawText( hdc, foodNrMessage, -1, &updateRect, DT_SINGLELINE | DT_NOCLIP  ) ;

            // First Text
            HFONT hFont = CreateFont(25,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
            CLIP_DEFAULT_PRECIS,NULL, VARIABLE_PITCH,TEXT("Impact"));
            SetRect(&rect, 10, 10, 50, 50);

            SelectObject(hdc, hFont);
            SetBkMode(hdc, OPAQUE);
            SetBkColor(hdc, RGB(0,255,255));
            SetTextColor(hdc, RGB(255,0,0));
            DrawText(hdc, TEXT(firstText), -1,&rect, DT_NOCLIP);

            EndPaint(hWnd, &Ps);
        }
        break;

        case WM_CTLCOLOREDIT: {
            HDC hdc = (HDC)wParam;
            HWND hwnd = (HWND)lParam;
            HBRUSH color;

            if (GetDlgCtrlID(hwnd) == INPUT_TEXT_ADD_FOOD) {
                color = CreateSolidBrush(RGB(225, 225, 225));
                SetTextColor(hdc, RGB(0, 0, 255));
                SetBkMode(hdc, TRANSPARENT);
                SetBkColor(hdc,(LONG)color);
            }
            return (LONG) color;
        }
        break;

		case WM_COMMAND: {
            switch(LOWORD(wParam)) {
                case BUTTON_ADD_FOOD: {

                    char buffer[256];
                    SendMessage(hInputFood,
                        WM_GETTEXT,
                        sizeof(buffer)/sizeof(buffer[0]),
                        reinterpret_cast<LPARAM>(buffer));

                    if(strlen(buffer) > 0){
                        char newInput[255] = "";
                        char stat[30];
                        strcat(newInput, itoa((foodNumber+1), stat, 10) );
                        strcat(newInput, " ) ");
                        strcat(newInput, buffer);
                        strcat(newInput, "\r\n");

                        SendMessage(hFoodList, EM_REPLACESEL, FALSE, (LPARAM)newInput);
                        SendMessage(hInputFood, WM_SETTEXT, NULL, (LPARAM)"");
                        foodNumber++;
                        InvalidateRect(hWnd, &updateRect, TRUE);
                    }

                }
                break;

                case BUTTON_DISPLAY_FOOD_NR: {
                    char buffer[255] = "";

                    switch(foodNumber){
                    case 0:http://pastebin.com/62fGU90U
                    case 1:
                    case 2:
                    case 3:
                        strcat(buffer, "You are not hungry at all");
                        break;
                    case 4:
                    case 5:
                    case 6:
                        strcat(buffer, "I see you are hungry now");
                        break;
                    default:
                        strcat(buffer, "You are starvin... go get something to eat");
                        break;
                    }
                    MessageBox(NULL,
                        buffer,
                        "Funny",
                        MB_ICONINFORMATION);
                }
                break;
            }
        }
        break;

        case WM_SIZE: {
            INT nWidth = LOWORD(lParam);
            HWND hFunnyButton = GetDlgItem(hWnd, BUTTON_DISPLAY_FOOD_NR);

            MoveWindow(hFunnyButton, 10, 180, nWidth - 17, 40, TRUE);

            HWND hShowFoodInput = GetDlgItem(hWnd, INPUT_TEXT_SHOW_FOOD);
            HWND hAddFood = GetDlgItem(hWnd, INPUT_TEXT_ADD_FOOD);

            MoveWindow(hShowFoodInput, 10, 40, nWidth - 18, 100, TRUE);
            MoveWindow(hAddFood, 120, 150, nWidth - 128, 25, TRUE);
        }
        break;

        case WM_GETMINMAXINFO: {
            MINMAXINFO * mmiStruct;
			mmiStruct = (MINMAXINFO*)lParam;

			POINT ptPoint;

			ptPoint.x = 335;    //Minimum width of the window.
			ptPoint.y = 260;    //Minimum height of the window.
			mmiStruct->ptMinTrackSize = ptPoint;

			ptPoint.x = GetSystemMetrics(SM_CXMAXIMIZED);   //Maximum width of the window.
			ptPoint.y = GetSystemMetrics(SM_CYMAXIMIZED);   //Maximum height of the window.
			mmiStruct->ptMaxTrackSize = ptPoint;
        }
        break;

		case WM_DESTROY: {
			PostQuitMessage(0);
			return 0;
		}
		break;
	}

	return DefWindowProc(hWnd,msg,wParam,lParam);
}
Пример #26
0
static qboolean GLW_CreateWindow( const char *drivername, int width, int height, int colorbits, qboolean cdsFullscreen ) {
	RECT r;
	cvar_t          *vid_xpos, *vid_ypos;
	int stylebits;
	int x, y, w, h;
	int exstyle;

	//
	// register the window class if necessary
	//
	if ( !s_classRegistered ) {
		WNDCLASS wc;

		memset( &wc, 0, sizeof( wc ) );

		wc.style         = 0;
		wc.lpfnWndProc   = (WNDPROC) glw_state.wndproc;
		wc.cbClsExtra    = 0;
		wc.cbWndExtra    = 0;
		wc.hInstance     = g_wv.hInstance;
		wc.hIcon         = LoadIcon( g_wv.hInstance, MAKEINTRESOURCE( IDI_ICON1 ) );
		wc.hCursor       = LoadCursor( NULL,IDC_ARROW );
		wc.hbrBackground = (void *)COLOR_GRAYTEXT;
		wc.lpszMenuName  = 0;
		wc.lpszClassName = WINDOW_CLASS_NAME;

		if ( !RegisterClass( &wc ) ) {
			ri.Error( ERR_VID_FATAL, "GLW_CreateWindow: could not register window class" );
		}
		s_classRegistered = qtrue;
		ri.Printf( PRINT_ALL, "...registered window class\n" );
	}

	//
	// create the HWND if one does not already exist
	//
	if ( !g_wv.hWnd ) {
		//
		// compute width and height
		//
		r.left = 0;
		r.top = 0;
		r.right  = width;
		r.bottom = height;

		if ( cdsFullscreen || !Q_stricmp( _3DFX_DRIVER_NAME, drivername ) ) {
			exstyle = WS_EX_TOPMOST;
			stylebits = WS_POPUP | WS_VISIBLE | WS_SYSMENU;
		} else
		{
			exstyle = 0;
			stylebits = WINDOW_STYLE | WS_SYSMENU;
			AdjustWindowRect( &r, stylebits, FALSE );
		}

		w = r.right - r.left;
		h = r.bottom - r.top;

		if ( cdsFullscreen || !Q_stricmp( _3DFX_DRIVER_NAME, drivername ) ) {
			x = 0;
			y = 0;
		} else
		{
			vid_xpos = ri.Cvar_Get( "vid_xpos", "", 0 );
			vid_ypos = ri.Cvar_Get( "vid_ypos", "", 0 );
			x = vid_xpos->integer;
			y = vid_ypos->integer;

			// adjust window coordinates if necessary
			// so that the window is completely on screen
			if ( x < 0 ) {
				x = 0;
			}
			if ( y < 0 ) {
				y = 0;
			}

			if ( w < glw_state.desktopWidth &&
				 h < glw_state.desktopHeight ) {
				if ( x + w > glw_state.desktopWidth ) {
					x = ( glw_state.desktopWidth - w );
				}
				if ( y + h > glw_state.desktopHeight ) {
					y = ( glw_state.desktopHeight - h );
				}
			}
		}

		g_wv.hWnd = CreateWindowEx(
			exstyle,
			WINDOW_CLASS_NAME,
			//"Wolfenstein",
			"Enemy Territory - Omni-bot",
			stylebits,
			x, y, w, h,
			NULL,
			NULL,
			g_wv.hInstance,
			NULL );

		if ( !g_wv.hWnd ) {
			ri.Error( ERR_VID_FATAL, "GLW_CreateWindow() - Couldn't create window" );
		}

		ShowWindow( g_wv.hWnd, SW_SHOW );
		UpdateWindow( g_wv.hWnd );
		ri.Printf( PRINT_ALL, "...created window@%d,%d (%dx%d)\n", x, y, w, h );
	} else
	{
		ri.Printf( PRINT_ALL, "...window already present, CreateWindowEx skipped\n" );
	}

	if ( !GLW_InitDriver( drivername, colorbits ) ) {
		ShowWindow( g_wv.hWnd, SW_HIDE );
		DestroyWindow( g_wv.hWnd );
		g_wv.hWnd = NULL;

		return qfalse;
	}

	SetForegroundWindow( g_wv.hWnd );
	SetFocus( g_wv.hWnd );

	return qtrue;
}
Пример #27
0
//------------------------------------------------------------------------
int WINAPI WinMain(
	HINSTANCE	instance,
	HINSTANCE	previnst,
	LPSTR		cmdline,
	int			cmdshow)
{
MSG		msg;
DWORD	win_style;
int		win_width;
int		win_height;

	// Setup window stuff
	g_win_instance = instance;
	strcpy(g_win_class_name, "DreamGL_cls");

	memset(&g_win_class, 0, sizeof(g_win_class));
	g_win_class.cbSize        = sizeof(WNDCLASSEX);
	g_win_class.lpfnWndProc   = MainWindowProc;
	g_win_class.style         = CS_HREDRAW | CS_VREDRAW;//CS_CLASSDC;
	g_win_class.cbClsExtra    = 0;
	g_win_class.cbWndExtra    = 0;
	g_win_class.hInstance     = g_win_instance;
	g_win_class.hIcon         = LoadIcon(g_win_instance, MAKEINTRESOURCE(IDI_APPLICATION));
	g_win_class.hIconSm       = g_win_class.hIcon;
	g_win_class.hCursor       = LoadCursor(NULL, IDC_ARROW);
	g_win_class.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	g_win_class.lpszClassName = g_win_class_name;
	g_win_class.lpszMenuName  = NULL;

	g_win_atom = RegisterClassEx(&g_win_class);
	if(INVALID_ATOM == g_win_atom)
	{
		MessageBox(0, "Invalid ATOM returned by RegisterClassEx()!", "ERROR!", MB_OK);
		return(0);
	}

	win_style = WS_OVERLAPPEDWINDOW;
	if(g_full_screen) win_style = WS_POPUP;

	// In windowed mode, account for window border and caption bar.
	win_width  = g_screen_width;
	win_height = g_screen_height;
	if(!g_full_screen)
	{
		win_width  += (GetSystemMetrics(SM_CXFRAME)*2);
		win_height += (GetSystemMetrics(SM_CYFRAME)*2)+GetSystemMetrics(SM_CYCAPTION);
	}

	g_win_h = CreateWindowEx(
		WS_EX_APPWINDOW,
		MAKEINTATOM(g_win_atom),
		"DreamGL Demo",
		win_style,
		0, 0, win_width, win_height,
		NULL, NULL, g_win_instance, NULL);

	if(!IsWindow(g_win_h))
	{
		MessageBox(0, "Invalid HWND returned by CreateWindowEx()!", "ERROR!", MB_OK);
		return(0);
	}

	ShowWindow(g_win_h, cmdshow);
	UpdateWindow(g_win_h);



	if(!init())
	{
		MessageBox(0, "Failed to initialize OpenGL!", "ERROR!", MB_OK);
		return(0);
	}
	demo_init();

	while(TRUE)
	{
		if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			if(WM_QUIT == msg.message)
			{
				break;
			}
			else
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else
		{
			demo_tick();
		}
	}

	demo_end();
	end();



	UnregisterClass(MAKEINTATOM(g_win_atom), instance);
	return(msg.wParam);
}
/* ********************************************************************************************************************
   *                          *                              *                     *                                  *
   *                          * IDC_STATIC_SCALE             *                     *                                  *
   *                          *                              *                     * IDC_STATIC_POPULANTS_GROUP_BOX   *
   *                          * IDC_STATIC_SLOPE_SCALE       *                     *      (popGrpBoxProp)             *
   *      bathyBitmapProp     *                              *                     *                                  *
   *                          *                              *                     ************************************
   *                          *   (scaleProp)                *                     |                                  *
   *                          *                              *         B           |                                  *
   *                          *                              *                     |                                  *
   *                          *                              *                     |                                  *
   ***********************************************************                     |                 C                *
   *                                                         |                     |                                  *
   *                                                         |                     |                                  *
   *                          A                              |                     |                                  *
   *                                                         |                     |                                  *
   *********************************************************************************************************************/
DLGLAYOUT SelectDialogLayout(HWND hDlg, WNDPROP PrevDlgProp, const BATHYMAPINF *pBathyMapInf, const HEIGHTWIDTH *pReqPixels, DLGLAYOUTOPTIONS *pLayoutOptions)
{
	//SEEDDLGSETUP sedg = GetSeedDlgSetup();
	static int scaleWidths = GetWinProps(GetDlgItem(hDlg,IDC_STATIC_SCALE)).width;
	static int minY = GetWinProps(GetDlgItem(hDlg,IDC_STATIC_SCALE)).y;
	int c, i;
	int dx, dy;
	const int CONTRLSPACEPIXELS = 7;
	//WNDPROP winProp;
	DLGLAYOUT dlgLayout;
	WNDPROP winProp;
	WNDPROP dlg = GetWinProps(hDlg);
	WNDPROP pop = GetWinProps(GetDlgItem(hDlg,IDC_STATIC_POPULANTS_GROUP_BOX));
	HEIGHTWIDTH bathyPixAvial[NUMCONFIGURATIONS] = {0}; // Pixels available for the bathymetry map
	HEIGHTWIDTH bathyDimResult[NUMCONFIGURATIONS] = {0}; //  Resulting dimensions of the bathymap
	HEIGHTWIDTH cntrlsPixAvail[NUMCONFIGURATIONS] = {0}; // Pixels available for the controls
	MAPGRPCONFIG m;
	ANIMATGRPCONFIG a;
	BUTTONGRPCONFIG b;


	// Get the current bathymetry bitmap properties.  Needed for its X Y values.
	if(g_hwndBathy == NULL)
	{
		_ASSERT(g_hwndDepthScale == NULL && g_hwndSlopeScale == NULL);

		// Bathymetry Map
		dlgLayout.bathy.x = DLGBOXLEFTSIDEMARGIN;
		dlgLayout.bathy.y = DLBBOXTOPMARGIN;
		dlgLayout.bathy.width = 0;
		dlgLayout.bathy.height = 0;

		// Widths for the scaling bitmaps is needed now.
		winProp = GetWinProps(GetDlgItem(hDlg,IDC_STATIC_SCALE));
		while((winProp.width % 16) != 0)
			winProp.width++;

		// Depth Scale
		dlgLayout.depth.x = 0;
		dlgLayout.depth.y = DLBBOXTOPMARGIN;
		dlgLayout.depth.width = winProp.width;
		dlgLayout.depth.height = winProp.height;


		dlgLayout.slope.x = 0;
		dlgLayout.slope.y = DLBBOXTOPMARGIN;
		dlgLayout.slope.width = winProp.width;
		dlgLayout.slope.height = winProp.height;

	}
	else
	{
//		_ASSERT(g_hwndDepthScale != NULL && g_hwndSlopeScale != NULL);

		dlgLayout.bathy = GetWinProps(g_hwndBathy);

		// Get the current depth and slope scale and window properties.  Needed for their
		// dimensions.
		dlgLayout.depth = GetWinProps(g_hwndDepthScale);
		dlgLayout.slope = GetWinProps(g_hwndSlopeScale);
	}


	// The first three layouts have a horizontal layout
	for(c=0; c<3; c++)
	{
		if(dlg.width < pReqPixels[c].width + pop.width)
			continue;

		// Calculate the pixels avalable for the bathymetry map
		bathyPixAvial[c].width = dlg.width - (pop.width +
									     dlgLayout.depth.width +
										 dlgLayout.slope.width +
										 3*CONTRLSPACEPIXELS +
										 DLGBOXLEFTSIDEMARGIN +
										 DLGBOXRIGHTSIDEMARGIN);
		bathyPixAvial[c].height = dlg.height - (pReqPixels[c].height +
										   DLBBOXTOPMARGIN);

		cntrlsPixAvail[c].width = dlg.width - (pop.width +
										  CONTRLSPACEPIXELS +
										  DLGBOXLEFTSIDEMARGIN +
										  DLGBOXRIGHTSIDEMARGIN);
		cntrlsPixAvail[c].height = dlg.height - (pop.width +
										    CONTRLSPACEPIXELS +
											DLBBOXTOPMARGIN);
	}

	// vertical layout
		// Calculate the pixels avalable for the bathymetry map
	bathyPixAvial[3].width =
		dlg.width - (
		DLGBOXRIGHTSIDEMARGIN + // margin on the dialog box's right side
		pop.width + // populants group box width
		CONTRLSPACEPIXELS + // pixels between the populants group box and this layout's setup	
		pReqPixels[3].width + // pixels required by the controls of this layout
		CONTRLSPACEPIXELS + // pixels between the this layout's setup and the depth bitmap slider
		dlgLayout.depth.width + // depth bitmap slider width
		CONTRLSPACEPIXELS + // pixels between the two sliders
		dlgLayout.slope.width + // slope bitmap slider width
		CONTRLSPACEPIXELS + // pixels between the slope slider and the bathymetry bitmap
		DLGBOXLEFTSIDEMARGIN); // margin on the left side of the dialog box.

	bathyPixAvial[3].height =
		dlg.height - (
		DLBBOXTOPMARGIN + // top of the dialog box margin
		7 + // space for the mouse move.
		//pReqPixels[3].height + // height of this layout
		DLBBOXTOPMARGIN);// bottom margin of the dialog box?



	cntrlsPixAvail[3].width = 
		dlg.width - (
		DLGBOXLEFTSIDEMARGIN + // left margin
		pop.width + // populants group box width
		CONTRLSPACEPIXELS + // space between the populants group box and depth slider
		dlgLayout.depth.width + // depth slider width
		CONTRLSPACEPIXELS + // space between depth slider and slope slider
		dlgLayout.slope.width + // slope slider width
		CONTRLSPACEPIXELS);// space between slope slider and bathymetry map.
	cntrlsPixAvail[3].height =
		dlg.height - (
		DLBBOXTOPMARGIN + // top margin
		0); // ? bottom margin???

	//----------------------------------------------------------------------------------//
	// Handle the dialog set up based on if the map runs horizontally (width being larger
	// than height or square) or vertically.
	//-------------------------------------//
	// Horizontal and square maps have all of the controls underneath (in the dialog box
	// design) remain their.  Vertical maps can have those controls repositioned when
	// possible to give the bitmap as much space as possible.
	if(pBathyMapInf->widthMeters >= pBathyMapInf->heightMeters /* Horizontal orientation or square*/)
	{
		// Cares about height available when determining width.  Grab the first the meets the
		// requirements starting with the widest (want the map as wide as possible)
		for(c=0; c<3; c++)
		{
			if(bathyPixAvial[c].width == 0)
				continue;

			bathyDimResult[c].width = bathyPixAvial[c].width-2; // -2 to be sure to save room for the border.
			while(bathyDimResult[c].width%16 != 0)
				bathyDimResult[c].width--;

			bathyDimResult[c].height =
				(int)((double)bathyDimResult[c].width * pBathyMapInf->heightMeters/pBathyMapInf->widthMeters);

			while(bathyDimResult[c].height > bathyPixAvial[c].height-2 || bathyDimResult[c].width%16 != 0)
			{
				while(--bathyDimResult[c].width%16 != 0)
					;
				bathyDimResult[c].height =
					(int)((double)(bathyDimResult[c].width * pBathyMapInf->heightMeters/pBathyMapInf->widthMeters));
			}
		}

		// Now determine which configuration allows for the maximum width
		c = 0;
		for(i=1; i<3; i++)
		{
			if(cntrlsPixAvail[c].width <= bathyDimResult[i].width)
				c = i;
		}

		_ASSERT(c >= 0 && c <=2);
	}
	else /* vertical orientation (height is greater than width)*/
	{
		c = 3;
		bathyDimResult[c].height = bathyPixAvial[c].height-2;
		bathyDimResult[c].width = (int)(bathyDimResult[c].height * pBathyMapInf->widthMeters/pBathyMapInf->heightMeters);
		while(bathyDimResult[c].width > bathyPixAvial[c].width || bathyDimResult[c].width%16 != 0)
		{
			while(--bathyDimResult[c].width%16 != 0)
				;
			_ASSERT(bathyDimResult[c].width%16 == 0);
			bathyDimResult[c].height = (int)(bathyDimResult[c].width * pBathyMapInf->heightMeters/pBathyMapInf->widthMeters);
		}
	}

	_ASSERT(c >= 0 && c <=3);

	// Get the configuration
	//layoutConfig = GetDlgLayoutConfig(

	//----------------------------------------------------------------------------------//
	// Set up the bathymetry map size on the dialog box.
	//-------------------------------------------------//
	dlgLayout.bathy.width = bathyDimResult[c].width;
	dlgLayout.bathy.height = bathyDimResult[c].height;
	_ASSERT(bathyDimResult[c].width%16 == 0);


	//----------------------------------------------------------------------------------//
	// Set the slope and depth scale locations and size on the dialog box.
	//--------------------------------------------------------------------//
	// The X locations are a function of the space the bathymetry bitmap take up plus
	// space inbetween
	dlgLayout.depth.x = dlgLayout.bathy.x + dlgLayout.bathy.width + CONTRLSPACEPIXELS;
	dlgLayout.depth.y = dlgLayout.bathy.y;
	dlgLayout.depth.height = dlgLayout.bathy.height;
#if 0
	if(g_hwndDepthScale == NULL)
	{
		// Depth scale
		g_hwndDepthScale = CreateWindowEx(
			0,	// dwExStyle: The extended window style of the window being created.
			SCALEBITMAPWINDOWCLASSNAME, // lpClassName: Pointer to a null-terminated string or a class atom
			"ScaleBitmap", // lpWindowName: Pointer to a null-terminated string that specifies the window name
			WS_CLIPCHILDREN | WS_BORDER | WS_VISIBLE | WS_CHILD, //dwStyle: Specifies the style of the window
			dlgLayout.depth.x, // x: Initial horizontal position of the window
			dlgLayout.depth.y, // y: Initial vertical position of the window
			dlgLayout.depth.width + 2, // The width of the window in device units.  +2 for the border box.
			dlgLayout.depth.height + 2, // The height of the window in device units.  +2 for the border box.
			g_hDlgSeed, // hWndParent: Handle to the parent or owner window of the window being created.
			(HMENU) NULL, //hMenu: Handle to a menu, or specifies a child-window identifier, depending on the window style. 
			NULL,//hInstance: Handle to the instance of the module to be associated with the window.
			(LPVOID)(pSeedInf)); // lpParam: Pointer to a value to be passed to the window through the CREATESTRUCT
								 //          structure (lpCreateParams member) pointed to by the lParam param of
								 //			 the WM_CREATE message
	}
	else
	{
		SetWindowPos(g_hwndDepthScale, HWND_TOP, dlgLayout.depth.x, dlgLayout.depth.y+2, dlgLayout.depth.width+2, dlgLayout.depth.height, SWP_SHOWWINDOW);
	}
#endif

	dlgLayout.slope.x = dlgLayout.depth.x + dlgLayout.depth.width + CONTRLSPACEPIXELS;
	dlgLayout.slope.y = dlgLayout.bathy.y;
	dlgLayout.slope.height = dlgLayout.bathy.height;

#if 0
	if(g_hwndSlopeScale == NULL)
	{
		g_hwndSlopeScale  = CreateWindowEx(
			0,	// dwExStyle: The extended window style of the window being created.
			SCALEBITMAPWINDOWCLASSNAME, // lpClassName: Pointer to a null-terminated string or a class atom
			"ScaleSlopeBitmap", // lpWindowName: Pointer to a null-terminated string that specifies the window name
			WS_CLIPCHILDREN | WS_BORDER | WS_VISIBLE | WS_CHILD, //dwStyle: Specifies the style of the window
			dlgLayout.slope.x, // x: Initial horizontal position of the window
			dlgLayout.slope.y, //layout.depth.y, // y: Initial vertical position of the window
			dlgLayout.slope.width + 2, // The width of the window in device units.  +2 for the border box.
			dlgLayout.slope.height + 2, // The height of the window in device units.  +2 for the border box.
			g_hDlgSeed, // hWndParent: Handle to the parent or owner window of the window being created.
			(HMENU) NULL, //hMenu: Handle to a menu, or specifies a child-window identifier, depending on the window style. 
			NULL,//hInstance: Handle to the instance of the module to be associated with the window.
			(LPVOID)(pSeedInf)); // lpParam: Pointer to a value to be passed to the window through the CREATESTRUCT
								 //          structure (lpCreateParams member) pointed to by the lParam param of
								 //			 the WM_CREATE message
	}
	else
	{
		SetWindowPos(g_hwndSlopeScale, HWND_TOP, dlgLayout.slope.x, dlgLayout.slope.y+2, dlgLayout.slope.width+2, dlgLayout.slope.height, SWP_SHOWWINDOW);
	}
#endif

#if 0
	if(g_hwndBathy == NULL)
	{
		// Bathymetry bitmap
		g_hwndBathy  = CreateWindowEx(
			0,
			BATHYBITMAPWINDOWCLASSNAME,"BathyBitmap",
			WS_CLIPCHILDREN | WS_BORDER | WS_VISIBLE | WS_CHILD,
			DLGBOXLEFTSIDEMARGIN, //layout.bathy.x,
			DLBBOXTOPMARGIN, //layout.bathy.y,
			dlgLayout.bathy.width+2, //layout.bathy.width+2, // The width of the window in device units.  +2 for the border box.
			dlgLayout.bathy.height+2, // The height of the window in device units.  +2 for the border box.
			g_hDlgSeed, // parent window.
			(HMENU) NULL,
			NULL,
			(LPVOID)(pSeedInf));
	}
	else
	{
		SetWindowPos(g_hwndBathy, HWND_TOP, NULL, NULL, dlgLayout.bathy.width+2, dlgLayout.bathy.height+2,
			SWP_NOMOVE|SWP_SHOWWINDOW);
	}
#endif
	//----------------------------------------------------------------------------------//
	// Get the change in the dialog box width and height.
	//--------------------------------------------------//
	// The change in width (dx) here tells how far to move the populants group box
	// controls to the left (negative) or right (positive)
	dx = dlg.width - PrevDlgProp.width;
	dy = dlg.height - PrevDlgProp.height;

	//----------------------------------------------------------------------------------//
	// Move the Populants Group Box controls.
	//---------------------------------------//
	MoveDlgControl(IDC_STATIC_POPULANTS_GROUP_BOX, hDlg, dx, 0);
	// Things under the IDC_STATIC_POPULANTS_GROUP_BOX control.
	MoveDlgControl(IDC_LOAD_SCENARIO, hDlg, dx, 0);
	MoveDlgControl(IDC_TRACKTOGGLE_BUTTON, hDlg, dx, 0);
	MoveDlgControl(IDC_VISUAL_INC_BUTTON, hDlg, dx, 0);
	MoveDlgControl(IDC_VISUAL_RESET_BUTTON, hDlg, dx, 0);
	MoveDlgControl(IDC_VISUAL_STOP_BUTTON, hDlg, dx, 0);
	MoveDlgControl(IDC_VISUAL_PLAY_BUTTON, hDlg, dx, 0);
	MoveDlgControl(IDC_VISUAL_DEC_BUTTON, hDlg, dx, 0);


	MoveDlgControl(IDC_STATIC_SPE_ACSRC, hDlg, dx, 0);
	MoveDlgControl(IDC_BUTTON_ENVDLG_FIRSANIMATACSTSRCE, hDlg, dx, 0);
	MoveDlgControl(IDC_BUTTON_ENVDLG_SPEC_ADD, hDlg, dx, 0);
	MoveDlgControl(IDC_BUTTON_ENVDLG_SPEC_REMOVE, hDlg, dx, 0);
	MoveDlgControl(IDC_LIST_SPECIES, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_INDIVIDUAL, hDlg, dx, 0);
	MoveDlgControl(IDC_BUTTON_ENVDLG_INDIVIDUAL_DELETE, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_PODS, hDlg, dx, 0);
	MoveDlgControl(IDC_BUTTON_ENVDLG_POD_DELETE, hDlg, dx, 0);
	MoveDlgControl(IDC_LIST_INDIVIDUAL, hDlg, dx, 0);
	MoveDlgControl(IDC_LIST_PODS, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_POP_LOCATION, hDlg, dx, 0);
	MoveDlgControl(IDC_BUTTON_ENVDLG_PODMEMBER_DELETE, hDlg, dx, 0);
	MoveDlgControl(IDC_LIST_SEL_POP, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_SEEDOPTNS_GRPBOX, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_SEED_INDIVIDUAL, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_ADD_POD, hDlg, dx, 0);
	MoveDlgControl(IDC_EDIT_ENVBITMAP_INIT_PODSIZE, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_ENVBITMAP_INITPODSIZE, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_LEADANIMATSETTING_GRPBOX, hDlg, dx, 0);
	MoveDlgControl(IDC_EDIT_ENVBITMAP_FOCAL_DIST, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_ENVBITMAP_FOCAL_DIST, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_PODLEADTYPE_ANIMAT, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_PODLEADTYPE_CENTROID, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_ADJUSTPODSIZE_GRPBOX, hDlg, dx, 0);
	MoveDlgControl(IDC_BUTTON_DEBUG_ADDPODMEMBER, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_SEEDING_METHOD, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_MOUSE_CLICKING, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_N_ANIMATS_AROUND_CLICK, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_BOUNDING_BOX, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_N_ANIMATS_OVERMAP, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_POLYGON, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_ANIMATS_BY_DENSITY, hDlg, dx, 0);
	MoveDlgControl(IDC_EDIT_DENSITY, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_DENSITY, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_DENSITYCALC, hDlg, dx, 0);
	MoveDlgControl(IDC_RADIO_LOAD_SHAPE_FILE, hDlg, dx, 0);
	MoveDlgControl(IDC_EDIT_NUM_ANIMATS, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_NUMANIMATS, hDlg, dx, 0);
	MoveDlgControl(IDC_EDIT_AVE_DIST, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_AVEDIST, hDlg, dx, 0);
	MoveDlgControl(IDC_EDIT_STD_DIST, hDlg, dx, 0);
	MoveDlgControl(IDC_STATIC_STDEVDIST, hDlg, dx, 0);
	MoveDlgControl(IDC_VISUAL_RUN_BUTTON, hDlg, dx, 0);
	MoveDlgControl(IDC_BUTTON_DENSITYDISTRIBUTE, hDlg, dx, 0);
	MoveDlgControl(IDC_BUTTON_PODSIZEINC, hDlg, dx, 0);
	MoveDlgControl(IDC_BUTTON_PODSIZEDEC, hDlg, dx, 0);

	//----------------------------------------------------------------------------------//
	// Move the Done Button
	//---------------------//
	MoveDlgControl(IDOK, hDlg, dx, dy);

	//----------------------------------------------------------------------------------//
	// Configure and move the Map Information group box controls
	//-----------------------------------------------------------//
	dy = dlgLayout.bathy.y + dlgLayout.bathy.height + CONTRLSPACEPIXELS;
	dx = DLGBOXLEFTSIDEMARGIN;
	SetDlgControlLocation(pLayoutOptions->config[c].mouseMoveLabel, GetDlgItem(hDlg, IDC_STATIC_MOUSE_POSITION), dx, dy);

	if(c == 3)
	{
		dy = dlgLayout.bathy.y;
		dx = dlgLayout.slope.x + dlgLayout.slope.width + CONTRLSPACEPIXELS;
	}

	m = pLayoutOptions->config[c].map;
	SetDlgControlLocation(m.grpBox, GetDlgItem(hDlg, IDC_STATIC_MAPGROUPBOX), dx, dy);
	SetDlgControlLocation(m.heightLabel, GetDlgItem(hDlg, IDC_STATIC_MAPHEIGHT), dx, dy);
	SetDlgControlLocation(m.widthLabel, GetDlgItem(hDlg, IDC_STATIC_MAPWIDTH), dx, dy);
	SetDlgControlLocation(m.totSurfAreaLabel, GetDlgItem(hDlg, IDC_STATIC_MAPSURFAREA), dx, dy);
	SetDlgControlLocation(m.totWaterAreaLabel, GetDlgItem(hDlg, IDC_STATIC_MAPSURFAREA_WATER), dx, dy);
	SetDlgControlLocation(m.totLandAreaLabel, GetDlgItem(hDlg, IDC_STATIC_MAPSURFAREA_LAND), dx, dy);
	SetDlgControlLocation(m.latResLabel, GetDlgItem(hDlg, IDC_STATIC_RESOLUTION_LAT), dx, dy);
	SetDlgControlLocation(m.lonResLabel, GetDlgItem(hDlg, IDC_STATIC_RESOLUTION_LON), dx, dy);

	a = pLayoutOptions->config[c].animat;
	SetDlgControlLocation(a.grpBox, GetDlgItem(hDlg, IDC_STATIC_ANIMATDENSITYGROUPBOX), dx, dy);
	SetDlgControlLocation(a.densityLabel, GetDlgItem(hDlg, IDC_STATIC_ANIMATDENSITY), dx, dy);
	SetDlgControlLocation(a.popSizeLabel, GetDlgItem(hDlg, IDC_STATIC_ANIMATPOPSIZE), dx, dy);

	b = pLayoutOptions->config[c].buttonGroup;
	SetDlgControlLocation(b.grpBox, GetDlgItem(hDlg, IDC_STATIC_DISPLAYOPTSGROUPBOX), dx, dy);
	SetDlgControlLocation(b.samplePtsButton, GetDlgItem(hDlg, IDC_BUTTON_TOGGLE_DATPTS), dx, dy);
	//SetDlgControlLocation(b.bathySlopeButton, GetDlgItem(hDlg, IDC_BUTTON_TOGGLE_EXTRAS), dx, dy);
	SetDlgControlLocation(b.slopeRegionsButton, GetDlgItem(hDlg, IDC_BUTTON_TOGGLE_SLOPEREGIONS),  dx, dy);

	return dlgLayout;
}
Пример #29
0
BOOL CreateGLWindow(char* title, int width, int height, int bits, BOOL fullscreenflag)
{
	GLuint		PixelFormat;			// Holds The Results After Searching For A Match
	WNDCLASS	wc;						// Windows Class Structure
	DWORD		dwExStyle;				// Window Extended Style
	DWORD		dwStyle;				// Window Style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	WindowRect.left=(long)0;			// Set Left Value To 0
	WindowRect.right=(long)width;		// Set Right Value To Requested Width
	WindowRect.top=(long)0;				// Set Top Value To 0
	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height

	fullscreen=fullscreenflag;			// Set The Global Fullscreen Flag

	hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) WndProc;					// WndProc Handles Messages
	wc.cbClsExtra		= 0;									// No Extra Window Data
	wc.cbWndExtra		= 0;									// No Extra Window Data
	wc.hInstance		= hInstance;							// Set The Instance
	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
	wc.hbrBackground	= NULL;									// No Background Required For GL
	wc.lpszMenuName		= NULL;									// We Don't Want A Menu
	wc.lpszClassName	= "OpenGL";								// Set The Class Name

	EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &DMsaved); // save the current display state (NEW)

	if (fullscreen)												// Attempt Fullscreen Mode?
	{
		DEVMODE dmScreenSettings;								// Device Mode
		memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
		dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
		dmScreenSettings.dmPelsWidth	= width;				// Selected Screen Width
		dmScreenSettings.dmPelsHeight	= height;				// Selected Screen Height
		dmScreenSettings.dmBitsPerPel	= bits;					// Selected Bits Per Pixel
		dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
		if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			// If The Mode Fails, Offer Two Options.  Quit Or Use Windowed Mode.
			if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
			{
				fullscreen=FALSE;		// Windowed Mode Selected.  Fullscreen = FALSE
			}
			else
			{
				// Pop Up A Message Box Letting User Know The Program Is Closing.
				MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
				return FALSE;									// Return FALSE
			}
		}
	}

	if (!RegisterClass(&wc))									// Attempt To Register The Window Class
	{
		MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;											// Return FALSE
	}

	if (fullscreen)												// Are We Still In Fullscreen Mode?
	{
		dwExStyle=WS_EX_APPWINDOW;								// Window Extended Style
		dwStyle=WS_POPUP;										// Windows Style
		ShowCursor(FALSE);										// Hide Mouse Pointer
	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style
	}

	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);		// Adjust Window To True Requested Size

	// Create The Window
	if (!(hWnd=CreateWindowEx(	dwExStyle,							// Extended Style For The Window
								"OpenGL",							// Class Name
								title,								// Window Title
								dwStyle |							// Defined Window Style
								WS_CLIPSIBLINGS |					// Required Window Style
								WS_CLIPCHILDREN,					// Required Window Style
								0, 0,								// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,								// No Parent Window
								NULL,								// No Menu
								hInstance,							// Instance
								NULL)))								// Dont Pass Anything To WM_CREATE
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

    pfd.cColorBits = bits;

    if (!(hDC=GetDC(hWnd)))                         // Did We Get A Device Context?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))	// Did Windows Find A Matching Pixel Format?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if(!SetPixelFormat(hDC,PixelFormat,&pfd))		// Are We Able To Set The Pixel Format?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if (!(hRC=wglCreateContext(hDC)))				// Are We Able To Get A Rendering Context?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if(!wglMakeCurrent(hDC,hRC))					// Try To Activate The Rendering Context
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	ShowWindow(hWnd,SW_SHOW);						// Show The Window
	SetForegroundWindow(hWnd);						// Slightly Higher Priority
	SetFocus(hWnd);									// Sets Keyboard Focus To The Window
	ReSizeGLScene(width, height);					// Set Up Our Perspective GL Screen

	if (!InitGL())									// Initialize Our Newly Created GL Window
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	return TRUE;									// Success
}
Пример #30
-1
/**
 * name:	Button_WndProc
 * desc:	window procedure for the button class
 * param:	hwndBtn		- window handle to the button
 *			uMsg		- message to handle
 *			wParam		- message specific parameter
 *			lParam		- message specific parameter
 * return:	message specific
 **/
static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	LPBTNCTRL bct = (LPBTNCTRL)GetWindowLongPtr(hwndBtn, 0);
	
	switch (uMsg) {
	case WM_NCCREATE:
		{
			LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam;

			cs->style |= BS_OWNERDRAW;
			if (!(bct = (LPBTNCTRL)mir_alloc(sizeof(BTNCTRL))))
				return FALSE;
			ZeroMemory(bct, sizeof(BTNCTRL));
			bct->hwnd = hwndBtn;
			bct->stateId = PBS_NORMAL;
			bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
			bct->dwStyle = cs->style;
			if (cs->style & MBS_DOWNARROW)
				bct->arrow = Skin_GetIcon(ICO_BTN_DOWNARROW);
			LoadTheme(bct);
			SetWindowLongPtr(hwndBtn, 0, (LONG_PTR)bct);
			if (cs->lpszName) SetWindowText(hwndBtn, cs->lpszName);
			return TRUE;
		}
	case WM_DESTROY:
		if (bct) {
			EnterCriticalSection(&csTips);
			if (hwndToolTips) {
				TOOLINFO ti;

				ZeroMemory(&ti, sizeof(ti));
				ti.cbSize = sizeof(ti);
				ti.uFlags = TTF_IDISHWND;
				ti.hwnd = bct->hwnd;
				ti.uId = (UINT_PTR)bct->hwnd;
				if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) {
					SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti);
				}
				if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0) {
					DestroyWindow(hwndToolTips);
					hwndToolTips = NULL;
				}
			}
			LeaveCriticalSection(&csTips);
			DestroyTheme(bct);
			mir_free(bct);
		}
		SetWindowLongPtr(hwndBtn, 0, NULL);
		break;
	case WM_SETTEXT:
		bct->cHot = 0;
		if ((LPTSTR)lParam) {
			LPTSTR tmp = (LPTSTR)lParam;

			while (*tmp) {
				if (*tmp == '&' && *(tmp + 1)) {
					bct->cHot = _totlower(*(tmp + 1));
					break;
				}
				tmp++;
			}
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;
	case WM_SYSKEYUP:
		if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == _totlower((TCHAR)wParam)) {
			if (bct->dwStyle & MBS_PUSHBUTTON) {
				if (bct->pbState) bct->pbState = 0;
				else bct->pbState = 1;
				InvalidateRect(bct->hwnd, NULL, TRUE);
			}
			else
				SetFocus(hwndBtn);
			SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn);
			return 0;
		}
		break;
	case WM_THEMECHANGED: 
		// themed changed, reload theme object
		LoadTheme(bct);
		InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
		break;
	case WM_SETFONT: // remember the font so we can use it later
		bct->hFont = (HFONT)wParam; // maybe we should redraw?
		break;
	case WM_NCPAINT:
	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdcPaint;
			HDC hdcMem;
			HBITMAP hbmMem;
			HDC hOld;
			RECT rcClient;
			
			if (hdcPaint = BeginPaint(hwndBtn, &ps)) {
				GetClientRect(bct->hwnd, &rcClient);
				hdcMem = CreateCompatibleDC(hdcPaint);
				hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
				hOld = (HDC)SelectObject(hdcMem, hbmMem);

				// If its a push button, check to see if it should stay pressed
				if ((bct->dwStyle & MBS_PUSHBUTTON) && bct->pbState) bct->stateId = PBS_PRESSED;

				if ((bct->dwStyle & MBS_FLAT) && bct->hThemeToolbar || bct->hThemeButton)
					PaintThemeButton(bct, hdcMem, &rcClient);
				else
					PaintButton(bct, hdcMem, &rcClient);

				BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, hOld);
				DeleteObject(hbmMem);
				DeleteDC(hdcMem);				
				EndPaint(hwndBtn, &ps);
			}
		}
		return 0;
	case BM_SETIMAGE:
		if (wParam == IMAGE_ICON) {
			bct->hIcon = (HICON)lParam;
			bct->hBitmap = NULL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		else if (wParam == IMAGE_BITMAP) {
			bct->hIcon = NULL;
			bct->hBitmap = (HBITMAP)lParam;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		else if (wParam == NULL && lParam == NULL) {
			bct->hIcon = NULL;
			bct->hBitmap = NULL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;
	case BM_SETCHECK:
		if (!(bct->dwStyle & MBS_PUSHBUTTON)) break;
		if (wParam == BST_CHECKED) {
			bct->pbState = 1;
			bct->stateId = PBS_PRESSED;
		}
		else if (wParam == BST_UNCHECKED) {
			bct->pbState = 0;
			bct->stateId = PBS_NORMAL;
		}
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BM_GETCHECK:
		if (bct->dwStyle & MBS_PUSHBUTTON) return bct->pbState ? BST_CHECKED : BST_UNCHECKED;
		return 0;
	case BUTTONSETDEFAULT:
		bct->defbutton = (wParam != 0);
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BUTTONADDTOOLTIP:
		if (wParam) {			
			EnterCriticalSection(&csTips);
			if (!hwndToolTips)
				hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);

			if (lParam == MBBF_UNICODE) {
				TOOLINFOW ti;

				ZeroMemory(&ti, sizeof(TOOLINFOW));
				ti.cbSize = sizeof(TOOLINFOW);
				ti.uFlags = TTF_IDISHWND;
				ti.hwnd = bct->hwnd;
				ti.uId = (UINT_PTR)bct->hwnd;
				if (SendMessage(hwndToolTips, TTM_GETTOOLINFOW, 0, (LPARAM)&ti)) {
					SendMessage(hwndToolTips, TTM_DELTOOLW, 0, (LPARAM)&ti);
				}
				ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;
				ti.uId = (UINT_PTR)bct->hwnd;
				ti.lpszText=(LPWSTR)wParam;
				SendMessage(hwndToolTips, TTM_ADDTOOLW, 0, (LPARAM)&ti);
			}
			else {
				TOOLINFOA ti;

				ZeroMemory(&ti, sizeof(TOOLINFOA));
				ti.cbSize = sizeof(TOOLINFOA);
				ti.uFlags = TTF_IDISHWND;
				ti.hwnd = bct->hwnd;
				ti.uId = (UINT_PTR)bct->hwnd;
				if (SendMessage(hwndToolTips, TTM_GETTOOLINFOA, 0, (LPARAM)&ti)) {
					SendMessage(hwndToolTips, TTM_DELTOOLA, 0, (LPARAM)&ti);
				}
				ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;
				ti.uId = (UINT_PTR)bct->hwnd;
				ti.lpszText=(LPSTR)wParam;
				SendMessage(hwndToolTips, TTM_ADDTOOLA, 0, (LPARAM)&ti);
			}
			LeaveCriticalSection(&csTips);
		}
		break;
	case BUTTONTRANSLATE:
		{
			TCHAR szButton[MAX_PATH];
			GetWindowText(bct->hwnd, szButton, MAX_PATH);
			SetWindowText(bct->hwnd, TranslateTS(szButton));
		}
		break;
	case WM_SETFOCUS: // set keybord bFocus and redraw
		bct->bFocus = 1;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case WM_KILLFOCUS: // kill bFocus and redraw
		bct->bFocus = 0;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case WM_WINDOWPOSCHANGED:
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case WM_ENABLE: // windows tells us to enable/disable
		bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case WM_MOUSELEAVE: // faked by the WM_TIMER
		if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
			bct->stateId = PBS_NORMAL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;
	case WM_LBUTTONDOWN:
		if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
			bct->stateId = PBS_PRESSED;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;
	case WM_LBUTTONUP:
		if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
			BYTE bPressed = bct->stateId == PBS_PRESSED;

			if (bct->dwStyle & MBS_PUSHBUTTON) {
				if (bct->pbState) bct->pbState = 0;
				else bct->pbState = 1;
			}
			bct->stateId = PBS_HOT;

			// Tell your daddy you got clicked, if mouse is still over the button.
			if ((bct->dwStyle & MBS_PUSHBUTTON) || bPressed)
				SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn);
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;
	case WM_MOUSEMOVE:
		if (bct->stateId == PBS_NORMAL) {
			bct->stateId = PBS_HOT;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		// Call timer, used to start cheesy TrackMouseEvent faker
		SetTimer(hwndBtn, BUTTON_POLLID, BUTTON_POLLDELAY, NULL);
		break;
	case WM_TIMER: // use a timer to check if they have did a mouseout
		if (wParam == BUTTON_POLLID) {
			RECT rc;
			POINT pt;

			GetWindowRect(hwndBtn, &rc);
			GetCursorPos(&pt);
			if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave
				PostMessage(hwndBtn, WM_MOUSELEAVE, 0, 0L);
				KillTimer(hwndBtn, BUTTON_POLLID);
			}
		}
		break;
	case WM_ERASEBKGND:
		return 1;
	}
	return DefWindowProc(hwndBtn, uMsg, wParam, lParam);
}