1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2001 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
/*****************************************************************************
* GUI_test.exe is a binary that tests if the Window that it opens is
* beeing displayed on the visible desktop.
*
* Purpose: This binary allows the testsuite to test the
* display_win_gui complex variable on Windows hosts.
*
* GUI_test.cpp : Defines the entry point for the application.
******************************************************************************/
#include <windows.h>
// Global Variables:
TCHAR g_szWindowClass[] = "GUI_TEST"; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
/****** GUI_test/WinMain() ***************************************************
* NAME
* WinMain() -- Entry point of this executable
*
* SYNOPSIS
* int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
* LPTSTR lpCmdLine, int nCmdShow)
*
* FUNCTION
* Entry point of this executable. Initializes this instance of the
* application and does the message loop.
*
* INPUTS
* See WinAPI documentation.
*
* RESULTS
* int - Depends on how this application gets terminated.
* See WinAPI documentation for details.
******************************************************************************/
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow)) {
return FALSE;
}
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
/****** GUI_test/MyRegisterClass() *******************************************
* NAME
* MyRegisterClass() -- Registers a 'personalized' window class
*
* SYNOPSIS
* ATOM MyRegisterClass(HINSTANCE hInstance)
*
* FUNCTION
* Registers a special window class for this application at the system.
*
* INPUTS
* HINSTANCE hInstance - Handle to this instance of the application.
* See WinAPI documentation for details.
*
* RESULTS
* ATOM - Class-Atom of the registered class.
* See WinAPI documentation for details.
******************************************************************************/
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(WNDCLASSEX));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.hInstance = hInstance;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszClassName = g_szWindowClass;
return RegisterClassEx(&wcex);
}
/****** GUI_test/InitInstance() **********************************************
* NAME
* InitInstance() -- Initializes this instance of this application
*
* SYNOPSIS
* BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
*
* FUNCTION
* Creates and shows the main Windows of this application.
*
* INPUTS
* HINSTANCE hInstance - Handle of this instance of this application.
* int nCmdShow - Show mode of the main window,
* e.g. maximized, normal, show, hide, ...
* See WinAPI documentation for details.
*
* RESULTS
* BOOL - TRUE if OK, FALSE is creation of main windows failed.
******************************************************************************/
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hWnd = CreateWindow(g_szWindowClass, "GUI_test", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd) {
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
/****** GUI_test/WndProc() ***************************************************
* NAME
* WndProc() -- The message handler of the main window
*
* SYNOPSIS
* LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
* WPARAM wParam, LPARAM lParam)
*
* FUNCTION
* Processes messages for the main window.
* Exits this application with return code 57 if the main window is visible
* on the default desktop of the default window station ("WinSta0").
*
* INPUTS
* HWND hWnd - Handle of the main window
* UINT message - Message-ID
* WPARAM wParam - First parameter of the message
* LPARAM lParam - Second parameter of the message
* See WinAPI documentation for details.
*
* RESULTS
* LRESULT - 0 if the message was handled by this function,
* the result of DefWindowProc() if it was handled by
* the default handler.
******************************************************************************/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
HWINSTA hWinsta;
HDESK hDesk;
char szDeskName[100];
char szWinstaName[100];
int ret = 0;
switch (message)
{
// This message is sent when CreateWindow() finishes
case WM_CREATE:
// Check if we are on the visible Desktop
hWinsta = GetProcessWindowStation();
hDesk = GetThreadDesktop(GetCurrentThreadId());
GetUserObjectInformation(hWinsta, UOI_NAME, szWinstaName, 100, NULL);
GetUserObjectInformation(hDesk, UOI_NAME, szDeskName, 100, NULL);
if (strcmp(szWinstaName, "WinSta0") == 0
&& strcmp(szDeskName, "Default") == 0) {
ret = 57;
}
PostQuitMessage(ret);
break;
// This message is sent whenever a region of the window
// has to be repainted
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
// This message is sent when the Window is to be destroyed
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
|