void initializeMainThreadPlatform() { if (threadingWindowHandle) return; HWND hWndParent = 0; WNDCLASSW wcex; memset(&wcex, 0, sizeof(WNDCLASSW)); wcex.lpfnWndProc = ThreadingWindowWndProc; wcex.lpszClassName = kThreadingWindowClassName; RegisterClassW(&wcex); #if !OS(WINCE) hWndParent = HWND_MESSAGE; #endif threadingWindowHandle = CreateWindowW(kThreadingWindowClassName, 0, 0, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, hWndParent, 0, 0, 0); threadingFiredMessage = RegisterWindowMessageW(L"com.apple.WebKit.MainThreadFired"); initializeCurrentThreadInternal("Main Thread"); }
bool StWinHandles::registerClass(const StStringUtfWide& theName, WNDPROC theProc) { HINSTANCE aModule = GetModuleHandleW(NULL); WNDCLASSW aClass; stMemZero(&aClass, sizeof(aClass)); // redraw on resize, and request own DC for window aClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; aClass.lpfnWndProc = theProc; aClass.cbClsExtra = 0; aClass.cbWndExtra = 0; aClass.hInstance = aModule; aClass.hIcon = LoadIconW(aModule, L"A"); aClass.hCursor = LoadCursor(NULL, IDC_ARROW); aClass.hbrBackground = NULL; aClass.lpszMenuName = NULL; aClass.lpszClassName = theName.toCString(); if(RegisterClassW(&aClass) == 0) { stError(StString("WinAPI: Failed to register window class '") + theName.toUtf8() + "'"); return false; } return true; }
/*static*/ const WCHAR* GetWNDCLASS(HINSTANCE const hInstance) { static WNDCLASSW const wc = { CS_OWNDC, // style m1::game_platform::impl::WndProc, // lpfnWndProc 0, // cbClsExtra 0, // cbWndExtra hInstance, // hInstance LoadIcon(nullptr, IDI_APPLICATION), // hIcon LoadCursor(nullptr, IDC_ARROW), // hCursor GetSysColorBrush(COLOR_WINDOW), // hbrBackground nullptr, // lpszMenuName L"M1_GAME_WNDCLASS", // lpszClassName }; assert(wc.hInstance == hInstance); static WCHAR const *result = MAKEINTRESOURCEW(RegisterClassW(&wc)); return result; }
static void Control_DoInterface(CPanel* panel, HWND hWnd, HINSTANCE hInst) { WNDCLASSW wc; MSG msg; const WCHAR* appName = L"ReactOS Control Panel"; wc.style = CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc = Control_WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = sizeof(CPlApplet*); wc.hInstance = hInst; wc.hIcon = 0; wc.hCursor = 0; wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = L"Shell_Control_WndClass"; if (!RegisterClassW(&wc)) return; CreateWindowExW(0, wc.lpszClassName, appName, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWnd, NULL, hInst, panel); if (!panel->hWnd) return; if (!panel->first) { /* FIXME appName & message should be localized */ MessageBoxW(panel->hWnd, L"Cannot load any applets", appName, MB_OK); return; } while (GetMessageW(&msg, panel->hWnd, 0, 0)) { TranslateMessage(&msg); DispatchMessageW(&msg); } }
int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE hprevinst, wchar_t *cmdline, int cmdshow) { const wchar_t *classname = L"My Demo Class"; const wchar_t *wndcaption = L"My Demo Window"; WNDCLASSW wc; HWND hwnd; MSG msg; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = wndproc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hinst; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = classname; if (!RegisterClassW(&wc)) return -1; hwnd = CreateWindowW( classname, wndcaption, WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, NULL, NULL, hinst, NULL); if (hwnd == NULL) return -1; ShowWindow(hwnd, SW_SHOW); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }
GLContext::GLContext() { LPCWSTR title = L"Virtual Sculpting"; WNDCLASSW windowClass; HWND hWnd; DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; hInstance = GetModuleHandle(NULL); windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; windowClass.lpfnWndProc = (WNDPROC) WndProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = hInstance; windowClass.hIcon = LoadIcon(NULL, IDI_WINLOGO); windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); windowClass.hbrBackground = NULL; windowClass.lpszMenuName = NULL; windowClass.lpszClassName = title; if (!RegisterClassW(&windowClass)) { return; } // define the screen resolution #define SCREEN_WIDTH 1920 #define SCREEN_HEIGHT 1080 hWnd = CreateWindowExW(dwExStyle, title, title, NULL | WS_MAXIMIZE, 0, 0, 1920, 1080, NULL, NULL, hInstance, NULL); this->hwnd = hWnd; create30Context(); // Create a context given a HWND ShowWindow(this->hwnd, SW_SHOW); UpdateWindow(this->hwnd); }
nsresult TaskbarTabPreview::Enable() { WNDCLASSW wc; HINSTANCE module = GetModuleHandle(nullptr); if (!GetClassInfoW(module, kWindowClass, &wc)) { wc.style = 0; wc.lpfnWndProc = GlobalWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = module; wc.hIcon = nullptr; wc.hCursor = nullptr; wc.hbrBackground = (HBRUSH) nullptr; wc.lpszMenuName = (LPCWSTR) nullptr; wc.lpszClassName = kWindowClass; RegisterClassW(&wc); } ::CreateWindowW(kWindowClass, L"TaskbarPreviewWindow", WS_CAPTION | WS_SYSMENU, 0, 0, 200, 60, nullptr, nullptr, module, this); // GlobalWndProc will set mProxyWindow so that WM_CREATE can have a valid HWND if (!mProxyWindow) return NS_ERROR_INVALID_ARG; UpdateProxyWindowStyle(); nsresult rv = TaskbarPreview::Enable(); nsresult rvUpdate; rvUpdate = UpdateTitle(); if (NS_FAILED(rvUpdate)) rv = rvUpdate; rvUpdate = UpdateIcon(); if (NS_FAILED(rvUpdate)) rv = rvUpdate; return rv; }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow) { MSG msg; WNDCLASSW wc = {0}; wc.lpszClassName = L"Windows"; wc.hInstance = hInstance; wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); wc.lpfnWndProc = WndProc; wc.hCursor = LoadCursor(0, IDC_ARROW); RegisterClassW(&wc); CreateWindowW(wc.lpszClassName, L"Windows", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 180, 0, 0, hInstance, 0); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int) msg.wParam; }
static ATOM clutter_stage_win32_get_window_class () { static ATOM klass = 0; if (klass == 0) { WNDCLASSW wndclass; memset (&wndclass, 0, sizeof (wndclass)); wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = _clutter_stage_win32_window_proc; wndclass.cbWndExtra = sizeof (LONG_PTR); wndclass.hInstance = GetModuleHandleW (NULL); wndclass.hIcon = LoadIconW (NULL, (LPWSTR) IDI_APPLICATION); wndclass.hCursor = LoadCursorW (NULL, (LPWSTR) IDC_ARROW); wndclass.hbrBackground = NULL; wndclass.lpszMenuName = NULL; wndclass.lpszClassName = L"ClutterStageWin32"; klass = RegisterClassW (&wndclass); } return klass; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd){ static wchar_t szAppName[] = L"Checker2"; HWND hwnd; MSG msg; WNDCLASS wndcls; wndcls.cbClsExtra = 0; wndcls.cbWndExtra = 0; wndcls.hbrBackground = (HBRUSH)GetStockObject(DC_BRUSH); wndcls.hCursor = LoadCursor(NULL,IDC_ARROW); wndcls.hIcon = LoadIcon(NULL,IDI_APPLICATION); wndcls.hInstance = hInstance; wndcls.lpfnWndProc = WndProc; wndcls.lpszClassName = szAppName; wndcls.lpszMenuName = NULL; wndcls.style = CS_HREDRAW | CS_VREDRAW; if(!RegisterClassW(&wndcls)){ MessageBoxW(NULL,L"This program requires Windows NT!",szAppName,MB_ICONERROR); return 0; } hwnd = CreateWindowW(szAppName,L"Checker2 Mouse Hit-Test Demo",WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,hInstance,NULL); ShowWindow(hwnd,nShowCmd); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0)){ TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
EF_Error ef_internal_video_init() { drawable_parameters.double_buffer = False; drawable_parameters.stereo = False; drawable_parameters.aux_buffers = 0; drawable_parameters.color_size = 8; drawable_parameters.alpha_size = 0; drawable_parameters.depth_size = 0; drawable_parameters.stencil_size = 0; drawable_parameters.accumulation_size = 0; drawable_parameters.samples = 0; drawable_parameters.aux_depth_stencil = False; drawable_parameters.color_float = False; drawable_parameters.multisample = False; drawable_parameters.supersample = False; drawable_parameters.sample_alpha = False; n_drawables = 0; all_drawables = NULL; hInstance = GetModuleHandleW(NULL); WNDCLASSW window_class; window_class.style = CS_OWNDC; window_class.lpfnWndProc = window_procedure; window_class.cbClsExtra = 0; window_class.cbWndExtra = 0; window_class.hInstance = hInstance; window_class.hIcon = LoadIcon(NULL, IDI_APPLICATION); window_class.hCursor = LoadCursor(NULL, IDC_ARROW); window_class.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); window_class.lpszMenuName = NULL; window_class.lpszClassName = L"Emerald Frame"; RegisterClassW(&window_class); return 0; }
void EnableBatteryNotifications() { // Create custom window to watch battery event // If we can get Gecko's window handle, this is unnecessary. if (sHWnd == nullptr) { WNDCLASSW wc; HMODULE hSelf = GetModuleHandle(nullptr); if (!GetClassInfoW(hSelf, L"MozillaBatteryClass", &wc)) { ZeroMemory(&wc, sizeof(WNDCLASSW)); wc.hInstance = hSelf; wc.lpfnWndProc = BatteryWindowProc; wc.lpszClassName = L"MozillaBatteryClass"; RegisterClassW(&wc); } sHWnd = CreateWindowW(L"MozillaBatteryClass", L"Battery Watcher", 0, 0, 0, 0, 0, nullptr, nullptr, hSelf, nullptr); } if (sHWnd == nullptr) { return; } sPowerHandle = RegisterPowerSettingNotification(sHWnd, &GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE); sCapacityHandle = RegisterPowerSettingNotification(sHWnd, &GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE); }
bool KINWM::Create(const std::wstring& p_Caption, const Common::KINRect p_Rect, const unsigned int p_BackColor, const unsigned int p_WindowStyle, const WNDPROC p_MessageFunction) { mhInstance = GetModuleHandle(NULL); WNDCLASSW WndClass; WndClass.style = CS_CLASSDC; WndClass.lpfnWndProc = (WNDPROC)p_MessageFunction; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = mhInstance; WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION); WndClass.hCursor = LoadCursor (NULL, IDC_ARROW); WndClass.hbrBackground = 0; WndClass.lpszMenuName = NULL; WndClass.lpszClassName = p_Caption.c_str(); RegisterClassW(&WndClass); mhWnd = CreateWindowW(p_Caption.c_str(), p_Caption.c_str(), p_WindowStyle, p_Rect.mX, p_Rect.mY, p_Rect.mWidth, p_Rect.mHeight, NULL, NULL, GetModuleHandle(NULL), NULL); if(mhWnd == NULL) { printf("KINWM::Create 실패 - mhWnd가 NULL 입니다.\n"); } SetToClient(Common::KINSize(p_Rect.mWidth, p_Rect.mHeight)); ShowWindow(); return true; }
static void gui_unique_win32_init (Gimp *gimp) { WNDCLASSW wc; g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (unique_gimp == NULL); unique_gimp = gimp; /* register window class for proxy window */ memset (&wc, 0, sizeof (wc)); wc.hInstance = GetModuleHandle (NULL); wc.lpfnWndProc = gui_unique_win32_message_handler; wc.lpszClassName = GIMP_UNIQUE_WIN32_WINDOW_CLASS; RegisterClassW (&wc); proxy_window = CreateWindowExW (0, GIMP_UNIQUE_WIN32_WINDOW_CLASS, GIMP_UNIQUE_WIN32_WINDOW_NAME, WS_POPUP, 0, 0, 1, 1, NULL, NULL, wc.hInstance, NULL); }
HWND GamePlayer::StartWindow() { // 创建窗口 WNDCLASSW winclass; winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = DefWindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hInstance; winclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(101)); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = pWndClassName; if (!RegisterClassW(&winclass)) { ShowErrorMsg(g_hWnd, szTitle, L"注册窗口类失败 %s。", pWndClassName); return 0; } DWORD dwStyle = WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE| WS_CLIPCHILDREN; HWND th=::CreateWindowEx(WS_EX_WINDOWEDGE,pWndClassName,L"v",WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,0,0,600,400,0,0,hInstance,0); RECT rt1; GetClientRect(th,&rt1); int width = nScreenWidth + (600-rt1.right-rt1.left);//GetSystemMetrics(SM_CXFIXEDFRAME) * 2; int height = nScreenHeight + (400-rt1.bottom-rt1.top); RECT rt;{ rt.left = (GetSystemMetrics(SM_CXSCREEN) - width) / 2; //rt.top = (GetSystemMetrics(SM_CYSCREEN) - height) / 2; rt.top = (GetSystemMetrics(SM_CYMAXIMIZED) - nScreenHeight) / 2 - GetSystemMetrics(SM_CYCAPTION); rt.right = rt.left + width; rt.bottom = rt.top + height; } DestroyWindow(th); g_hWnd = ::CreateWindowEx(WS_EX_WINDOWEDGE, pWndClassName, szTitle, dwStyle, rt.left, rt.top, /*rt.right - rt.left*/width, /*rt.bottom - rt.top*/height, 0, 0, hInstance, 0); if (!g_hWnd) { ShowErrorMsg(g_hWnd, szTitle, L"创建窗口失败 %s。", szTitle); ___exit(); return (HWND)-1; } // 控制台 if (strcmp(lpCmdLine, "console") == 0) { if (AllocConsole()) { SetConsoleTitle(L"RGSS Console"); FILE* frw = NULL; freopen_s(&frw, "conout$", "w", stdout); } } ShowWindow(g_hWnd, SW_SHOW); return g_hWnd; }
INT WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow) { g_hInstance = hInstance; InitCommonControls(); HACCEL hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(1)); LoadStringW(hInstance, IDS_TITLE, g_szTitle, _countof(g_szTitle)); LoadStringW(hInstance, IDS_FONTNAME, g_szNameHead, _countof(g_szNameHead)); LoadStringW(hInstance, IDS_SUBSTITUTE, g_szSubstituteHead, _countof(g_szSubstituteHead)); WNDCLASSW wc = {0}; wc.style = 0; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; g_hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(1)); wc.hIcon = g_hIcon; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); wc.lpszMenuName = MAKEINTRESOURCEW(1); wc.lpszClassName = g_pszClassName; if (!RegisterClassW(&wc)) { MessageBoxA(NULL, "ERROR: RegisterClass failed.", NULL, MB_ICONERROR); return 1; } const DWORD dwStyle = WS_OVERLAPPEDWINDOW; INT Width = NAME_COLUMN_WIDTH + SUB_COLUMN_WIDTH + GetSystemMetrics(SM_CXVSCROLL) + GetSystemMetrics(SM_CXSIZEFRAME); INT Height = 320; RECT Rect = { 0, 0, Width, Height }; AdjustWindowRect(&Rect, dwStyle, TRUE); Width = Rect.right - Rect.left; Height = Rect.bottom - Rect.top; g_hMainWnd = CreateWindowW(g_pszClassName, g_szTitle, dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, Width, Height, NULL, NULL, hInstance, NULL); if (g_hMainWnd == NULL) { MessageBoxA(NULL, "ERROR: CreateWindow failed.", NULL, MB_ICONERROR); return 2; } ShowWindow(g_hMainWnd, nCmdShow); UpdateWindow(g_hMainWnd); MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { if (TranslateAccelerator(g_hMainWnd, hAccel, &msg)) continue; TranslateMessage(&msg); DispatchMessage(&msg); } return (INT)msg.wParam; }
void EnableBatteryNotifications() { #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN if (IsVistaOrLater()) { // RegisterPowerSettingNotification is from Vista or later. // Use this API if available. HMODULE hUser32 = GetModuleHandleW(L"USER32.DLL"); if (!sRegisterPowerSettingNotification) sRegisterPowerSettingNotification = (REGISTERPOWERSETTINGNOTIFICATION) GetProcAddress(hUser32, "RegisterPowerSettingNotification"); if (!sUnregisterPowerSettingNotification) sUnregisterPowerSettingNotification = (UNREGISTERPOWERSETTINGNOTIFICATION) GetProcAddress(hUser32, "UnregisterPowerSettingNotification"); if (!sRegisterPowerSettingNotification || !sUnregisterPowerSettingNotification) { NS_ASSERTION(false, "Canot find PowerSettingNotification functions."); return; } // Create custom window to watch battery event // If we can get Gecko's window handle, this is unnecessary. if (sHWnd == nsnull) { WNDCLASSW wc; HMODULE hSelf = GetModuleHandle(nsnull); if (!GetClassInfoW(hSelf, L"MozillaBatteryClass", &wc)) { ZeroMemory(&wc, sizeof(WNDCLASSW)); wc.hInstance = hSelf; wc.lpfnWndProc = BatteryWindowProc; wc.lpszClassName = L"MozillaBatteryClass"; RegisterClassW(&wc); } sHWnd = CreateWindowW(L"MozillaBatteryClass", L"Battery Watcher", 0, 0, 0, 0, 0, nsnull, nsnull, hSelf, nsnull); } if (sHWnd == nsnull) { return; } sPowerHandle = sRegisterPowerSettingNotification(sHWnd, &GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE); sCapacityHandle = sRegisterPowerSettingNotification(sHWnd, &GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE); } else #endif { // for Windows 2000 and Windwos XP. If we remove Windows XP support, // we should remove timer-based power notification sUpdateTimer = do_CreateInstance(NS_TIMER_CONTRACTID); if (sUpdateTimer) { sUpdateTimer->InitWithFuncCallback(UpdateHandler, nsnull, Preferences::GetInt("dom.battery.timer", 30000 /* 30s */), nsITimer::TYPE_REPEATING_SLACK); } } }
static qboolean VID_CreateWindow( int *width, int *height, qboolean fullscreen ) { RECT r; cvar_t *vid_xpos, *vid_ypos; int stylebits; int x, y, w, h; int exstyle; #define WITH_UTF8 // FIXME: turn non-Unicode code into a runtime fallback for Win9x #ifndef WITH_UTF8 WNDCLASS wc; #else WNDCLASSW wc; HWND parentHWND = glw_state.parenthWnd; /* determine buffer size required for the unicode string */ WCHAR windowClassName[sizeof(WINDOW_CLASS_NAME)] = L""; MultiByteToWideChar( CP_ACP, 0, WINDOW_CLASS_NAME, -1, windowClassName, sizeof( windowClassName )-1 ); #endif assert( width && height ); /* 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 = LoadIcon( glw_state.hInstance, MAKEINTRESOURCE( IDI_APPICON_VALUE ) ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( GRAY_BRUSH ); wc.lpszMenuName = 0; #ifdef WITH_UTF8 wc.lpszClassName = (LPCWSTR)windowClassName; if( !RegisterClassW( &wc ) ) #else wc.lpszClassName = (LPCSTR)WINDOW_CLASS_NAME; if( !RegisterClass( &wc ) ) #endif Com_Error( ERR_FATAL, "Couldn't register window class" ); r.left = 0; r.top = 0; r.right = *width; r.bottom = *height; if( fullscreen ) { exstyle = WS_EX_TOPMOST; stylebits = ( WS_POPUP|WS_VISIBLE ); parentHWND = NULL; } else if( parentHWND ) { RECT parentWindowRect; GetWindowRect( parentHWND, &parentWindowRect ); r.right = /*min( *width, (parentWindowRect.right - parentWindowRect.left) )*/parentWindowRect.right - parentWindowRect.left; r.bottom = /*min( *height, (parentWindowRect.bottom - parentWindowRect.top) )*/parentWindowRect.bottom - parentWindowRect.top; exstyle = 0; stylebits = WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_VISIBLE; } else { exstyle = 0; stylebits = WINDOW_STYLE; } AdjustWindowRect( &r, stylebits, FALSE ); w = r.right - r.left; h = r.bottom - r.top; if( fullscreen ) { x = 0; y = 0; } else if( parentHWND ) { RECT parentWindowRect; *width = w; *height = h; GetWindowRect( parentHWND, &parentWindowRect ); // share centre with the parent window x = (parentWindowRect.right - parentWindowRect.left - w) / 2; y = (parentWindowRect.bottom - parentWindowRect.top - h) / 2; Cvar_ForceSet( "vid_xpos", va( "%i", x ) ); Cvar_ForceSet( "vid_ypos", va( "%y", y ) ); } else { vid_xpos = Cvar_Get( "vid_xpos", "0", 0 ); vid_ypos = Cvar_Get( "vid_ypos", "0", 0 ); x = vid_xpos->integer; y = vid_ypos->integer; } glw_state.hWnd = CreateWindowEx( exstyle, WINDOW_CLASS_NAME, APPLICATION, stylebits, x, y, w, h, parentHWND, NULL, glw_state.hInstance, NULL ); if( !glw_state.hWnd ) Com_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() ) { Com_Printf( "VID_CreateWindow() - GLimp_InitGL failed\n" ); return qfalse; } SetForegroundWindow( glw_state.hWnd ); SetFocus( glw_state.hWnd ); if( glw_state.parenthWnd ) PostMessage( glw_state.parenthWnd, UWM_APPACTIVE, WA_ACTIVE, 0 ); // let the sound and input subsystems know about the new window VID_NewWindow( *width, *height ); return qtrue; }
agpu_device *_agpu_device::open(agpu_device_open_info* openInfo) { // Create the device. std::unique_ptr<agpu_device> device(new agpu_device); bool failure = false; // Perform the main context creation in device->mainContextJobQueue.start(); AsyncJob contextCreationJob([&] { std::unique_ptr<OpenGLContext> contextWrapper(new OpenGLContext()); // Window for context creation. HINSTANCE hInstance = GetModuleHandle(nullptr); WNDCLASSW wc; memset(&wc, 0, sizeof(wc)); wc.lpfnWndProc = dummyWindowProc; wc.hInstance = hInstance; wc.lpszClassName = L"agpuDummyOGLWindow"; wc.style = CS_OWNDC; if (!RegisterClassW(&wc)) { failure = true; return; } HWND dummyWindow = CreateWindowW(wc.lpszClassName, L"agpuDummyOGLWindow", WS_OVERLAPPEDWINDOW, 0, 0, 16, 16, 0, 0, hInstance, 0); // Need to create a dummy context first. PIXELFORMATDESCRIPTOR pixelFormatDescriptor = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, //Flags PFD_TYPE_RGBA, //The kind of framebuffer. RGBA or palette. 32, //Colordepth of the framebuffer. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, //Number of bits for the depthbuffer 8, //Number of bits for the stencilbuffer 0, //Number of Aux buffers in the framebuffer. PFD_MAIN_PLANE, 0, 0, 0, 0 }; // Set the pixel format. auto dummyDC = GetDC(dummyWindow); int dummyPixelFormat = ChoosePixelFormat(dummyDC, &pixelFormatDescriptor); auto pfRes = SetPixelFormat(dummyDC, dummyPixelFormat, &pixelFormatDescriptor);; if (pfRes == FALSE) { if (!printLastError()) printError("Failed to set window pixel format.\n"); } // Create the context. auto dummyContext = wglCreateContext(dummyDC); if (!dummyContext) { DestroyWindow(dummyWindow); failure = true; return; } // Use the context. if (!wglMakeCurrent(dummyDC, dummyContext)) { wglDeleteContext(dummyContext); DestroyWindow(dummyWindow); failure = true; return; } // Create the context window. HWND contextWindow = CreateWindowW(wc.lpszClassName, L"agpuOGLWindow", WS_OVERLAPPEDWINDOW, 0, 0, 16, 16, 0, 0, hInstance, 0); auto contextDC = GetDC(contextWindow); // Choose a proper pixel format contextWrapper->wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); if (contextWrapper->wglChoosePixelFormatARB) { int pixelFormat; UINT numFormats; int pixelAttributes[] = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, WGL_SUPPORT_OPENGL_ARB, GL_TRUE, WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, WGL_RED_BITS_ARB, 8, WGL_GREEN_BITS_ARB, 8, WGL_BLUE_BITS_ARB, 8, WGL_ALPHA_BITS_ARB, 8, WGL_DEPTH_BITS_ARB, 0, 0 }; contextWrapper->wglChoosePixelFormatARB(contextDC, &pixelAttributes[0], nullptr, 1, &pixelFormat, &numFormats); auto res = SetPixelFormat(contextDC, pixelFormat, &pixelFormatDescriptor); if (res == FALSE) { printError("Failed to set the pixel format.\n"); failure = true; return; } } else { printError("Missing a required extension.\n"); failure = true; return; } // Now create the actual context. contextWrapper->wglCreateContextAttribsARB = (wglCreateContextAttribsARBProc)wglGetProcAddress("wglCreateContextAttribsARB"); if (contextWrapper->wglCreateContextAttribsARB) { int contextAttributes[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 0, WGL_CONTEXT_MINOR_VERSION_ARB, 0, //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 0 }; for (int versionIndex = 0; GLContextVersionPriorities[versionIndex] != OpenGLVersion::Invalid; ++versionIndex) { auto version = (int)GLContextVersionPriorities[versionIndex]; // GLX_CONTEXT_MAJOR_VERSION_ARB contextAttributes[1] = version / 10; // GLX_CONTEXT_MINOR_VERSION_ARB contextAttributes[3] = version % 10; contextWrapper->context = contextWrapper->wglCreateContextAttribsARB(contextDC, NULL, contextAttributes);//glXCreateContextAttribsARB(display, framebufferConfig, 0, True, contextAttributes); // Check for success. if (contextWrapper->context) { contextWrapper->version = OpenGLVersion(version); break; } } } else { contextWrapper->context = wglCreateContext(contextDC); } // Destroy the dummy context wglMakeCurrent(dummyDC, NULL); wglDeleteContext(dummyContext); DestroyWindow(dummyWindow); // Set the current context. if (!contextWrapper->context || !wglMakeCurrent(contextDC, contextWrapper->context)) { failure = true; return; } // Create the device and load the extensions. contextWrapper->window = contextWindow; contextWrapper->hDC = contextDC; contextWrapper->makeCurrent(); device->mainContext = contextWrapper.release(); device->mainContext->device = device.get(); device->initializeObjects(); }); device->mainContextJobQueue.addJob(&contextCreationJob); contextCreationJob.wait(); if (failure) return nullptr; return device.release(); }
int cvrun(int argc, char ** argv) { HANDLE mod = GetModuleHandle(0); WNDCLASSW wc; HGLRC ctx; HWND win; HDC dc; WCHAR name[256]; RECT r; PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 24, // 24-bit 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, // accum bits ignored 32, // 32-bit z-buffer 0, // no stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; DWORD exstyle = WS_EX_APPWINDOW; DWORD style = WINDOWED_STYLE; MultiByteToWideChar(CP_UTF8, 0, (const char *)cvInject(CVQ_NAME, 0, 0), -1, name, sizeof(name)); ZeroMemory(&wc, sizeof(wc)); wc.style += CS_OWNDC; wc.lpfnWndProc = handle; wc.hInstance = mod; wc.hCursor = LoadCursor(0, IDC_ARROW); wc.lpszClassName = name; RegisterClassW(&wc); cvInject(CVE_INIT, 1, (intptr_t)argv); r.left = cvInject(CVQ_XPOS, 0, 0); r.top = cvInject(CVQ_YPOS, 0, 0); r.right = r.left + cvInject(CVQ_WIDTH, 0, 0); r.bottom = r.top + cvInject(CVQ_HEIGHT, 0, 0); AdjustWindowRect(&r, style, FALSE); win = CreateWindowExW(exstyle, name, name, style, r.left, r.top, r.right - r.left, r.bottom - r.top, 0, 0, mod, 0); g_win = win; dc = GetDC(win); SetPixelFormat(dc, ChoosePixelFormat(dc, &pfd), &pfd); ctx = wglCreateContext(dc); wglMakeCurrent(dc, ctx); cvInject(CVE_GLINIT, 0, 0); ((int(APIENTRY*)(int))wglGetProcAddress("wglSwapIntervalEXT"))(1); ShowWindow(win, SW_SHOWNORMAL); while (!g_done) { MSG msg; if (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessageW(&msg); } InvalidateRect(win, 0, 0); UpdateWindow(win); } cvInject(CVE_GLTERM, 0, 0); ReleaseDC(win, dc); return cvInject(CVE_TERM, 0, 0); }
bool DeviceManagerD3D9::Init() { WNDCLASSW wc; HRESULT hr; if (!GetClassInfoW(GetModuleHandle(NULL), kClassName, &wc)) { ZeroMemory(&wc, sizeof(WNDCLASSW)); wc.hInstance = GetModuleHandle(NULL); wc.lpfnWndProc = ::DefWindowProc; wc.lpszClassName = kClassName; if (!RegisterClassW(&wc)) { NS_WARNING("Failed to register window class for DeviceManager."); return false; } } mFocusWnd = ::CreateWindowW(kClassName, L"D3D9Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, GetModuleHandle(NULL), NULL); if (!mFocusWnd) { NS_WARNING("Failed to create DeviceManagerD3D9 Window."); return false; } /* Create an Nv3DVUtils instance */ if (!mNv3DVUtils) { mNv3DVUtils = new Nv3DVUtils(); if (!mNv3DVUtils) { NS_WARNING("Could not create a new instance of Nv3DVUtils.\n"); } } /* Initialize the Nv3DVUtils object */ if (mNv3DVUtils) { mNv3DVUtils->Initialize(); } HMODULE d3d9 = LoadLibraryW(L"d3d9.dll"); Direct3DCreate9Func d3d9Create = (Direct3DCreate9Func) GetProcAddress(d3d9, "Direct3DCreate9"); Direct3DCreate9ExFunc d3d9CreateEx = (Direct3DCreate9ExFunc) GetProcAddress(d3d9, "Direct3DCreate9Ex"); #ifdef USE_D3D9EX if (d3d9CreateEx) { hr = d3d9CreateEx(D3D_SDK_VERSION, getter_AddRefs(mD3D9Ex)); if (SUCCEEDED(hr)) { mD3D9 = mD3D9Ex; } } #endif if (!mD3D9) { if (!d3d9Create) { return false; } mD3D9 = dont_AddRef(d3d9Create(D3D_SDK_VERSION)); if (!mD3D9) { return false; } } D3DADAPTER_IDENTIFIER9 ident; hr = mD3D9->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &ident); if (FAILED(hr)) { return false; } if (!PL_strncasecmp(ident.Driver, "nvumdshim.dll", PL_strlen(ident.Driver))) { // XXX - This is a device using NVidia Optimus. We have no idea how to do // interop here so let's fail and use BasicLayers. See bug 597320. return false; } D3DPRESENT_PARAMETERS pp; memset(&pp, 0, sizeof(D3DPRESENT_PARAMETERS)); pp.BackBufferWidth = 1; pp.BackBufferHeight = 1; pp.BackBufferFormat = D3DFMT_A8R8G8B8; pp.SwapEffect = D3DSWAPEFFECT_DISCARD; pp.Windowed = TRUE; pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; pp.hDeviceWindow = mFocusWnd; if (mD3D9Ex) { hr = mD3D9Ex->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mFocusWnd, D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED | D3DCREATE_MIXED_VERTEXPROCESSING, &pp, NULL, getter_AddRefs(mDeviceEx)); if (SUCCEEDED(hr)) { mDevice = mDeviceEx; } D3DCAPS9 caps; if (mDeviceEx && mDeviceEx->GetDeviceCaps(&caps)) { if (LACKS_CAP(caps.Caps2, D3DCAPS2_DYNAMICTEXTURES)) { // XXX - Should we actually hit this we'll need a CanvasLayer that // supports static D3DPOOL_DEFAULT textures. NS_WARNING("D3D9Ex device not used because of lack of support for \ dynamic textures. This is unexpected."); mDevice = nsnull; mDeviceEx = nsnull; } } }
void winopen() { WNDCLASS wc; HMENU menu; RECT r; ATOM a; /* Create and register window frame class */ memset(&wc, 0, sizeof(wc)); wc.style = 0; wc.lpfnWndProc = frameproc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetModuleHandle(NULL); wc.hIcon = LoadIconA(wc.hInstance, "IDI_ICONAPP"); wc.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = L"FrameWindow"; a = RegisterClassW(&wc); if (!a) winerror(&gapp, "cannot register frame window class"); /* Create and register window view class */ memset(&wc, 0, sizeof(wc)); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = viewproc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetModuleHandle(NULL); wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = L"ViewWindow"; a = RegisterClassW(&wc); if (!a) winerror(&gapp, "cannot register view window class"); /* Get screen size */ SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0); gapp.scrw = r.right - r.left; gapp.scrh = r.bottom - r.top; /* Create cursors */ arrowcurs = LoadCursor(NULL, IDC_ARROW); handcurs = LoadCursor(NULL, IDC_HAND); waitcurs = LoadCursor(NULL, IDC_WAIT); caretcurs = LoadCursor(NULL, IDC_IBEAM); /* And a background color */ bgbrush = CreateSolidBrush(RGB(0x70,0x70,0x70)); shbrush = CreateSolidBrush(RGB(0x40,0x40,0x40)); /* Init DIB info for buffer */ dibinf = malloc(sizeof(BITMAPINFO) + 12); assert(dibinf); dibinf->bmiHeader.biSize = sizeof(dibinf->bmiHeader); dibinf->bmiHeader.biPlanes = 1; dibinf->bmiHeader.biBitCount = 32; dibinf->bmiHeader.biCompression = BI_RGB; dibinf->bmiHeader.biXPelsPerMeter = 2834; dibinf->bmiHeader.biYPelsPerMeter = 2834; dibinf->bmiHeader.biClrUsed = 0; dibinf->bmiHeader.biClrImportant = 0; dibinf->bmiHeader.biClrUsed = 0; /* Create window */ hwndframe = CreateWindowW(L"FrameWindow", // window class name NULL, // window caption WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, // initial position 300, // initial x size 300, // initial y size 0, // parent window handle 0, // window menu handle 0, // program instance handle 0); // creation parameters if (!hwndframe) winerror(&gapp, "cannot create frame"); hwndview = CreateWindowW(L"ViewWindow", // window class name NULL, WS_VISIBLE | WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndframe, 0, 0, 0); if (!hwndview) winerror(&gapp, "cannot create view"); hdc = NULL; SetWindowTextW(hwndframe, L"MuPDF"); menu = GetSystemMenu(hwndframe, 0); AppendMenuW(menu, MF_SEPARATOR, 0, NULL); AppendMenuW(menu, MF_STRING, ID_ABOUT, L"About MuPDF..."); AppendMenuW(menu, MF_STRING, ID_DOCINFO, L"Document Properties..."); SetCursor(arrowcurs); }
int gui_main(char const* (*gen_)(int), void (*poll_)(), void(*stop_)()) //(int ac, char* const av[]) { GdiFont* font; struct nk_context *ctx; WNDCLASSW wc; ATOM atom; RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT }; DWORD style = WS_OVERLAPPEDWINDOW; DWORD exstyle = WS_EX_APPWINDOW; HWND wnd; HDC dc; int running = 1; int needs_refresh = 1; /* Win32 */ memset(&wc, 0, sizeof(wc)); wc.lpfnWndProc = WindowProc; wc.hInstance = GetModuleHandleW(0); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = L"NuklearWindowClass"; atom = RegisterClassW(&wc); AdjustWindowRectEx(&rect, style, FALSE, exstyle); wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Lucky", style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, wc.hInstance, NULL); dc = GetDC(wnd); /* GUI */ font = nk_gdifont_create("Arial", 14); ctx = nk_gdi_init(font, dc, WINDOW_WIDTH, WINDOW_HEIGHT); while (running) { MSG msg; poll_(); /* Input */ nk_input_begin(ctx); if (needs_refresh == 0) { if (GetMessageW(&msg, NULL, 0, 0) <= 0) { running = 0; } else { TranslateMessage(&msg); DispatchMessageW(&msg); } needs_refresh = 1; } else { needs_refresh = 0; } while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) running = 0; TranslateMessage(&msg); DispatchMessageW(&msg); needs_refresh = 1; } nk_input_end(ctx); /* GUI */ {struct nk_panel layout; if (nk_begin(ctx, &layout, "Demo", nk_rect(60, 0, 120, 320), 0)) //NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE { enum {EASY, HARD}; static int op = EASY; static int property = 20; //nk_layout_row_static(ctx, 30, 80, 1); nk_layout_row_dynamic(ctx, 30, 1); if (nk_button_label(ctx, "三码", NK_BUTTON_DEFAULT)) { notepad_open(gen_(3)); } if (nk_button_label(ctx, "二码", NK_BUTTON_DEFAULT)) { notepad_open(gen_(2)); } if (nk_button_label(ctx, "one", NK_BUTTON_DEFAULT)) { notepad_open(gen_(1)); } #if 0 if (nk_button_label(ctx, "四码", NK_BUTTON_DEFAULT)) { notepad_open(gen_(4)); } if (nk_button_label(ctx, "五码", NK_BUTTON_DEFAULT)) { notepad_open(gen_(5)); } if (nk_button_label(ctx, "六码", NK_BUTTON_DEFAULT)) { notepad_open(gen_(6)); } if (nk_button_label(ctx, "七码", NK_BUTTON_DEFAULT)) { notepad_open(gen_(7)); } if (nk_button_label(ctx, "八码", NK_BUTTON_DEFAULT)) { notepad_open(gen_(8)); } if (nk_button_label(ctx, "九码", NK_BUTTON_DEFAULT)) { notepad_open(gen_(9)); } if (nk_button_label(ctx, "十码", NK_BUTTON_DEFAULT)) { notepad_open(gen_(10)); } #endif //nk_layout_row_dynamic(ctx, 30, 2); //if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; //if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; //nk_layout_row_dynamic(ctx, 22, 1); //nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } nk_end(ctx);} if (nk_window_is_closed(ctx, "Demo")) break; /* Draw */ nk_gdi_render(nk_rgb(30,30,30)); } stop_(); nk_gdifont_del(font); ReleaseDC(wnd, dc); UnregisterClassW(wc.lpszClassName, wc.hInstance); return 0; }
/// <summary> /// Creates the main window and begins processing /// </summary> /// <param name="hInstance">handle to the application instance</param> /// <param name="nCmdShow">whether to display minimized, maximized, or normally</param> int CCoordinateMappingBasics::Run(HINSTANCE hInstance, int nCmdShow) { if (m_pBackgroundRGBX) { //if (FAILED(LoadResourceImage(L"Background", L"Image", cDepthWidth, cDepthHeight, m_pBackgroundRGBX))) //if (FAILED(LoadResourceImage(MAKEINTRESOURCE(IDB_BITMAP1), RT_BITMAP, cDepthWidth, cDepthHeight, m_pBackgroundRGBX))) if (FAILED(LoadResourceImage(MAKEINTRESOURCE(IDB_PNG1), L"Png", cDepthWidth, cDepthHeight, m_pBackgroundRGBX))) { delete [] m_pBackgroundRGBX; m_pBackgroundRGBX = NULL; } } MSG msg = {0}; WNDCLASS wc; // Dialog custom window class ZeroMemory(&wc, sizeof(wc)); wc.style = CS_HREDRAW | CS_VREDRAW; wc.cbWndExtra = DLGWINDOWEXTRA; wc.hCursor = LoadCursorW(NULL, IDC_ARROW); wc.hIcon = LoadIconW(hInstance, MAKEINTRESOURCE(IDI_APP)); wc.lpfnWndProc = DefDlgProcW; wc.lpszClassName = L"CoordinateMappingBasicsAppDlgWndClass"; if (!RegisterClassW(&wc)) { return 0; } // Create main application window HWND hWndApp = CreateDialogParamW( NULL, MAKEINTRESOURCE(IDD_APP), NULL, (DLGPROC)CCoordinateMappingBasics::MessageRouter, reinterpret_cast<LPARAM>(this)); // Show window ShowWindow(hWndApp, nCmdShow); // Main message loop while (WM_QUIT != msg.message) { Update(); while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { // If a dialog message will be taken care of by the dialog proc if (hWndApp && IsDialogMessageW(hWndApp, &msg)) { continue; } TranslateMessage(&msg); DispatchMessageW(&msg); } } return static_cast<int>(msg.wParam); }
int main(void) { WNDCLASSW wc; HWND mainwin; RECT r; INITCOMMONCONTROLSEX icc; MSG msg; ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX)); icc.dwSize = sizeof (INITCOMMONCONTROLSEX); icc.dwICC = ICC_PROGRESS_CLASS | ICC_PROGRESS_CLASS | ICC_USEREX_CLASSES; if (InitCommonControlsEx(&icc) == 0) abort(); ZeroMemory(&wc, sizeof (WNDCLASSEX)); wc.lpszClassName = L"mainwin"; wc.lpfnWndProc = wndproc; wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); if (RegisterClassW(&wc) == 0) abort(); r.left = 0; r.top = 0; r.right = 10 + 400 + 10; r.bottom = 10 + 20 + 5 + 20 + 5 + 20 + 10; if (AdjustWindowRectEx(&r, WS_OVERLAPPEDWINDOW, FALSE, 0) == 0) abort(); mainwin = CreateWindowExW(0, L"mainwin", L"Main Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL); if (mainwin == NULL) abort(); pbar = CreateWindowExW(0, PROGRESS_CLASSW, L"", PBS_SMOOTH | WS_CHILD | WS_VISIBLE, 10, 10, 400, 20, mainwin, NULL, NULL, NULL); if (pbar == NULL) abort(); SendMessageW(pbar, PBM_SETRANGE32, 0, 100); SendMessageW(pbar, PBM_SETPOS, 0, 0); SendMessageW(pbar, PBM_SETSTATE, (WPARAM) PBST_NORMAL, 0); slider = CreateWindowExW(0, TRACKBAR_CLASSW, L"", TBS_HORZ | TBS_TOOLTIPS | TBS_TRANSPARENTBKGND | WS_TABSTOP | WS_CHILD | WS_VISIBLE, 10, 10 + 20 + 5, 400, 20, mainwin, NULL, NULL, NULL); if (slider == NULL) abort(); SendMessageW(slider, TBM_SETRANGEMIN, (WPARAM) TRUE, 0); SendMessageW(slider, TBM_SETRANGEMAX, (WPARAM) TRUE, 100); SendMessageW(slider, TBM_SETPOS, (WPARAM) TRUE, 0); state = CreateWindowExW(0, WC_COMBOBOXEXW, L"", CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE, 10, 10 + 20 + 5 + 20 + 5, 400, 20, mainwin, NULL, NULL, NULL); if (state == NULL) abort(); addItem(L"Normal"); addItem(L"Error"); addItem(L"Paused"); addItem(L"4 (PBFS_PARTIAL)"); addItem(L"0 (PBFS_PARTIAL)"); if (SendMessageW(state, CB_SETCURSEL, 0, 0) == (LRESULT) (CB_ERR)) abort(); ShowWindow(mainwin, SW_SHOWDEFAULT); UpdateWindow(mainwin); while (GetMessageW(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessageW(&msg); } return 0; }
bool DeviceManagerD3D9::Init() { WNDCLASSW wc; HRESULT hr; if (!GetClassInfoW(GetModuleHandle(nullptr), kClassName, &wc)) { ZeroMemory(&wc, sizeof(WNDCLASSW)); wc.hInstance = GetModuleHandle(nullptr); wc.lpfnWndProc = ::DefWindowProc; wc.lpszClassName = kClassName; if (!RegisterClassW(&wc)) { gfxCriticalError() << "[D3D9] Failed to register class for DeviceManager"; return false; } } mFocusWnd = ::CreateWindowW(kClassName, L"D3D9Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, GetModuleHandle(nullptr), nullptr); if (!mFocusWnd) { gfxCriticalError() << "[D3D9] Failed to create a window"; return false; } if (gfxPrefs::StereoVideoEnabled()) { /* Create an Nv3DVUtils instance */ if (!mNv3DVUtils) { mNv3DVUtils = new Nv3DVUtils(); if (!mNv3DVUtils) { NS_WARNING("Could not create a new instance of Nv3DVUtils."); } } /* Initialize the Nv3DVUtils object */ if (mNv3DVUtils) { mNv3DVUtils->Initialize(); } } HMODULE d3d9 = LoadLibraryW(L"d3d9.dll"); decltype(Direct3DCreate9)* d3d9Create = (decltype(Direct3DCreate9)*) GetProcAddress(d3d9, "Direct3DCreate9"); decltype(Direct3DCreate9Ex)* d3d9CreateEx = (decltype(Direct3DCreate9Ex)*) GetProcAddress(d3d9, "Direct3DCreate9Ex"); #ifdef USE_D3D9EX if (d3d9CreateEx) { hr = d3d9CreateEx(D3D_SDK_VERSION, getter_AddRefs(mD3D9Ex)); if (SUCCEEDED(hr)) { mD3D9 = mD3D9Ex; } } #endif if (!mD3D9) { if (!d3d9Create) { gfxCriticalError() << "[D3D9] Failed to load symbols"; return false; } mD3D9 = dont_AddRef(d3d9Create(D3D_SDK_VERSION)); if (!mD3D9) { gfxCriticalError() << "[D3D9] Failed to create the IDirect3D9 object"; return false; } } D3DADAPTER_IDENTIFIER9 ident; hr = mD3D9->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &ident); if (FAILED(hr)) { gfxCriticalError() << "[D3D9] Failed to create the environment code: " << gfx::hexa(hr); return false; } D3DPRESENT_PARAMETERS pp; memset(&pp, 0, sizeof(D3DPRESENT_PARAMETERS)); pp.BackBufferWidth = 1; pp.BackBufferHeight = 1; pp.BackBufferFormat = D3DFMT_A8R8G8B8; pp.SwapEffect = D3DSWAPEFFECT_DISCARD; pp.Windowed = TRUE; pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; pp.hDeviceWindow = mFocusWnd; if (mD3D9Ex) { hr = mD3D9Ex->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mFocusWnd, D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED | D3DCREATE_MIXED_VERTEXPROCESSING, &pp, nullptr, getter_AddRefs(mDeviceEx)); if (SUCCEEDED(hr)) { mDevice = mDeviceEx; } D3DCAPS9 caps; if (mDeviceEx && mDeviceEx->GetDeviceCaps(&caps)) { if (LACKS_CAP(caps.Caps2, D3DCAPS2_DYNAMICTEXTURES)) { // XXX - Should we actually hit this we'll need a CanvasLayer that // supports static D3DPOOL_DEFAULT textures. NS_WARNING("D3D9Ex device not used because of lack of support for \ dynamic textures. This is unexpected."); mDevice = nullptr; mDeviceEx = nullptr; } } }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { WNDCLASSW wc; HWND hWnd; WCHAR WindowTextW[256]; char WindowTextA[256]; wc.lpszClassName = L"UnicodeClass"; wc.lpfnWndProc = UnicodeWndProc; wc.style = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.cbClsExtra = 0; wc.cbWndExtra = 0; if (RegisterClassW(&wc) == 0) { fprintf(stderr, "RegisterClassW failed (last error 0x%lu)\n", GetLastError()); return 1; } printf("Unicode class registered, WndProc = 0x%p\n", wc.lpfnWndProc); hWnd = CreateWindowA("UnicodeClass", "Unicode Window", WS_OVERLAPPEDWINDOW, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (hWnd == NULL) { fprintf(stderr, "CreateWindowA failed (last error 0x%lu)\n", GetLastError()); return 1; } printf("Window created, IsWindowUnicode returns %s\n", IsWindowUnicode(hWnd) ? "TRUE" : "FALSE"); printf("Calling GetWindowTextW\n"); if (! GetWindowTextW(hWnd, WindowTextW, sizeof(WindowTextW) / sizeof(WindowTextW[0]))) { fprintf(stderr, "GetWindowTextW failed (last error 0x%lu)\n", GetLastError()); return 1; } printf("GetWindowTextW returned Unicode string \"%S\"\n", WindowTextW); printf("Calling GetWindowTextA\n"); if (! GetWindowTextA(hWnd, WindowTextA, sizeof(WindowTextA) / sizeof(WindowTextA[0]))) { fprintf(stderr, "GetWindowTextA failed (last error 0x%lu)\n", GetLastError()); return 1; } printf("GetWindowTextA returned Ansi string \"%s\"\n", WindowTextA); printf("\n"); SavedWndProcW = (WNDPROC) GetWindowLongW(hWnd, GWL_WNDPROC); printf("GetWindowLongW returned 0x%p\n", SavedWndProcW); SavedWndProcA = (WNDPROC) GetWindowLongA(hWnd, GWL_WNDPROC); printf("GetWindowLongA returned 0x%p\n", SavedWndProcA); printf("\n"); printf("Subclassing window using SetWindowLongW, new WndProc 0x%p\n", UnicodeSubclassProc); SetWindowLongW(hWnd, GWL_WNDPROC, (LONG) UnicodeSubclassProc); printf("After subclass, IsWindowUnicode %s, WndProcA 0x%lx, WndProcW 0x%lx\n", IsWindowUnicode(hWnd) ? "TRUE" : "FALSE", GetWindowLongA(hWnd, GWL_WNDPROC), GetWindowLongW(hWnd, GWL_WNDPROC)); printf("Calling GetWindowTextW\n"); if (! GetWindowTextW(hWnd, WindowTextW, sizeof(WindowTextW) / sizeof(WindowTextW[0]))) { fprintf(stderr, "GetWindowTextW failed (last error 0x%lu)\n", GetLastError()); return 1; } printf("GetWindowTextW returned Unicode string \"%S\"\n", WindowTextW); printf("\n"); printf("Subclassing window using SetWindowLongA, new WndProc 0x%p\n", AnsiSubclassProc); SetWindowLongA(hWnd, GWL_WNDPROC, (LONG) AnsiSubclassProc); printf("After subclass, IsWindowUnicode %s, WndProcA 0x%lx, WndProcW 0x%lx\n", IsWindowUnicode(hWnd) ? "TRUE" : "FALSE", GetWindowLongA(hWnd, GWL_WNDPROC), GetWindowLongW(hWnd, GWL_WNDPROC)); printf("Calling GetWindowTextW\n"); if (! GetWindowTextW(hWnd, WindowTextW, sizeof(WindowTextW) / sizeof(WindowTextW[0]))) { fprintf(stderr, "GetWindowTextW failed (last error 0x%lu)\n", GetLastError()); return 1; } printf("GetWindowTextW returned Unicode string \"%S\"\n", WindowTextW); DestroyWindow(hWnd); return 0; }
static qboolean VID_CreateWindow( void ) { #define WITH_UTF8 // FIXME: turn non-Unicode code into a runtime fallback for Win9x #ifndef WITH_UTF8 WNDCLASS wc; #else WNDCLASSW wc; qboolean fullscreen = glState.fullScreen; HWND parentHWND = glw_state.parenthWnd; /* determine buffer size required for the unicode string */ WCHAR windowClassName[sizeof(WINDOW_CLASS_NAME)] = L""; MultiByteToWideChar( CP_ACP, 0, WINDOW_CLASS_NAME, -1, windowClassName, sizeof( windowClassName )-1 ); #endif /* 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 = LoadIcon( glw_state.hInstance, MAKEINTRESOURCE( IDI_APPICON_VALUE ) ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( GRAY_BRUSH ); wc.lpszMenuName = 0; #ifdef WITH_UTF8 wc.lpszClassName = (LPCWSTR)windowClassName; if( !RegisterClassW( &wc ) ) #else wc.lpszClassName = (LPCSTR)WINDOW_CLASS_NAME; if( !RegisterClass( &wc ) ) #endif Com_Error( ERR_FATAL, "Couldn't register window class" ); glw_state.hWnd = CreateWindowEx( 0, WINDOW_CLASS_NAME, APPLICATION, 0, 0, 0, 0, 0, parentHWND, NULL, glw_state.hInstance, NULL ); if( !glw_state.hWnd ) Com_Error( ERR_FATAL, "Couldn't create window" ); VID_SetWindowSize( fullscreen ); // init all the gl stuff for the window if( !GLimp_InitGL() ) { Com_Printf( "VID_CreateWindow() - GLimp_InitGL failed\n" ); return qfalse; } if( glw_state.parenthWnd ) PostMessage( glw_state.parenthWnd, UWM_APPACTIVE, WA_ACTIVE, 0 ); return qtrue; }
void Ctrl::InitWin32(HINSTANCE hInstance) { GuiLock __; LLOG("InitWin32"); InstallPanicMessageBox(&Win32PanicMessageBox); // RLOGBLOCK("Ctrl::InitWin32"); sMainThreadId = GetCurrentThreadId(); #define ILOG(x) // RLOG(x) Ctrl::hInstance = hInstance; ILOG("RegisterClassW"); #ifndef PLATFORM_WINCE if(IsWinNT()) #endif { WNDCLASSW wc; Zero(wc); wc.style = CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)Ctrl::WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = IsWinVista() ? (HBRUSH)(COLOR_WINDOW+1) : (HBRUSH)NULL; wc.lpszClassName = L"UPP-CLASS-W"; RegisterClassW(&wc); wc.style = 0x20000|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW; wc.lpszClassName = L"UPP-CLASS-DS-W"; RegisterClassW(&wc); wc.style = CS_SAVEBITS|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW; wc.lpszClassName = L"UPP-CLASS-SB-W"; RegisterClassW(&wc); wc.style = 0x20000|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW|CS_SAVEBITS; wc.lpszClassName = L"UPP-CLASS-SB-DS-W"; RegisterClassW(&wc); } ILOG("RegisterClassA"); WNDCLASS wc; Zero(wc); wc.style = CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)Ctrl::WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = IsWinVista() ? (HBRUSH)(COLOR_WINDOW+1) : (HBRUSH)NULL; wc.lpszClassName = L_("UPP-CLASS-A"); RegisterClass(&wc); if(IsWinXP()) { wc.style = 0x20000|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW; wc.lpszClassName = L_("UPP-CLASS-DS-A"); RegisterClass(&wc); } wc.style = CS_SAVEBITS|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW; wc.lpszClassName = L_("UPP-CLASS-SB-A"); RegisterClass(&wc); if(IsWinXP()) { wc.style = 0x20000|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW|CS_SAVEBITS; wc.lpszClassName = L_("UPP-CLASS-SB-DS-A"); RegisterClass(&wc); } wc.style = 0; wc.lpszClassName = L_("UPP-TIMER"); wc.hCursor = NULL; wc.lpfnWndProc = &Ctrl::UtilityProc; RegisterClass(&wc); ILOG("InitTimer"); InitTimer(); ILOG("SetTimer"); utilityHWND = CreateWindow(L_("UPP-TIMER"), L_(""), WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); SetTimer(utilityHWND, 1, 10, NULL); ILOG("Windows"); Windows(); //?? TRC: what's the use of this? ReSkin(); OleInitialize(NULL); /* TRC 05/11/14: moved to GuiSleep to avoid thread creation in OCX DllMain DWORD dummy; OverwatchThread = CreateThread(NULL, 0x100000, Win32OverwatchThread, NULL, 0, &dummy); ExitLoopEvent().Wait(); */ // TRC 05/11/18: pSetLayeredWindowAttributes moved to GLOBAL_VAR (see below) to make OCX initialization simpler Csizeinit(); #undef ILOG if(IsWin7()) GlobalBackPaint(); }
static bool VID_CreateWindow( void ) { bool fullscreen = glConfig.fullScreen; HWND parentHWND = glw_state.parenthWnd; #ifdef WITH_UTF8 WNDCLASSW wc; #else WNDCLASS wc; #endif Q_snprintfz( glw_state.windowClassName, sizeof( glw_state.windowClassName ), "%sWndClass", glw_state.applicationName ); #ifdef WITH_UTF8 MultiByteToWideChar( CP_UTF8, 0, glw_state.windowClassName, -1, glw_state.windowClassNameW, sizeof( glw_state.windowClassNameW ) ); glw_state.windowClassNameW[sizeof( glw_state.windowClassNameW )/sizeof( glw_state.windowClassNameW[0] ) - 1] = 0; #endif /* 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 = LoadIcon( glw_state.hInstance, MAKEINTRESOURCE( glw_state.applicationIconResourceID ) ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ); wc.lpszMenuName = 0; #ifdef WITH_UTF8 wc.lpszClassName = (LPCWSTR)glw_state.windowClassNameW; if( !RegisterClassW( &wc ) ) #else wc.lpszClassName = (LPCSTR)glw_state.windowClassName; if( !RegisterClass( &wc ) ) #endif Sys_Error( "Couldn't register window class" ); glw_state.hWnd = #ifdef WITH_UTF8 CreateWindowExW( #else CreateWindowEx( #endif 0, #ifdef WITH_UTF8 glw_state.windowClassNameW, glw_state.applicationNameW, #else glw_state.windowClassName, glw_state.applicationName, #endif 0, 0, 0, 0, 0, parentHWND, NULL, glw_state.hInstance, NULL ); if( !glw_state.hWnd ) Sys_Error( "Couldn't create window" ); VID_SetWindowSize( fullscreen ); // init all the gl stuff for the window if( !GLimp_InitGL() ) { ri.Com_Printf( "VID_CreateWindow() - GLimp_InitGL failed\n" ); return false; } return true; }