static HWND InitInstance(HINSTANCE hInst) { WCHAR szClass[] = L"CharMap"; WCHAR szTitle[256]; WNDCLASSEXW wc; HWND hWnd; LoadStringW(hInst, IDS_TITLE, szTitle, SIZEOF(szTitle)); hSmIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0); hBgIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0); // Create workspace ZeroMemory(&wc, sizeof(wc)); wc.cbSize = sizeof(wc); wc.lpfnWndProc = PanelWndProc; wc.hInstance = hInst; wc.hIcon = hBgIcon; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = szClass; wc.hIconSm = hSmIcon; RegisterClassExW(&wc); hWnd = CreateWindowW( szClass, szTitle, WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL); if (hWnd != NULL) { LoadSettings(); ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); } return hWnd; }
INT Test_NtGdiGetRandomRgn(PTESTINFO pti) { HWND hWnd; HDC hDC; HRGN hrgn, hrgn2; /* Create a window */ hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, g_hInstance, 0); // UpdateWindow(hWnd); hDC = GetDC(hWnd); ASSERT(hDC != NULL); hrgn = CreateRectRgn(0,0,0,0); hrgn2 = CreateRectRgn(3,3,10,10); SetLastError(ERROR_SUCCESS); RTEST(NtGdiGetRandomRgn(0, hrgn, 0) == -1); RTEST(GetLastError() == ERROR_INVALID_HANDLE); SetLastError(ERROR_SUCCESS); RTEST(NtGdiGetRandomRgn((HDC)2345, hrgn, 1) == -1); RTEST(GetLastError() == ERROR_INVALID_HANDLE); SetLastError(ERROR_SUCCESS); RTEST(NtGdiGetRandomRgn((HDC)2345, hrgn, 10) == -1); RTEST(GetLastError() == ERROR_INVALID_HANDLE); SetLastError(ERROR_SUCCESS); RTEST(NtGdiGetRandomRgn((HDC)2345, (HRGN)10, 10) == -1); RTEST(GetLastError() == ERROR_INVALID_HANDLE); SetLastError(ERROR_SUCCESS); RTEST(NtGdiGetRandomRgn((HDC)2345, 0, 1) == -1); RTEST(GetLastError() == ERROR_INVALID_HANDLE); SetLastError(ERROR_SUCCESS); RTEST(NtGdiGetRandomRgn(hDC, 0, 0) == 0); RTEST(NtGdiGetRandomRgn(hDC, 0, 1) == 0); RTEST(NtGdiGetRandomRgn(hDC, (HRGN)-5, 0) == 0); RTEST(NtGdiGetRandomRgn(hDC, (HRGN)-5, 1) == 0); RTEST(NtGdiGetRandomRgn(hDC, hrgn, 0) == 0); RTEST(NtGdiGetRandomRgn(hDC, hrgn, 1) == 0); TEST(NtGdiGetRandomRgn(hDC, hrgn, 2) == 0); RTEST(NtGdiGetRandomRgn(hDC, hrgn, 3) == 0); RTEST(NtGdiGetRandomRgn(hDC, hrgn, 4) == 1); RTEST(NtGdiGetRandomRgn(hDC, hrgn, 5) == 0); RTEST(NtGdiGetRandomRgn(hDC, hrgn, 10) == 0); RTEST(NtGdiGetRandomRgn(hDC, hrgn, -10) == 0); RTEST(GetLastError() == ERROR_SUCCESS); SelectClipRgn(hDC, hrgn2); RTEST(NtGdiGetRandomRgn(hDC, 0, 1) == -1); RTEST(GetLastError() == ERROR_SUCCESS); RTEST(NtGdiGetRandomRgn(hDC, hrgn, 1) == 1); RTEST(CombineRgn(hrgn, hrgn, hrgn, RGN_OR) == SIMPLEREGION); RTEST(CombineRgn(hrgn, hrgn, hrgn2, RGN_XOR) == NULLREGION); SetRectRgn(hrgn2,0,0,0,0); SelectClipRgn(hDC, hrgn2); RTEST(NtGdiGetRandomRgn(hDC, hrgn, 1) == 1); RTEST(CombineRgn(hrgn2, hrgn, hrgn2, RGN_XOR) == NULLREGION); RTEST(CombineRgn(hrgn2, hrgn, hrgn, RGN_OR) == NULLREGION); SelectClipRgn(hDC, NULL); RTEST(NtGdiGetRandomRgn(hDC, hrgn, 1) == 0); RTEST(NtGdiGetRandomRgn(hDC, hrgn, 4) == 1); RTEST(GetLastError() == ERROR_SUCCESS); ReleaseDC(hWnd, hDC); DestroyWindow(hWnd); return APISTATUS_NORMAL; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { HINSTANCE hInstance = GetModuleHandle(NULL); static HWND hLabel, hStaticKey, hStaticValue, hWndList; static person_t person1 = NULL, person2 = NULL, person3 = NULL, person4 = NULL; switch (msg) { case WM_CREATE: { hLabel = CreateWindowEx( 0, (TCHAR*)"STATIC", (TCHAR*)"List of persons", WS_CHILD | WS_VISIBLE, 10, 10, 100, 26, hwnd, (HMENU)ID_LABEL, hInstance, NULL ); hStaticKey = CreateWindowEx(0, WC_STATIC, "Name", WS_CHILD | WS_VISIBLE, 220, 40, 170, 23, hwnd, (HMENU)HSTATICKEY, hInstance, NULL); hStaticValue = CreateWindowEx(0, WC_STATIC, "Value", WS_CHILD | WS_VISIBLE, 220, 70, 170, 23, hwnd, (HMENU)HSTATICVALUE, hInstance, NULL); hWndList = CreateWindowW( L"listbox", L"Update timer", WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_AUTOVSCROLL | WS_BORDER | LBS_NOTIFY, 10, 40, 185, 125, hwnd, (HMENU)ID_LB, NULL, NULL ); person1 = person_new("Ivan", "Ivanov", 1995); person_insertToList(person1, hWndList); person2 = person_new("Petr", "Petrov", 1944); person_insertToList(person2, hWndList); person3 = person_new("Dmitriy", "Dmitrenko", 1986); person_insertToList(person3, hWndList); person4 = person_new("Maxim", "Maximov", 1954); person_insertToList(person4, hWndList); } break; case WM_COMMAND: { switch (LOWORD(wParam)) { case ID_LB: switch (HIWORD(wParam)) { case LBN_SELCHANGE: { HWND hLabel = GetDlgItem(hwnd, ID_LABEL); HWND control = GetDlgItem(hwnd, ID_LB); char text[256]; int count = SendMessage(control, LB_GETCOUNT, 0, 0); int iSelected = -1; for (int i = 0; i < count; i++) { if (SendMessage(control, LB_GETSEL, i, 0) > 0) { iSelected = i; char key[100] = ""; SendMessage(control, LB_GETTEXT, (WPARAM)iSelected, (LPARAM)key); SetWindowText(hStaticKey, key); char * value = (char*)SendMessage(control, LB_GETITEMDATA, (WPARAM)iSelected, 0); SetWindowText(hStaticValue, value); } } } break; } break; } } break; case WM_CLOSE: DestroyWindow(hwnd); DestroyWindow(hStaticKey); DestroyWindow(hStaticValue); DestroyWindow(hWndList); DestroyWindow(hLabel); person_free(person1); person_free(person2); person_free(person3); person_free(person4); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }
void OpenGLWindow::Impl::create(unsigned w, unsigned h, const std::string& title) { DWORD win32_style = 0; int x; int y; int width = static_cast<int>(w); int height = static_cast<int>(h); //TODO: Make window style ! bool fullscreen = false; bool frame = true; bool resizable = true; bool closable = true; if (fullscreen) { DEVMODE win32_mode; std::memset(&win32_mode, 0, sizeof(DEVMODE)); //TODO: Make these parameters custom win32_mode.dmBitsPerPel = 32; win32_mode.dmPelsWidth = width; win32_mode.dmPelsHeight = height; win32_mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; win32_mode.dmSize = sizeof(DEVMODE); m_fullscreen = true; if (ChangeDisplaySettings(&win32_mode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) ATEMA_ERROR("Video mode not supported."); } else { RECT rectangle = { 0, 0, width, height }; win32_style |= WS_VISIBLE; if (frame) { win32_style |= WS_CAPTION | WS_MINIMIZEBOX; if (resizable) win32_style |= WS_MAXIMIZEBOX | WS_SIZEBOX; if (closable) win32_style |= WS_SYSMENU; } else { win32_style |= WS_POPUP; } AdjustWindowRect(&rectangle, win32_style, false); width = rectangle.right - rectangle.left; height = rectangle.bottom - rectangle.top; m_fullscreen = false; } x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2; y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2; std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; std::wstring name_w = converter.from_bytes(title.c_str()); m_handle = CreateWindowW(ATEMA_CLASS_NAME, name_w.data(), win32_style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), this); HCURSOR cursor = static_cast<HCURSOR>(LoadImage(nullptr, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED)); SetCursor(cursor); createContext(); }
//-------------------------------------------------------------------------- void WindowsWindow::Init(WindowsVideo& kVideo, const char* pcTitle, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t u32Flags) { Term(); LPWSTR lpwstrTitle = WindowsVideo::UTF8ToWSTR(pcTitle); DWORD dwStyle = FlagsToWindowStyle(u32Flags); int32_t flag_x = x >> 28; int32_t flag_y = y >> 28; x = flag_x ? 0 : x; y = flag_y ? 0 : y; RECT windowRect = { x, y, w, h }; AdjustWindowRect(&windowRect, dwStyle, FALSE); VE_ASSERT(w > 0 && w < UINT16_MAX && h > 0 && h < UINT16_MAX); m_u16Width = (uint16_t)w; m_u16Height = (uint16_t)h; w = windowRect.right - windowRect.left; h = windowRect.bottom - windowRect.top; switch (flag_x) { case 1: x = CW_USEDEFAULT; break; case 2: x = (GetSystemMetrics(SM_CXSCREEN) - w) >> 1; break; default: x = windowRect.left; break; } switch (flag_y) { case 1: y = CW_USEDEFAULT; break; case 2: y = (GetSystemMetrics(SM_CYSCREEN) - h) >> 1; break; default: y = windowRect.top; break; } x = x == CW_USEDEFAULT ? x : vtd::max(x, 0); y = y == CW_USEDEFAULT ? y : vtd::max(y, 0); m_hHandle = CreateWindowW(kVideo.m_wstrClassName, lpwstrTitle, dwStyle, x, y, w, h, nullptr, nullptr, kVideo.m_hInstance, this); VeFree(lpwstrTitle); if (!m_hHandle) { m_u16Width = 0; m_u16Height = 0; THROW("Couldn't create window"); } if (VE_MASK_HAS_ALL(u32Flags, VE_WINDOW_SHOWN)) { int32_t i32Show = SW_SHOW; if (VE_MASK_HAS_ALL(dwStyle, WS_THICKFRAME)) { switch (u32Flags & 0xF) { case VE_WINDOW_MINIMIZED: i32Show = SW_SHOWMINIMIZED; break; case VE_WINDOW_MAXIMIZED: i32Show = SW_SHOWMAXIMIZED; break; case VE_WINDOW_DEPSTARTUP: i32Show = kVideo.m_i32CmdShow; break; default: break; } } ShowWindow(m_hHandle, i32Show); } m_u32Flags = u32Flags & (VE_WINDOW_ALLOW_HIGHDPI | VE_WINDOW_FOREIGN); UpdateFlags(); kVideo.m_kWindowList.attach_back(m_kNode); }
/* Show the window */ int text_create(TW *tw, const char *app_name, int show_cmd) { HMENU sysmenu; HINSTANCE hInstance = GetModuleHandle(NULL); #ifndef GS_NO_UTF8 wchar_t *app_nameW, *d; const char *s; app_nameW = malloc(strlen(app_name)*2+2); if (app_nameW == NULL) { text_error("Out of memory"); return 1; } d = app_nameW; s = app_name; while ((*d++ = (wchar_t)(unsigned char)(*s++)) != 0); tw->TitleW = app_nameW; #endif tw->Title = app_name; tw->nCmdShow = show_cmd; tw->quitnow = FALSE; /* make sure we have some sensible defaults */ if (tw->KeyBufSize < 256) tw->KeyBufSize = 256; tw->CursorPos.x = tw->CursorPos.y = 0; tw->bFocus = FALSE; tw->bGetCh = FALSE; tw->CaretHeight = 0; /* allocate buffers */ tw->KeyBufIn = tw->KeyBufOut = tw->KeyBuf = malloc(tw->KeyBufSize); if (tw->KeyBuf == NULL) { text_error("Out of memory"); return 1; } tw->ScreenBuffer = malloc(tw->ScreenSize.x * tw->ScreenSize.y * CHARSIZE); if (tw->ScreenBuffer == NULL) { text_error("Out of memory"); return 1; } #ifdef GS_NO_UTF8 memset(tw->ScreenBuffer, ' ', tw->ScreenSize.x * tw->ScreenSize.y); #else wmemset(tw->ScreenBuffer, ' ', tw->ScreenSize.x * tw->ScreenSize.y); #endif #ifdef GS_NO_UTF8 tw->hwnd = CreateWindow(TextWinClassName, tw->Title, WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL, tw->x, tw->y, tw->cx, tw->cy, NULL, NULL, hInstance, tw); #else tw->hwnd = CreateWindowW(TextWinClassName, app_nameW, WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL, tw->x, tw->y, tw->cx, tw->cy, NULL, NULL, hInstance, tw); #endif if (tw->hwnd == NULL) { MessageBoxA((HWND)NULL,"Couldn't open text window",(LPSTR)NULL, MB_ICONHAND | MB_SYSTEMMODAL); return 1; } ShowWindow(tw->hwnd, tw->nCmdShow); sysmenu = GetSystemMenu(tw->hwnd,0); /* get the sysmenu */ AppendMenu(sysmenu, MF_SEPARATOR, 0, NULL); AppendMenuA(sysmenu, MF_STRING, M_COPY_CLIP, "Copy to Clip&board"); AppendMenuA(sysmenu, MF_STRING, M_PASTE_CLIP, "&Paste"); return 0; }
bool StTestEmbed::createNative() { myParent = (StNativeWin_t )NULL; StRectI_t aRect; aRect.top() = 128; aRect.bottom() = 128 + 400; aRect.left() = 128; aRect.right() = 128 + 400; #if defined(_WIN32) WNDCLASSW aWinClass; stMemSet(&aWinClass, 0, sizeof(aWinClass)); HINSTANCE anAppInst = GetModuleHandle(NULL); aWinClass.lpfnWndProc = (WNDPROC )embedWindowProc; aWinClass.hInstance = anAppInst; aWinClass.hIcon = LoadIcon(NULL, IDI_WINLOGO); aWinClass.hCursor = LoadCursor(NULL, IDC_ARROW); aWinClass.lpszClassName = L"DummyClass"; if(!RegisterClassW(&aWinClass)) { st::cout << stostream_text("RegisterClass() failed:\nCannot register window class 'DummyClass'.\n"); return false; } HWND aWin = CreateWindowW(L"DummyClass", L"DummyWindow", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, aRect.left(), aRect.top(), aRect.width(), aRect.height(), NULL, NULL, anAppInst, NULL); ShowWindow(aWin, TRUE); myParent = aWin; return true; #elif defined(__linux__) // open a connection to the X server Display* aDisplay = XOpenDisplay(NULL); if(aDisplay == NULL) { st::cout << stostream_text("XOpenDisplay() failed!\n"); return false; } Window aWin = XCreateSimpleWindow(aDisplay, RootWindow(aDisplay, DefaultScreen(aDisplay)), aRect.left(), aRect.top(), aRect.width(), aRect.height(), 0, 0, BlackPixel(aDisplay, DefaultScreen(aDisplay))); if(aWin == 0) { st::cout << stostream_text("XCreateSimpleWindow() failed!\n"); XCloseDisplay(aDisplay); return false; } XSetStandardProperties(aDisplay, aWin, "DummyWindow", "DummyWindow", None, NULL, 0, NULL); XSelectInput(aDisplay, aWin, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask); // handle close window event //XSetWMProtocols(aDisplay, aWin, &(stXDisplay->wndDestroyAtom), 1); // request the X window to be displayed on the screen XMapWindow(aDisplay, aWin); // flushes the output buffer XFlush(aDisplay); myParent = (void* )aWin; myDisplay = aDisplay; return true; #else st::cout << stostream_text("StTestEmbed::createNative() not implemented on this platform!\n"); return false; #endif }
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow) { wchar_t progname[] = L"CerealBox"; windata.gameoutput.graphic.width = 1920/2; windata.gameoutput.graphic.height = 1080/2; windata.running = ootrue; windata.gameMemory = (void *) calloc((size_t)gameMemorySize(), 1L); oouint audioBufferSize = win32AudioBufferSize(); windata.gameoutput.audio.buffer = (ooshort *) calloc((size_t)audioBufferSize, 1L); oouint audioFramesPerSecond = win32AudioFramesPerSecond(); WNDCLASSEXW winclass; ZeroMemory(&winclass, sizeof(WNDCLASSEXW)); MSG msg; winclass.cbSize = sizeof(WNDCLASSEXW); winclass.style = CS_DBLCLKS; winclass.lpfnWndProc = &winproc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hInst; winclass.hIcon = LoadIcon(NULL,IDI_WINLOGO); winclass.hCursor = LoadCursor(NULL,IDC_ARROW); winclass.lpszClassName = progname; if(!RegisterClassExW(&winclass)) { return 0; } oouint startX = 100; oouint startY = 100; DWORD windowStyle = WS_SYSMENU|WS_CAPTION|WS_BORDER|WS_OVERLAPPED|WS_VISIBLE|WS_MINIMIZEBOX; #ifdef OO_FULLSCREEN windowStyle = WS_EX_TOPMOST | WS_POPUP; win32GetScreenResolution(&windata.gameoutput.graphic.width, &windata.gameoutput.graphic.height); startX = 0; startY = 0; #endif RECT wr = {0, 0, windata.gameoutput.graphic.width, windata.gameoutput.graphic.height}; AdjustWindowRect(&wr, windowStyle, FALSE); windata.window = CreateWindowW( progname, progname, windowStyle, startX, startY, wr.right - wr.left, wr.bottom - wr.top, NULL, NULL, hInst, NULL); initGraphics(&windata); win32AudioInit(windata.window); ShowWindow(windata.window,nCmdShow); UpdateWindow(windata.window); LARGE_INTEGER timeFrequency; QueryPerformanceFrequency(&timeFrequency); LARGE_INTEGER lastTime; ZeroMemory(&lastTime, sizeof(LARGE_INTEGER) ); LARGE_INTEGER time; windata.gameinput.dt = 1.f/60.f; windata.windowDC = GetDC(windata.window); ooint monitorRefreshHz = 60; oofloat frameMs = 1.f / (oofloat)monitorRefreshHz; ooint win32RefreshRate = GetDeviceCaps(windata.windowDC, VREFRESH); if( win32RefreshRate>1 ) { monitorRefreshHz = win32RefreshRate; frameMs = 1.f / (oofloat)monitorRefreshHz; } while( windata.running ) { PeekMessage(&msg,NULL,0,0,PM_REMOVE); if(msg.message == WM_QUIT) { break; } TranslateMessage(&msg); DispatchMessage(&msg); win32ProcessMouseEvents(windata.window, &windata); QueryPerformanceCounter(&time); if( lastTime.QuadPart>0 ) { windata.gameinput.dt = (oofloat)(time.QuadPart - lastTime.QuadPart); windata.gameinput.dt /= timeFrequency.QuadPart; windata.gameoutput.audio.framesToWrite = (oouint)(windata.gameinput.dt*audioFramesPerSecond); if(windata.gameoutput.audio.framesToWrite>audioBufferSize) { windata.gameoutput.audio.framesToWrite = audioBufferSize; } advanceGame(windata.gameMemory,&windata.gameinput,&windata.gameoutput); win32AudioOutput(windata.gameoutput.audio.buffer, windata.gameoutput.audio.framesToWrite); renderGraphics(&windata); } lastTime = time; } ReleaseDC(windata.window, windata.windowDC); destroyGraphics(&windata); win32AudioDestroy(); free(windata.gameMemory); free(windata.gameoutput.audio.buffer); return (msg.wParam); }
static LRESULT CALLBACK GROUP_GroupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { PROGGROUP* group; INT iItem; LVITEMW lvItem; POINT pt; group = (PROGGROUP*)GetWindowLongPtrW(hWnd, 0); switch (uMsg) { case WM_NCCREATE: { LPCREATESTRUCTW pcs = (LPCREATESTRUCTW)lParam; LPMDICREATESTRUCTW pMDIcs = (LPMDICREATESTRUCTW)pcs->lpCreateParams; group = (PROGGROUP*)pMDIcs->lParam; SetWindowLongPtrW(hWnd, 0, (LONG_PTR)group); if (group->bIsCommonGroup) { DefMDIChildProcW(hWnd, WM_SETICON, ICON_BIG, (LPARAM)CopyImage(Globals.hCommonGroupIcon, IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_COPYFROMRESOURCE)); DefMDIChildProcW(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)CopyImage(Globals.hCommonGroupIcon, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_COPYFROMRESOURCE)); } else { DefMDIChildProcW(hWnd, WM_SETICON, ICON_BIG, (LPARAM)CopyImage(Globals.hPersonalGroupIcon, IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_COPYFROMRESOURCE)); DefMDIChildProcW(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)CopyImage(Globals.hPersonalGroupIcon, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_COPYFROMRESOURCE)); } break; } case WM_NCDESTROY: SetWindowLongPtrW(hWnd, 0, 0); break; case WM_CREATE: { DWORD dwStyle; RECT rect; GetClientRect(hWnd, &rect); group->hListView = CreateWindowW(WC_LISTVIEW, NULL, WS_CHILD | WS_VISIBLE | WS_OVERLAPPED, 0, 0, rect.right - rect.left, rect.bottom - rect.top, hWnd, NULL, Globals.hInstance, NULL); dwStyle = (GetWindowLongPtrW(group->hListView, GWL_STYLE) | LVS_SHOWSELALWAYS) & ~LVS_AUTOARRANGE; SetWindowLongPtrW(group->hListView, GWL_STYLE, dwStyle); dwStyle = SendMessageA(group->hListView, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0) | LVS_EX_BORDERSELECT; SendMessageA(group->hListView, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_SNAPTOGRID, dwStyle); InitUxTheme(); SetWindowTheme(group->hListView, L"Explorer", NULL); group->hListLarge = ImageList_Create(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), ILC_COLOR24 | ILC_MASK, 1, 1); SendMessageA(group->hListView, LVM_SETIMAGELIST, 0, (LPARAM)group->hListLarge); SendMessageA(group->hListView, LVM_SETICONSPACING, 0, MAKELPARAM(80, 64)); break; } case WM_DESTROY: { SendMessageA(group->hListView, LVM_SETIMAGELIST, 0, 0); ImageList_Destroy(group->hListLarge); DestroyWindow(group->hListView); break; } case WM_SIZE: { RECT rect; rect.left = 0; rect.top = 0; rect.right = LOWORD(lParam); rect.bottom = HIWORD(lParam); AdjustWindowRectEx(&rect, GetWindowLongPtrW(group->hListView, GWL_STYLE), FALSE, GetWindowLongPtrW(group->hListView, GWL_EXSTYLE)); MoveWindow(group->hListView, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE); break; } case WM_CLOSE: SendMessageW(hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0); break; case WM_SYSCOMMAND: if (wParam == SC_CLOSE) wParam = SC_MINIMIZE; break; case WM_CHILDACTIVATE: case WM_NCLBUTTONDOWN: Globals.hActiveGroup = (PROGGROUP*)GetWindowLongPtrW(hWnd, 0); Globals.hActiveGroup->hActiveProgram = NULL; break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case NM_CLICK: { iItem = ((LPNMITEMACTIVATE)lParam)->iItem; if (iItem == -1) { group->hActiveProgram = NULL; break; } lvItem.mask = LVIF_PARAM; lvItem.iItem = iItem; SendMessageW(group->hListView, LVM_GETITEMW, 0, (LPARAM)&lvItem); group->hActiveProgram = (PROGRAM*)lvItem.lParam; break; } case NM_DBLCLK: { iItem = ((LPNMITEMACTIVATE)lParam)->iItem; if (iItem == -1) break; lvItem.mask = LVIF_PARAM; lvItem.iItem = iItem; SendMessageW(group->hListView, LVM_GETITEMW, 0, (LPARAM)&lvItem); /* ... or use group->hActiveProgram */ PROGRAM_ExecuteProgram((PROGRAM*)lvItem.lParam); break; } case LVN_BEGINDRAG: { POINT ptMin; BOOL bFirst = TRUE; for (iItem = SendMessageA(group->hListView, LVM_GETNEXTITEM, -1, LVNI_SELECTED); iItem != -1; iItem = SendMessageA(group->hListView, LVM_GETNEXTITEM, iItem, LVNI_SELECTED)) { if (bFirst) { group->hDragImageList = (HIMAGELIST)SendMessageA(group->hListView, LVM_CREATEDRAGIMAGE, iItem, (LPARAM)&pt); ptMin = pt; bFirst = FALSE; } else { HIMAGELIST hOneImageList, hTempImageList; hOneImageList = (HIMAGELIST)SendMessageA(group->hListView, LVM_CREATEDRAGIMAGE, iItem, (LPARAM)&pt); hTempImageList = ImageList_Merge(group->hDragImageList, 0, hOneImageList, 0, pt.x - ptMin.x, pt.y - ptMin.y); ImageList_Destroy(group->hDragImageList); ImageList_Destroy(hOneImageList); group->hDragImageList = hTempImageList; ptMin.x = min(ptMin.x, pt.x); ptMin.y = min(ptMin.y, pt.y); } } // pt = ((LPNMLISTVIEW)lParam)->ptAction; pt.x = ((LPNMLISTVIEW)lParam)->ptAction.x; pt.y = ((LPNMLISTVIEW)lParam)->ptAction.y; group->ptStart = pt; pt.x -= ptMin.x; pt.y -= ptMin.y; ImageList_BeginDrag(group->hDragImageList, 0, pt.x, pt.y); MapWindowPoints(group->hListView, Globals.hMDIWnd, &pt, 1); ImageList_DragEnter(Globals.hMDIWnd, pt.x, pt.y); group->bDragging = TRUE; group->hOldCursor = GetCursor(); SetCapture(group->hWnd); break; } } break; case WM_MOUSEMOVE: if (group->bDragging) { pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); MapWindowPoints(group->hWnd, Globals.hMDIWnd, &pt, 1); ImageList_DragMove(pt.x, pt.y); } break; case WM_LBUTTONUP: if (group->bDragging) { // LVHITTESTINFO lvhti; POINT ptHit; group->bDragging = FALSE; ImageList_DragLeave(Globals.hMDIWnd); ImageList_EndDrag(); ImageList_Destroy(group->hDragImageList); ReleaseCapture(); SetCursor(group->hOldCursor); ptHit.x = GET_X_LPARAM(lParam); ptHit.y = GET_Y_LPARAM(lParam); MapWindowPoints(group->hWnd, group->hListView, &ptHit, 1); for (iItem = SendMessageA(group->hListView, LVM_GETNEXTITEM, -1, LVNI_SELECTED); iItem != -1; iItem = SendMessageA(group->hListView, LVM_GETNEXTITEM, iItem, LVNI_SELECTED)) { SendMessageA(group->hListView, LVM_GETITEMPOSITION, iItem, (LPARAM)&pt); pt.x += ptHit.x - group->ptStart.x; pt.y += ptHit.y - group->ptStart.y; SendMessageA(group->hListView, LVM_SETITEMPOSITION, iItem, MAKELPARAM(pt.x, pt.y)); } } break; } return DefMDIChildProcW(hWnd, uMsg, wParam, lParam); }
void EnableBatteryNotifications() { if (IsVistaOrLater()) { // RegisterPowerSettingNotification is from Vista or later. // Use this API if available. HMODULE hUser32 = GetModuleHandleW(L"USER32.DLL"); if (!sRegisterPowerSettingNotification) sRegisterPowerSettingNotification = (decltype(RegisterPowerSettingNotification)*) GetProcAddress(hUser32, "RegisterPowerSettingNotification"); if (!sUnregisterPowerSettingNotification) sUnregisterPowerSettingNotification = (decltype(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 == 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 = sRegisterPowerSettingNotification(sHWnd, &GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE); sCapacityHandle = sRegisterPowerSettingNotification(sHWnd, &GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE); } else { // for Windows 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, nullptr, Preferences::GetInt("dom.battery.timer", 30000 /* 30s */), nsITimer::TYPE_REPEATING_SLACK); } } }
/***************************************************************** * DdeConnect (USER32.@) */ HCONV WINAPI DdeConnect(DWORD idInst, HSZ hszService, HSZ hszTopic, PCONVCONTEXT pCC) { HWND hwndClient; WDML_INSTANCE* pInstance; WDML_CONV* pConv = NULL; ATOM aSrv = 0, aTpc = 0; TRACE("(0x%x,%p,%p,%p)\n", idInst, hszService, hszTopic, pCC); pInstance = WDML_GetInstance(idInst); if (!pInstance) return NULL; /* make sure this conv is never created */ pConv = WDML_FindConv(pInstance, WDML_CLIENT_SIDE, hszService, hszTopic); if (pConv != NULL) { ERR("This Conv already exists: (%p)\n", pConv); return NULL; } /* we need to establish a conversation with server, so create a window for it */ if (pInstance->unicode) { WNDCLASSEXW wndclass; wndclass.cbSize = sizeof(wndclass); wndclass.style = 0; wndclass.lpfnWndProc = WDML_ClientProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 2 * sizeof(ULONG_PTR); wndclass.hInstance = 0; wndclass.hIcon = 0; wndclass.hCursor = 0; wndclass.hbrBackground = 0; wndclass.lpszMenuName = NULL; wndclass.lpszClassName = WDML_szClientConvClassW; wndclass.hIconSm = 0; RegisterClassExW(&wndclass); hwndClient = CreateWindowW(WDML_szClientConvClassW, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0); } else { WNDCLASSEXA wndclass; wndclass.cbSize = sizeof(wndclass); wndclass.style = 0; wndclass.lpfnWndProc = WDML_ClientProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 2 * sizeof(ULONG_PTR); wndclass.hInstance = 0; wndclass.hIcon = 0; wndclass.hCursor = 0; wndclass.hbrBackground = 0; wndclass.lpszMenuName = NULL; wndclass.lpszClassName = WDML_szClientConvClassA; wndclass.hIconSm = 0; RegisterClassExA(&wndclass); hwndClient = CreateWindowA(WDML_szClientConvClassA, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0); } SetWindowLongPtrW(hwndClient, GWL_WDML_INSTANCE, (ULONG_PTR)pInstance); if (hszService) { aSrv = WDML_MakeAtomFromHsz(hszService); if (!aSrv) goto theEnd; } if (hszTopic) { aTpc = WDML_MakeAtomFromHsz(hszTopic); if (!aTpc) goto theEnd; } /* note: sent messages shall not use packing */ SendMessageTimeoutW( HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)hwndClient, MAKELPARAM(aSrv, aTpc), SMTO_ABORTIFHUNG, 2000, NULL ); pInstance = WDML_GetInstance(idInst); if (!pInstance) { goto theEnd; } /* At this point, Client WM_DDE_ACK should have saved hwndServer for this instance id and hwndClient if server responds. So get HCONV and return it. And add it to conv list */ pConv = WDML_GetConvFromWnd(hwndClient); if (pConv == NULL || pConv->hwndServer == 0) { WARN("Done with INITIATE, but no Server window available\n"); pConv = NULL; goto theEnd; } TRACE("Connected to Server window (%p)\n", pConv->hwndServer); pConv->wConvst = XST_CONNECTED; /* finish init of pConv */ if (pCC != NULL) { pConv->convContext = *pCC; } else { memset(&pConv->convContext, 0, sizeof(pConv->convContext)); pConv->convContext.cb = sizeof(pConv->convContext); pConv->convContext.iCodePage = (pInstance->unicode) ? CP_WINUNICODE : CP_WINANSI; } theEnd: if (aSrv) GlobalDeleteAtom(aSrv); if (aTpc) GlobalDeleteAtom(aTpc); return (HCONV)pConv; }
static void test_ax_win(void) { DWORD ret, ret_size, i; HRESULT res; HWND hwnd; HANDLE hfile; IUnknown *control; WNDPROC wndproc[2] = {NULL, NULL}; WCHAR file_uri1W[MAX_PATH], pathW[MAX_PATH]; WNDCLASSEXW wcex; static HMODULE hinstance = 0; static const WCHAR cls_names[][16] = { {'A','t','l','A','x','W','i','n','1','0','0',0}, {'A','t','l','A','x','W','i','n','L','i','c','1','0','0',0} }; ret = AtlAxWinInit(); ok(ret, "AtlAxWinInit failed\n"); hinstance = GetModuleHandleA(NULL); for (i = 0; i < 2; i++) { memset(&wcex, 0, sizeof(wcex)); wcex.cbSize = sizeof(wcex); ret = GetClassInfoExW(hinstance, cls_names[i], &wcex); ok(ret, "%s has not registered\n", wine_dbgstr_w(cls_names[i])); ok(wcex.style == (CS_GLOBALCLASS | CS_DBLCLKS), "wcex.style %08x\n", wcex.style); wndproc[i] = wcex.lpfnWndProc; hwnd = CreateWindowW(cls_names[i], NULL, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "CreateWindow failed!\n"); control = (IUnknown *)0xdeadbeef; res = AtlAxGetControl(hwnd, &control); ok(res == E_FAIL, "Expected E_FAIL, returned %08x\n", res); ok(!control, "returned %p\n", control); if (control) IUnknown_Release(control); DestroyWindow(hwnd); hwnd = CreateWindowW(cls_names[i], emptyW, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "CreateWindow failed!\n"); control = (IUnknown *)0xdeadbeef; res = AtlAxGetControl(hwnd, &control); ok(res == E_FAIL, "Expected E_FAIL, returned %08x\n", res); ok(!control, "returned %p\n", control); if (control) IUnknown_Release(control); DestroyWindow(hwnd); hwnd = CreateWindowW(cls_names[i], randomW, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); todo_wine ok(!hwnd, "returned %p\n", hwnd); if(hwnd) DestroyWindow(hwnd); hwnd = CreateWindowW(cls_names[i], progid1W, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "CreateWindow failed!\n"); control = NULL; res = AtlAxGetControl(hwnd, &control); ok(res == S_OK, "AtlAxGetControl failed with res %08x\n", res); ok(control != NULL, "AtlAxGetControl failed!\n"); IUnknown_Release(control); DestroyWindow(hwnd); hwnd = CreateWindowW(cls_names[i], clsid1W, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "CreateWindow failed!\n"); control = NULL; res = AtlAxGetControl(hwnd, &control); ok(res == S_OK, "AtlAxGetControl failed with res %08x\n", res); ok(control != NULL, "AtlAxGetControl failed!\n"); IUnknown_Release(control); DestroyWindow(hwnd); hwnd = CreateWindowW(cls_names[i], url1W, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "CreateWindow failed!\n"); control = NULL; res = AtlAxGetControl(hwnd, &control); ok(res == S_OK, "AtlAxGetControl failed with res %08x\n", res); ok(control != NULL, "AtlAxGetControl failed!\n"); IUnknown_Release(control); DestroyWindow(hwnd); /* test html stream with "MSHTML:" prefix */ hwnd = CreateWindowW(cls_names[i], mshtml1W, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "CreateWindow failed!\n"); control = NULL; res = AtlAxGetControl(hwnd, &control); ok(res == S_OK, "AtlAxGetControl failed with res %08x\n", res); ok(control != NULL, "AtlAxGetControl failed!\n"); IUnknown_Release(control); DestroyWindow(hwnd); hwnd = CreateWindowW(cls_names[i], mshtml2W, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "CreateWindow failed!\n"); control = NULL; res = AtlAxGetControl(hwnd, &control); ok(res == S_OK, "AtlAxGetControl failed with res %08x\n", res); ok(control != NULL, "AtlAxGetControl failed!\n"); IUnknown_Release(control); DestroyWindow(hwnd); /* test html stream without "MSHTML:" prefix */ hwnd = CreateWindowW(cls_names[i], mshtml3W, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); todo_wine ok(!hwnd, "returned %p\n", hwnd); if(hwnd) DestroyWindow(hwnd); ret = GetTempPathW(MAX_PATH, pathW); ok(ret, "GetTempPath failed!\n"); lstrcatW(pathW, html_fileW); hfile = CreateFileW(pathW, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0); ok(hfile != INVALID_HANDLE_VALUE, "failed to create file\n"); ret = WriteFile(hfile, html_str, sizeof(html_str), &ret_size, NULL); ok(ret, "WriteFile failed\n"); CloseHandle(hfile); /* test C:// scheme */ hwnd = CreateWindowW(cls_names[i], pathW, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "CreateWindow failed!\n"); control = NULL; res = AtlAxGetControl(hwnd, &control); ok(res == S_OK, "AtlAxGetControl failed with res %08x\n", res); ok(control != NULL, "AtlAxGetControl failed!\n"); IUnknown_Release(control); DestroyWindow(hwnd); /* test file:// scheme */ lstrcpyW(file_uri1W, fileW); lstrcatW(file_uri1W, pathW); hwnd = CreateWindowW(cls_names[i], file_uri1W, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "CreateWindow failed!\n"); control = NULL; res = AtlAxGetControl(hwnd, &control); ok(res == S_OK, "AtlAxGetControl failed with res %08x\n", res); ok(control != NULL, "AtlAxGetControl failed!\n"); IUnknown_Release(control); DestroyWindow(hwnd); /* test file:// scheme on non-existent file */ ret = DeleteFileW(pathW); ok(ret, "DeleteFile failed!\n"); hwnd = CreateWindowW(cls_names[i], file_uri1W, 0, 100, 100, 100, 100, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "CreateWindow failed!\n"); control = NULL; res = AtlAxGetControl(hwnd, &control); ok(res == S_OK, "AtlAxGetControl failed with res %08x\n", res); ok(control != NULL, "AtlAxGetControl failed!\n"); IUnknown_Release(control); DestroyWindow(hwnd); } todo_wine ok(wndproc[0] != wndproc[1], "expected different proc!\n"); }