int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR CmdLine, int nCmdShow) { MSG msg; /* MSG structure to pass to windows proc */ WNDCLASS wndclass; char *AppName; /* Name for the window */ cbErrHandling (PRINTALL, STOPALL); /* Set library's error handling */ CmdLine = NULL; /* Not used */ AppName = "WINCDEMO"; /* The name of this application */ if(!hPrevInstance) { wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc= MainMessageHandler; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (hInstance, AppName); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = GetStockObject (WHITE_BRUSH); wndclass.lpszMenuName = AppName; wndclass.lpszClassName = AppName; RegisterClass (&wndclass); } /* create application's Main window */ hWndMain = CreateWindow (AppName, /* Window class name */ "AInScan Foreground", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, /* Use default X, Y */ CW_USEDEFAULT, /* Use default X, Y */ GetSystemMetrics(SM_CXSIZE) * 12, /* x - fit text */ GetSystemMetrics(SM_CYSIZE) * 20, /* y - fit text */ NULL, /* Parent window's handle */ NULL, /* Default to Class Menu */ hInstance, /* Instance of window */ NULL); /* Create struct for WM_CREATE */ if (hWndMain == NULL) { MessageBox(NULL, "Could not create window in WinMain", NULL, MB_ICONEXCLAMATION); return (1); } ShowWindow(hWndMain, nCmdShow); /* Display main window */ UpdateWindow(hWndMain); /* Start a 500ms timer to update display */ // if(!SetTimer(hWndMain, TIMER_NUM, 500, NULL)) // { // MessageBox(NULL, "Error starting Windows timer", NULL, MB_OK | // MB_ICONEXCLAMATION); // return (1); // } while(GetMessage(&msg, NULL, 0, 0)) /* Main message loop */ { TranslateMessage(&msg); DispatchMessage(&msg); } UnregisterClass (AppName, hInstance); return (msg.wParam); }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { srand(time(NULL)); WNDCLASSEX windowClass; ZeroMemory(&windowClass, sizeof(WNDCLASSEX)); windowClass.cbSize = sizeof(WNDCLASSEX); windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW); windowClass.hInstance = hInstance; windowClass.lpfnWndProc = WindowProc; windowClass.lpszClassName = "MainWindow"; windowClass.style = CS_HREDRAW | CS_VREDRAW; RegisterClassEx(&windowClass); RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT }; AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, false, WS_EX_OVERLAPPEDWINDOW); HWND windowHandle = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, windowClass.lpszClassName, "Codrut Niculescu's Tetris Project", WS_OVERLAPPEDWINDOW, 100, 100, (rect.right-rect.left), (rect.bottom-rect.top), NULL, NULL, hInstance, NULL); if (windowHandle == NULL) { return -1; } graphics = new Graphics(); if (graphics->Init(windowHandle) == false) { delete graphics; return -1; } ShowWindow(windowHandle, nCmdShow); MSG message; message.message = WM_NULL; GameController::Init(); while (message.message != WM_QUIT) { if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) { DispatchMessage(&message); } else { GameController::Update(); // Render! graphics->BeginDraw(); GameController::Render(graphics); graphics->EndDraw(); GameController::FinishedBlock(); } } delete graphics; return 0; }
/* ************************************ * 功能 显示一个窗口 **************************************/ int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wcx; // 窗口类 HWND hwnd; // 窗口句柄 MSG msg; // 消息 BOOL fGotMessage; // 是否成功获取消息 hinst = hinstance; // 应用程序实例句柄,保存为全局变量 // 填充窗口类的数据结构 wcx.cbSize = sizeof(wcx); // 结构体的大小 wcx.style = CS_HREDRAW | CS_VREDRAW; // 样式:大小改变时重绘界面 wcx.lpfnWndProc = MainWndProc; // 窗口消息处理函数 wcx.cbClsExtra = 0; // 不使用类内存 wcx.cbWndExtra = 0; // 不使用窗口内存 wcx.hInstance = hinstance; // 所属的应用程序实例句柄 wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); // 图标:默认 wcx.hCursor = LoadCursor(NULL, IDC_ARROW); // 光标:默认 wcx.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH); // 背景:白色 wcx.lpszMenuName = NULL; // 菜单:不使用 wcx.lpszClassName = "MainWClass"; // 窗口类名 wcx.hIconSm = (HICON)LoadImage(hinstance, // 小图标 MAKEINTRESOURCE(5), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); // 注册窗口类 if(!RegisterClassEx(&wcx)) { return 1; } // 创建窗口 hwnd = CreateWindow( "MainWClass", // 窗口名 "CH 2-3", // 窗口标题 WS_OVERLAPPEDWINDOW, // 窗口样式 CW_USEDEFAULT, // 水平位置X:默认 CW_USEDEFAULT, // 垂直位置Y:默认 CW_USEDEFAULT, // 宽度:默认 CW_USEDEFAULT, // 高度:默认 (HWND) NULL, // 父窗口:无 (HMENU) NULL, // 菜单:使用窗口类的菜单 hinstance, // 应用程序实例句柄 (LPVOID) NULL); // 窗口创建时数据:无 if (!hwnd) { return 1; } // 显示窗口 ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); // 消息循环 while ( (fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0 && fGotMessage != -1) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
int CALLBACK WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg = {0}; NOTIFYICONDATA nid = {}; WNDCLASSEX wx = {}; MENUITEMINFO mi = {}; ::hInstance = hInstance; mi.cbSize = sizeof(MENUITEMINFO); mi.fMask = MIIM_STRING|MIIM_ID; mi.wID = 1; mi.dwTypeData = "E&xit"; hMenu = CreatePopupMenu(); if (InsertMenuItem(hMenu,0,TRUE,&mi) == 0) { MessageBox(NULL,"Failed to create menu!", NULL, NULL); return 1; } mi.wID = 2; mi.dwTypeData = "&Hotkey..."; if (InsertMenuItem(hMenu,0,TRUE,&mi) == 0) { MessageBox(NULL,"Failed to create menu!", NULL, NULL); return 1; } wx.cbSize = sizeof(WNDCLASSEX); wx.lpfnWndProc = WndProc; wx.hInstance = hInstance; wx.lpszClassName = className; if (RegisterClassEx(&wx) == NULL) { MessageBox(NULL,"Failed to register class!", NULL, NULL); return 1; } mainWindow = CreateWindowEx(0, className, "poepulse", 0,0,0,0,0, HWND_MESSAGE, NULL, hInstance, NULL); if (mainWindow == 0) { MessageBox(NULL,"Failed to create window!", NULL, NULL); return 1; } windowMessage = RegisterWindowMessage("poepulse_PulseCursor"); if (!windowMessage) { MessageBox(NULL,"Failed to register custom message!", NULL, NULL); return 1; } theDll = LoadLibrary("poepmod.dll"); if (!theDll) { MessageBox(NULL,"Failed to load poepmod.dll!", NULL, NULL); return 1; } hookProc = GetProcAddress(theDll,"_PoeWndProc@12"); if (!hookProc) { MessageBox(NULL,"Failed to find window hook procedure!", NULL,NULL); return 1; } // query/create the registry for our hotkey information if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Aaron Opfer\\PoE Pulse", NULL, NULL, NULL, KEY_ALL_ACCESS, NULL, ®Key, NULL) != ERROR_SUCCESS) { MessageBox(NULL,"Failed to read/write registry!", NULL,NULL); return 1; } // retrieve the hotkey values from the registry if (RegGetValue(regKey, NULL, "fsModifiers", RRF_RT_REG_DWORD, NULL, &fsModifiers, &sizeofUINT) != ERROR_SUCCESS || RegGetValue(regKey, NULL, "vKey", RRF_RT_REG_DWORD, NULL, &vKey, &sizeofUINT) != ERROR_SUCCESS) { // Couldn't read these registry keys, better set some defaults // instead fsModifiers = MOD_ALT; vKey = VK_SPACE; if (RegSetValueEx(regKey, "fsModifiers", NULL, REG_DWORD, (BYTE*)&fsModifiers, sizeofUINT) != ERROR_SUCCESS || RegSetValueEx(regKey, "vKey", NULL, REG_DWORD, (BYTE*)&vKey, sizeofUINT) != ERROR_SUCCESS) { MessageBox(NULL,"Failed to write registry!", NULL,NULL); return 1; } } if (RegisterHotKey(mainWindow, 1, fsModifiers, vKey) == FALSE) { MessageBox(NULL,"Failed to Create Hotkey!", NULL, NULL); return 1; } nid.cbSize = sizeof(NOTIFYICONDATA); nid.hWnd = mainWindow; nid.uID = 222; nid.uVersion = NOTIFYICON_VERSION_4; nid.uFlags = NIF_MESSAGE|NIF_TIP|NIF_ICON|NIF_SHOWTIP; nid.uCallbackMessage = 0xBEEF; strcpy(nid.szTip, "PoE Pulse"); nid.hIcon = LoadIcon(NULL,IDI_APPLICATION); if (Shell_NotifyIcon(NIM_ADD,&nid) == FALSE || Shell_NotifyIcon(NIM_SETVERSION,&nid) == FALSE) { MessageBox(NULL,"Failed to Create notification bar icon!!", NULL, NULL); return 1; } while (GetMessage(&msg,NULL,0,0) != 0) { DispatchMessage(&msg); } ExitProcess(0); return 0; }
void __declspec(dllexport) show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { TCHAR fn[MAX_PATH]; TCHAR temp[64]; TCHAR *sleep=temp; EXDLL_INIT(); popstring(sleep); popstring(fn); sleep_val=0; while (*sleep >= _T('0') && *sleep <= _T('9')) { sleep_val*=10; sleep_val+=*sleep++-_T('0'); } if (fn[0] && sleep_val>0) { MSG msg; TCHAR classname[4]=_T("_sp"); static WNDCLASS wc; wc.lpfnWndProc = WndProc; wc.hInstance = g_hInstance; wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.lpszClassName = classname; if (RegisterClass(&wc)) { TCHAR fn2[MAX_PATH]; lstrcpy(fn2,fn); lstrcat(fn,_T(".bmp")); lstrcat(fn2,_T(".wav")); g_hbm=LoadImage(NULL,fn,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE); if (g_hbm) { HWND myWnd; PlaySound(fn2,NULL,SND_ASYNC|SND_FILENAME|SND_NODEFAULT); myWnd = CreateWindowEx(WS_EX_TOOLWINDOW,classname,classname, 0,0,0,0,0,(HWND)hwndParent,NULL,g_hInstance,NULL); while (IsWindow(myWnd) && GetMessage(&msg,myWnd,0,0)) { DispatchMessage(&msg); } // Stop currently playing wave, we want to exit PlaySound(0,0,0); DeleteObject(g_hbm); UnregisterClass(classname, g_hInstance); } } } wsprintf(temp,_T("%d"),g_rv); pushstring(temp); }
/***************************************************************************** * Thread: main loop *****************************************************************************/ static void *Thread( void *p_data ) { MSG message; UINT i_key, i_keyMod, i_vk; ATOM atom; char *psz_hotkey = NULL; intf_thread_t *p_intf = p_data; intf_sys_t *p_sys = p_intf->p_sys; /* Window which receives Hotkeys */ vlc_mutex_lock( &p_sys->lock ); p_sys->hotkeyWindow = (void*)CreateWindow( _T("STATIC"), /* name of window class */ _T("VLC ghk ") _T(VERSION), /* window title bar text */ 0, /* window style */ 0, /* default X coordinate */ 0, /* default Y coordinate */ 0, /* window width */ 0, /* window height */ NULL, /* no parent window */ NULL, /* no menu in this window */ GetModuleHandle(NULL), /* handle of this program instance */ NULL ); /* sent to WM_CREATE */ if( p_sys->hotkeyWindow == NULL ) { p_sys->hotkeyWindow = INVALID_HANDLE_VALUE; vlc_cond_signal( &p_sys->wait ); vlc_mutex_unlock( &p_sys->lock ); return NULL; } vlc_cond_signal( &p_sys->wait ); vlc_mutex_unlock( &p_sys->lock ); SetWindowLongPtr( p_sys->hotkeyWindow, GWL_WNDPROC, (LONG_PTR)WMHOTKEYPROC ); SetWindowLongPtr( p_sys->hotkeyWindow, GWL_USERDATA, (LONG_PTR)p_intf ); /* Registering of Hotkeys */ for( struct hotkey *p_hotkey = p_intf->p_libvlc->p_hotkeys; p_hotkey->psz_action != NULL; p_hotkey++ ) { if( asprintf( &psz_hotkey, "global-%s", p_hotkey->psz_action ) < 0 ) break; i_key = config_GetInt( p_intf, psz_hotkey ); free( psz_hotkey ); i_keyMod = 0; if( i_key & KEY_MODIFIER_SHIFT ) i_keyMod |= MOD_SHIFT; if( i_key & KEY_MODIFIER_ALT ) i_keyMod |= MOD_ALT; if( i_key & KEY_MODIFIER_CTRL ) i_keyMod |= MOD_CONTROL; #define HANDLE( key ) case KEY_##key: i_vk = VK_##key; break #define HANDLE2( key, key2 ) case KEY_##key: i_vk = VK_##key2; break #ifndef VK_VOLUME_DOWN #define VK_VOLUME_DOWN 0xAE #define VK_VOLUME_UP 0xAF #endif #ifndef VK_MEDIA_NEXT_TRACK #define VK_MEDIA_NEXT_TRACK 0xB0 #define VK_MEDIA_PREV_TRACK 0xB1 #define VK_MEDIA_STOP 0xB2 #define VK_MEDIA_PLAY_PAUSE 0xB3 #endif #ifndef VK_PAGEUP #define VK_PAGEUP 0x21 #define VK_PAGEDOWN 0x22 #endif i_vk = 0; switch( i_key & ~KEY_MODIFIER ) { HANDLE( LEFT ); HANDLE( RIGHT ); HANDLE( UP ); HANDLE( DOWN ); HANDLE( SPACE ); HANDLE2( ESC, ESCAPE ); HANDLE2( ENTER, RETURN ); HANDLE( F1 ); HANDLE( F2 ); HANDLE( F3 ); HANDLE( F4 ); HANDLE( F5 ); HANDLE( F6 ); HANDLE( F7 ); HANDLE( F8 ); HANDLE( F9 ); HANDLE( F10 ); HANDLE( F11 ); HANDLE( F12 ); HANDLE( PAGEUP ); HANDLE( PAGEDOWN ); HANDLE( HOME ); HANDLE( END ); HANDLE( INSERT ); HANDLE( DELETE ); HANDLE( VOLUME_DOWN ); HANDLE( VOLUME_UP ); HANDLE( MEDIA_PLAY_PAUSE ); HANDLE( MEDIA_STOP ); HANDLE( MEDIA_PREV_TRACK ); HANDLE( MEDIA_NEXT_TRACK ); default: i_vk = toupper( i_key & ~KEY_MODIFIER ); break; } if( !i_vk ) continue; #undef HANDLE #undef HANDLE2 atom = GlobalAddAtomA( p_hotkey->psz_action ); if( !atom ) continue; if( !RegisterHotKey( p_sys->hotkeyWindow, atom, i_keyMod, i_vk ) ) GlobalDeleteAtom( atom ); } /* Main message loop */ while( GetMessage( &message, NULL, 0, 0 ) ) DispatchMessage( &message ); /* Unregistering of Hotkeys */ for( struct hotkey *p_hotkey = p_intf->p_libvlc->p_hotkeys; p_hotkey->psz_action != NULL; p_hotkey++ ) { atom = GlobalFindAtomA( p_hotkey->psz_action ); if( !atom ) continue; if( UnregisterHotKey( p_sys->hotkeyWindow, atom ) ) GlobalDeleteAtom( atom ); } /* close window */ vlc_mutex_lock( &p_sys->lock ); DestroyWindow( p_sys->hotkeyWindow ); p_sys->hotkeyWindow = NULL; vlc_mutex_unlock( &p_sys->lock ); return NULL; }
int _tmain(int argc, const TCHAR *argv) { HWND w; HINSTANCE hinst = GetModuleHandle(NULL); { WNDCLASS wc; wc.style = CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc = window_proc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hinst; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); wc.lpszMenuName = NULL; wc.lpszClassName = _T("MainWindowClass"); RegisterClass(&wc); } // CreateWindow // http://msdn.microsoft.com/en-us/library/windows/desktop/ms632679(v=vs.85).aspx // > If an overlapped window is created with the WS_VISIBLE // > style bit set and the x parameter is set to // > CW_USEDEFAULT, then the y parameter determines how the // > window is shown. If the y parameter is CW_USEDEFAULT, // > then the window manager calls ShowWindow with the SW_SHOW // > flag after the window has been created. If the y // > parameter is some other value, then the window manager // > calls ShowWindow with that value as the nCmdShow // > parameter. // ShowWindow // http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx // > Controls how the window is to be shown. // > This parameter is ignored the first time an // > application calls ShowWindow, if the program that // > launched the application provides a STARTUPINFO // > structure. // > Otherwise, the first time ShowWindow is called, the value // > should be the value obtained by the WinMain function in // > its nCmdShow parameter. In subsequent calls, this // > parameter can be one of the following values. w = CreateWindow(_T("MainWindowClass"), _T("hello"), WS_OVERLAPPEDWINDOW|WS_VISIBLE, CW_USEDEFAULT, SW_SHOW, CW_USEDEFAULT, 0, NULL, NULL, hinst, NULL); while (1) { MSG msg; BOOL b = GetMessage(&msg, NULL, 0, 0); if (b == 0) { return msg.wParam; } if (b == -1) { return 1; } TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }
int APIENTRY _tWinMain(HINSTANCE hinst, HINSTANCE foo1, LPTSTR foo2, int foo3) { MSG msg; WNDCLASSEX wcex = {sizeof(wcex)}; HANDLE htray; HMENU hmenu; MENUITEMINFO mi = {sizeof(mi)}; INITCOMMONCONTROLSEX icex; RECT rect; int style; HWND hwnd; wcex.lpfnWndProc = WndProc; wcex.lpszClassName = WINDOW_CLASS; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); RegisterClassEx(&wcex); icex.dwSize = sizeof(icex); icex.dwICC = ICC_DATE_CLASSES; InitCommonControlsEx(&icex); hwnd = CreateWindowEx(WS_EX_NOACTIVATE | WS_EX_TOPMOST, WINDOW_CLASS, WINDOW_TITLE, 0, 0, 0, 0, 0, NULL, NULL, hinst, NULL); if (!hwnd) return 1; style = GetWindowLong(hwnd, GWL_STYLE); if (style & WS_CAPTION) { style ^= WS_CAPTION; SetWindowLong(hwnd, GWL_STYLE, style); SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); } hcal = CreateWindowEx(0, MONTHCAL_CLASS, _T(""), WS_CHILD | WS_VISIBLE | MCS_NOTODAY | MCS_NOTRAILINGDATES | MCS_SHORTDAYSOFWEEK | MCS_NOSELCHANGEONNAV, 0, 0, 0, 0, hwnd, NULL, hinst, NULL); MonthCal_GetMinReqRect(hcal, &rect); SetWindowPos(hcal, NULL, 0, 0, rect.right, rect.bottom, SWP_NOZORDER | SWP_NOMOVE); SetWindowPos(hwnd, NULL, 0, 0, rect.right, rect.bottom, SWP_NOZORDER | SWP_NOMOVE); tti.hwnd = hwnd; tti.hcal = hcal; tti.hnotify = CreateEvent(NULL, TRUE, FALSE, NULL); tti.exit = FALSE; htray = CreateThread(NULL, 0, &TrayThreadProc, &tti, 0, NULL); if (!htray) return 1; hsubmenu = CreateMenu(); mi.fMask = MIIM_STRING | MIIM_ID; mi.wID = 1; mi.dwTypeData = EXIT_STRING; InsertMenuItem(hsubmenu, 0, TRUE, &mi); hmenu = CreateMenu(); mi.fMask = MIIM_SUBMENU; mi.hSubMenu = hsubmenu; InsertMenuItem(hmenu, 0, TRUE, &mi); WM_TASKBARCREATED = RegisterWindowMessageA(_T("TaskbarCreated")); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } DestroyMenu(hmenu); DestroyMenu(hsubmenu); WaitForSingleObject(htray, 1000); CloseHandle(htray); return (int)msg.wParam; }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MyDirectX = new DirectX(); WNDCLASSEX wndClass; wndClass.cbSize = sizeof( WNDCLASSEX ); wndClass.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hbrBackground = ( HBRUSH )GetStockObject( BLACK_BRUSH ); wndClass.hInstance = hInstance; wndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wndClass.hIconSm = LoadIcon( NULL, IDI_WINLOGO ); wndClass.hCursor = LoadCursor( NULL, IDC_ARROW ); wndClass.lpfnWndProc = ( WNDPROC )WndProc; wndClass.lpszClassName = "MainWndClass"; wndClass.lpszMenuName = ( LPCSTR )NULL; if( !RegisterClassEx( &wndClass ) ) { MessageBox( HWND_DESKTOP, "Cannot register the main window\nclass.", "Error", MB_OK | MB_ICONERROR ); return 0; } HWND hWndMain = CreateWindowEx( WS_EX_STATICEDGE, "MainWndClass", "DirectX Tutorial #1", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, HWND_DESKTOP, ( HMENU )NULL, ( HINSTANCE )hInstance, ( LPVOID* )NULL ); if( !hWndMain ) { MessageBox( HWND_DESKTOP, "Cannot create the main window.", "Error", MB_OK | MB_ICONERROR ); UnregisterClass( "MainWndClass", hInstance ); return 0; } ShowWindow( hWndMain, SW_SHOWNORMAL ); UpdateWindow( hWndMain ); MyDirectX->Init( hWndMain ); MSG msg = {0}; while( msg.message != WM_QUIT ) { if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } // Do game rendering/updating here MyDirectX->Render( ); } MyDirectX->CleanDirectX( ); delete [] MyDirectX; UnregisterClass( "MainWndClass", hInstance ); return 0; }
//-----------------------------------WinMain----------------------------------------- // Entry point for our windows application //----------------------------------------------------------------------------------- int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; HWND hwnd; MSG msg; // first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1)); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground= NULL; winclass.lpszMenuName = NULL; winclass.lpszClassName= szWindowClassName; winclass.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1)); // register the window class if (!RegisterClassEx(&winclass)) { MessageBox(NULL, "Error Registering Class!", "Error", 0); return 0; } // create the window (one that cannot be resized) if (!(hwnd = CreateWindowEx(NULL, szWindowClassName, szApplicationName, WS_OVERLAPPED | WS_VISIBLE | WS_CAPTION | WS_SYSMENU, GetSystemMetrics(SM_CXSCREEN)/2 - CParams::WindowWidth/2, GetSystemMetrics(SM_CYSCREEN)/2 - CParams::WindowHeight/2, CParams::WindowWidth, CParams::WindowHeight, NULL, NULL, hinstance, NULL))) { MessageBox(NULL, "Error Creating Window!", "Error", 0); return 0; } //Show the window ShowWindow(hwnd, SW_SHOWDEFAULT ); UpdateWindow(hwnd); //create a timer CTimer timer(CParams::iFramesPerSecond); //start the timer timer.Start(); // Enter the message loop bool bDone = FALSE; while(!bDone) { while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if( msg.message == WM_QUIT ) { //Stop loop if it's a quit message bDone = TRUE; } else { TranslateMessage( &msg ); DispatchMessage( &msg ); } } if (timer.ReadyForNextFrame() || g_pController->FastRender()) { if(!g_pController->Update()) { //we have a problem, end app bDone = TRUE; } //this will call WM_PAINT which will render our scene InvalidateRect(hwnd, NULL, TRUE); UpdateWindow(hwnd); } }//end while // Clean up everything and exit the app Cleanup(); UnregisterClass( szWindowClassName, winclass.hInstance ); return 0; } // end WinMain
int PASCAL WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { strcpy ( szMap, lpCmdLine ); //strcpy ( szMap, "csg1.x" ); char szFinal [ 256 ]; memset ( szFinal, 0, sizeof ( szFinal ) ); for ( int iTemp = strlen ( szMap ); iTemp > 0; iTemp-- ) { if ( szMap [ iTemp ] == '/' || szMap [ iTemp ] == '\\' ) { memcpy ( szFinal, &szMap [ iTemp + 1 ], sizeof ( char ) * iTemp ); break; } } strcpy ( szMap, szFinal ); //MessageBox ( NULL, szFinal, "info", MB_OK ); //MessageBox ( NULL, szMap, "info", MB_OK ); //MessageBox ( NULL, lpCmdLine, "lpCmdLine", MB_OK ); hInst = hInstance; hPrevInstance = hPrevInstance; MSG msg; BOOL perf_flag = FALSE; LONGLONG last_time = 0; LONGLONG cur_time; LONGLONG perf_cnt; float time_scale; if ( !doInit ( hInst, nCmdShow ) ) return FALSE; if ( QueryPerformanceFrequency ( ( LARGE_INTEGER* ) &perf_cnt ) ) { QueryPerformanceCounter ( ( LARGE_INTEGER* ) &last_time ); time_scale = 1.0f / perf_cnt; perf_flag = TRUE; } else { last_time = timeGetTime ( ); time_scale = 0.001f; } // SetCursorPos ( 320,200 ); // ShowCursor ( FALSE ); BOOL bGotMsg; while ( quit != 1 ) { while ( bGotMsg = PeekMessage ( &msg, NULL, 0U, 0U, PM_REMOVE ) ) { TranslateMessage ( &msg ); DispatchMessage ( &msg ); } if ( rendering == 1 ) { if ( perf_flag ) QueryPerformanceCounter ( ( LARGE_INTEGER* ) &cur_time ); else cur_time = timeGetTime ( ); time_elapsed = ( cur_time - last_time ) * time_scale; last_time = cur_time; // CheckInput ( ); // renderframe ( ); } } ShowCursor ( TRUE ); return msg.wParam; }
void mswin_display_RIP_window(HWND hWnd) { MSG msg; RECT rt; PNHRIPWindow data; HWND mapWnd; RECT riprt; RECT clientrect; RECT textrect; HFONT OldFont; MonitorInfo monitorInfo; win10_monitor_info(hWnd, &monitorInfo); data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); data->x = (int)(RIP_OFFSET_X * monitorInfo.scale); data->y = (int)(RIP_OFFSET_Y * monitorInfo.scale); data->width = (int)(RIP_WIDTH * monitorInfo.scale); data->height = (int)(RIP_HEIGHT * monitorInfo.scale); data->graveX = (int)(RIP_GRAVE_X * monitorInfo.scale); data->graveY = (int)(RIP_GRAVE_Y * monitorInfo.scale); data->graveWidth = (int)(RIP_GRAVE_WIDTH * monitorInfo.scale); data->graveHeight = (int)(RIP_GRAVE_HEIGHT * monitorInfo.scale); GetNHApp()->hPopupWnd = hWnd; mapWnd = mswin_hwnd_from_winid(WIN_MAP); if (!IsWindow(mapWnd)) mapWnd = GetNHApp()->hMainWnd; GetWindowRect(mapWnd, &rt); GetWindowRect(hWnd, &riprt); GetClientRect(hWnd, &clientrect); textrect = clientrect; textrect.top += data->y; textrect.left += data->x; textrect.right -= data->x; if (data->window_text) { HDC hdc = GetDC(hWnd); OldFont = SelectObject(hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE)->hFont); DrawText(hdc, data->window_text, strlen(data->window_text), &textrect, DT_LEFT | DT_NOPREFIX | DT_CALCRECT); SelectObject(hdc, OldFont); ReleaseDC(hWnd, hdc); } if (textrect.right - textrect.left > data->width) clientrect.right = textrect.right + data->y - clientrect.right; else clientrect.right = textrect.left + 2 * data->x + data->width - clientrect.right; clientrect.bottom = textrect.bottom + data->height + data->y - clientrect.bottom; GetWindowRect(GetDlgItem(hWnd, IDOK), &textrect); textrect.right -= textrect.left; textrect.bottom -= textrect.top; clientrect.bottom += textrect.bottom + data->y; riprt.right -= riprt.left; riprt.bottom -= riprt.top; riprt.right += clientrect.right; riprt.bottom += clientrect.bottom; rt.left += (rt.right - rt.left - riprt.right) / 2; rt.top += (rt.bottom - rt.top - riprt.bottom) / 2; MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE); GetClientRect(hWnd, &clientrect); MoveWindow(GetDlgItem(hWnd, IDOK), (clientrect.right - clientrect.left - textrect.right) / 2, clientrect.bottom - textrect.bottom - data->y, textrect.right, textrect.bottom, TRUE); ShowWindow(hWnd, SW_SHOW); while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) { if (!IsDialogMessage(hWnd, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } GetNHApp()->hPopupWnd = NULL; }
long CWorkgroupDocument::CopyMoveFile(DWORD folder_id, _bstr_t filepath, VARIANT_BOOL bSilent, CProgressDlg* dlg) { long nFilesCopied = 0; DWORD attributes = GetFileAttributes(filepath); char* filepart = PathFindFileName(filepath); if (attributes & FILE_ATTRIBUTE_DIRECTORY) { folder_id = m_filesystem->FindOrCreateFolder(folder_id, filepart, L""); if (folder_id) { HANDLE hFindFile; WIN32_FIND_DATA wfd; char search[MAX_PATH]; wsprintf(search, "%S\\*.*", (BSTR)filepath); if ((hFindFile = FindFirstFile(search, &wfd)) != INVALID_HANDLE_VALUE) { do { if (wfd.cFileName[0] != '.') { char pathName[_MAX_PATH]; _makepath(pathName, NULL, filepath, wfd.cFileName, NULL); nFilesCopied += CopyMoveFile(folder_id, pathName, bSilent, dlg); if (dlg) { if (dlg->m_bCancel) break; } } } while (FindNextFile(hFindFile, &wfd)); FindClose(hFindFile); } } else { if (!bSilent) { CUString str; str.Format("Couldn't create folder %S", (BSTR)filepath); MessageBox(NULL, str, "LXFramework", MB_OK); } } } else { SAFEARRAY* dataArray = NULL; long dataSize = 0; FILE* fp = fopen(filepath, "rb"); if (fp) { fseek(fp, 0, SEEK_END); dataSize = ftell(fp); fseek(fp, 0, SEEK_SET); dataArray = SafeArrayCreateVector(VT_UI1, 0, dataSize); if (dataArray) { fread((dataArray)->pvData, 1, dataSize, fp); } fclose(fp); } else { if (!bSilent) { CUString str; str.Format("Couldn't open %S", (BSTR)filepath); MessageBox(NULL, str, "LXFramework", MB_OK); } } if (dataArray) { long file_id; VARIANT_BOOL success = m_filesystem->SaveArrayAsFile(folder_id, _bstr_t(filepart), dataArray, L"", &file_id); SafeArrayDestroy(dataArray); if (success) { nFilesCopied++; } else { if (!bSilent) { CUString str; str.Format("Failed to copy %s", filepart); MessageBox(NULL, str, "LXFramework", MB_OK); } } } if (dlg) { dlg->m_pos += dataSize/10; dlg->Invalidate(); MSG msg; while (PeekMessage(&msg, dlg->m_hWnd, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } return nFilesCopied; }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: ここにコードを挿入してください。 MSG msg; HACCEL hAccelTable; // グローバル文字列を初期化しています。 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_WALL, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // アプリケーションの初期化を実行します: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } int ret; ret = OneTimeSceneInit(); if( ret ){ _ASSERT( 0 ); return FALSE; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WALL)); // Now we're ready to recieve and process Windows messages. BOOL bGotMsg; //MSG msg; PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE ); while( WM_QUIT != msg.message ) { // Use PeekMessage() if the app is active, so we can use idle time to // render the scene. Else, use GetMessage() to avoid eating CPU time. // if( m_bActive ) bGotMsg = PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ); //else // bGotMsg = GetMessage( &msg, NULL, 0U, 0U ); if( bGotMsg ) { // Translate and dispatch the message if( 0 == TranslateAccelerator(msg.hwnd, hAccelTable, &msg) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } }else{ if( Render3DEnvironment() != 0 ){ SendMessage( msg.hwnd, WM_CLOSE, 0, 0 ); } } } E3DBye(); return (int)msg.wParam; }
INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR szCmdLine, int iCmdShow) { WNDCLASSEX winClass ; winClass.lpszClassName = "Vertex Alpha"; 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 "Vertex Alpha", // 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() ; // Update last time to current time for next loop lastTime = currTime; } } } UnregisterClass(winClass.lpszClassName, hInstance) ; return 0; }
void ShowErrorPane(const char *text) { if (Window == NULL || ConWindow == NULL) { if (text != NULL) { MessageBox (Window, text, GAMESIG " Fatal Error", MB_OK|MB_ICONSTOP|MB_TASKMODAL); } return; } if (StartScreen != NULL) // Ensure that the network pane is hidden. { StartScreen->NetDone(); } if (text != NULL) { char caption[100]; mysnprintf(caption, countof(caption), "Fatal Error - "GAMESIG" %s "X64, GetVersionString()); SetWindowText (Window, caption); ErrorIcon = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SS_OWNERDRAW, 0, 0, 0, 0, Window, NULL, g_hInst, NULL); if (ErrorIcon != NULL) { SetWindowLong (ErrorIcon, GWL_ID, IDC_ICONPIC); } } ErrorPane = CreateDialogParam (g_hInst, MAKEINTRESOURCE(IDD_ERRORPANE), Window, ErrorPaneProc, (LONG_PTR)NULL); if (text != NULL) { CHARRANGE end; CHARFORMAT2 oldformat, newformat; PARAFORMAT2 paraformat; // Append the error message to the log. end.cpMax = end.cpMin = GetWindowTextLength (ConWindow); SendMessage (ConWindow, EM_EXSETSEL, 0, (LPARAM)&end); // Remember current charformat. oldformat.cbSize = sizeof(oldformat); SendMessage (ConWindow, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&oldformat); // Use bigger font and standout colors. newformat.cbSize = sizeof(newformat); newformat.dwMask = CFM_BOLD | CFM_COLOR | CFM_SIZE; newformat.dwEffects = CFE_BOLD; newformat.yHeight = oldformat.yHeight * 5 / 4; newformat.crTextColor = RGB(255,170,170); SendMessage (ConWindow, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&newformat); // Indent the rest of the text to make the error message stand out a little more. paraformat.cbSize = sizeof(paraformat); paraformat.dwMask = PFM_STARTINDENT | PFM_OFFSETINDENT | PFM_RIGHTINDENT; paraformat.dxStartIndent = paraformat.dxOffset = paraformat.dxRightIndent = 120; SendMessage (ConWindow, EM_SETPARAFORMAT, 0, (LPARAM)¶format); SendMessage (ConWindow, EM_REPLACESEL, FALSE, (LPARAM)"\n"); // Find out where the error lines start for the error icon display control. SendMessage (ConWindow, EM_EXGETSEL, 0, (LPARAM)&end); ErrorIconChar = end.cpMax; // Now start adding the actual error message. SendMessage (ConWindow, EM_REPLACESEL, FALSE, (LPARAM)"Execution could not continue.\n\n"); // Restore old charformat but with light yellow text. oldformat.crTextColor = RGB(255,255,170); SendMessage (ConWindow, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&oldformat); // Add the error text. SendMessage (ConWindow, EM_REPLACESEL, FALSE, (LPARAM)text); // Make sure the error text is not scrolled below the window. SendMessage (ConWindow, EM_LINESCROLL, 0, SendMessage (ConWindow, EM_GETLINECOUNT, 0, 0)); // The above line scrolled everything off the screen, so pretend to move the scroll // bar thumb, which clamps to not show any extra lines if it doesn't need to. SendMessage (ConWindow, EM_SCROLL, SB_PAGEDOWN, 0); } BOOL bRet; MSG msg; while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) { if (bRet == -1) { MessageBox (Window, text, GAMESIG " Fatal Error", MB_OK|MB_ICONSTOP|MB_TASKMODAL); return; } else if (!IsDialogMessage (ErrorPane, &msg)) { TranslateMessage (&msg); DispatchMessage (&msg); } } }
LRESULT CNewCompileDialog::CompileAll(WPARAM wParam, LPARAM lParam) { ShowWindow(SW_SHOW); m_wndProgress.SetPos(_nScript); int nSuccessfulResults = 0; // Clear out the results from previous compiles. _log.Clear(); int scriptsSize = static_cast<int>(_scripts.size()); ASSERT(_nScript < scriptsSize); ScriptId &scriptId = _scripts[_nScript]; // Update the edit control with the current scripts name. m_wndDisplay.SetWindowText(scriptId.GetTitle().c_str()); // Now pump some messages, so the display updates // Read all of the messages in this next loop, // removing each message as we read it. MSG msg; while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE | PM_QS_PAINT | PM_QS_INPUT)) { // If it is a quit message, exit. ASSERT(msg.message != WM_QUIT); // return 1; // Otherwise, dispatch the message. DispatchMessage(&msg); } // End of PeekMessage while loop. if (_fAbort) { _fDone = true; OnCancel(); } else { // Do a compile NewCompileScript(_log, _tables, _headers, scriptId); // The compile is done. Post the results. theApp.OutputAddBatch(_log.Results()); } if (!_fAbort) { _nScript++; if (_nScript < (((int)_scripts.size()) - 1)) { PostMessage(UWM_STARTCOMPILE, 0, 0); // Start another compile } else { // Change the text to close: SetDlgItemText(IDCANCEL, "Close"); _fDone = true; // Actually, just close ourselves PostMessage(WM_CLOSE, 0, 0); } } return 0; }
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow) { HDC hDCScreen = GetDC(NULL); int Horres = GetDeviceCaps(hDCScreen, HORZRES); int Vertres = GetDeviceCaps(hDCScreen, VERTRES); HWND hwnd = NULL; HMENU hmenu; MSG msg; WNDCLASSEX wndclass = { 1 }; wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WinProc; wndclass.hInstance = hinstance; wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszClassName = "Class"; hmenu = LoadMenu(hinstance, MAKEINTRESOURCE(IDR_MENU1)); if (!hmenu) return EXIT_FAILURE; // Something bad happened :( RegisterClassEx(&wndclass); hwnd = CreateWindowEx(NULL, // No extra style, "Class", "RSA Шифрование", WS_OVERLAPPEDWINDOW | WS_THICKFRAME, GetDeviceCaps(hDCScreen, HORZRES) / 2 - WINDOW_WIDTH / 2, GetDeviceCaps(hDCScreen, VERTRES) / 2 - WINDOW_HEIGHT / 2, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, hmenu, hinstance, NULL); SetCursorPos(GetDeviceCaps(hDCScreen, HORZRES) / 2, GetDeviceCaps(hDCScreen, VERTRES) / 2); ShowWindow(hwnd, ishow); UpdateWindow(hwnd); while (1) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } } UnregisterClass("Class", hinstance); return msg.wParam; }
void SampleMain() { SfwOpenWindow("Gainput: Gesture sample"); gainput::TrackingAllocator allocator(gainput::GetDefaultAllocator()); gainput::InputManager manager(true, allocator); const gainput::DeviceId keyboardId = manager.CreateDevice<gainput::InputDeviceKeyboard>(); const gainput::DeviceId mouseId = manager.CreateDevice<gainput::InputDeviceMouse>(); gainput::InputDeviceTouch* touchDevice = manager.CreateAndGetDevice<gainput::InputDeviceTouch>(); GAINPUT_ASSERT(touchDevice); gainput::DeviceId touchId = touchDevice->GetDeviceId(); #if defined(GAINPUT_PLATFORM_LINUX) || defined(GAINPUT_PLATFORM_WIN) manager.SetDisplaySize(SfwGetWidth(), SfwGetHeight()); #endif SfwSetInputManager(&manager); gainput::InputMap map(manager, "testmap", allocator); map.MapBool(ButtonConfirm, mouseId, gainput::MouseButtonLeft); gainput::DoubleClickGesture* dcg = manager.CreateAndGetDevice<gainput::DoubleClickGesture>(); GAINPUT_ASSERT(dcg); dcg->Initialize(mouseId, gainput::MouseButtonLeft, mouseId, gainput::MouseAxisX, 0.01f, mouseId, gainput::MouseAxisY, 0.01f, 500); map.MapBool(ButtonConfirmDouble, dcg->GetDeviceId(), gainput::DoubleClickTriggered); gainput::SimultaneouslyDownGesture* sdg = manager.CreateAndGetDevice<gainput::SimultaneouslyDownGesture>(); GAINPUT_ASSERT(sdg); sdg->AddButton(mouseId, gainput::MouseButtonLeft); sdg->AddButton(keyboardId, gainput::KeyShiftL); map.MapBool(ButtonConfirmExtra, sdg->GetDeviceId(), gainput::SimultaneouslyDownTriggered); MultiTouchEmulator* mte = manager.CreateAndGetDevice<MultiTouchEmulator>(); mte->Initialize(sdg->GetDeviceId(), gainput::SimultaneouslyDownTriggered, mouseId, gainput::MouseAxisX, mouseId, gainput::MouseAxisY, mouseId, gainput::MouseButtonLeft, mouseId, gainput::MouseAxisX, mouseId, gainput::MouseAxisY); if (!touchDevice->IsAvailable() || touchDevice->GetVariant() == gainput::InputDevice::DV_NULL) { touchId = mte->GetDeviceId(); } gainput::HoldGesture* hg = manager.CreateAndGetDevice<gainput::HoldGesture>(); GAINPUT_ASSERT(hg); hg->Initialize(touchId, gainput::Touch0Down, touchId, gainput::Touch0X, 0.1f, touchId, gainput::Touch0Y, 0.1f, true, 800); map.MapBool(ButtonHoldGesture, hg->GetDeviceId(), gainput::HoldTriggered); gainput::TapGesture* tg = manager.CreateAndGetDevice<gainput::TapGesture>(); GAINPUT_ASSERT(tg); tg->Initialize(touchId, gainput::Touch0Down, 500); map.MapBool(ButtonTapGesture, tg->GetDeviceId(), gainput::TapTriggered); gainput::PinchGesture* pg = manager.CreateAndGetDevice<gainput::PinchGesture>(); GAINPUT_ASSERT(pg); pg->Initialize(touchId, gainput::Touch0Down, touchId, gainput::Touch0X, touchId, gainput::Touch0Y, touchId, gainput::Touch1Down, touchId, gainput::Touch1X, touchId, gainput::Touch1Y); map.MapBool(ButtonPinching, pg->GetDeviceId(), gainput::PinchTriggered); map.MapFloat(ButtonPinchScale, pg->GetDeviceId(), gainput::PinchScale); gainput::RotateGesture* rg = manager.CreateAndGetDevice<gainput::RotateGesture>(); GAINPUT_ASSERT(rg); rg->Initialize(touchId, gainput::Touch0Down, touchId, gainput::Touch0X, touchId, gainput::Touch0Y, touchId, gainput::Touch1Down, touchId, gainput::Touch1X, touchId, gainput::Touch1Y); map.MapBool(ButtonRotating, rg->GetDeviceId(), gainput::RotateTriggered); map.MapFloat(ButtonRotateAngle, rg->GetDeviceId(), gainput::RotateAngle); bool doExit = false; while (!SfwIsDone() && !doExit) { manager.Update(); #if defined(GAINPUT_PLATFORM_LINUX) XEvent event; while (XPending(SfwGetXDisplay())) { XNextEvent(SfwGetXDisplay(), &event); manager.HandleEvent(event); if (event.type == DestroyNotify || event.type == ClientMessage) { doExit = true; } } #elif defined(GAINPUT_PLATFORM_WIN) MSG msg; while (PeekMessage(&msg, SfwGetHWnd(), 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); manager.HandleMessage(msg); } #endif SfwUpdate(); if (map.GetBoolWasDown(ButtonConfirm)) { SFW_LOG("Confirmed!\n"); SFW_LOG("Memory: %u allocs, %u deallocs, %u used bytes\n", static_cast<unsigned>(allocator.GetAllocateCount()), static_cast<unsigned>(allocator.GetDeallocateCount()), static_cast<unsigned>(allocator.GetAllocatedMemory())); } if (map.GetBoolWasDown(ButtonConfirmDouble)) { SFW_LOG("Confirmed doubly!\n"); } if (map.GetBoolWasDown(ButtonConfirmExtra)) { SFW_LOG("Confirmed alternatively!\n"); } if (map.GetBool(ButtonHoldGesture)) { SFW_LOG("Hold triggered!\n"); } if (map.GetBoolWasDown(ButtonTapGesture)) { SFW_LOG("Tapped!\n"); } if (map.GetBool(ButtonPinching)) { SFW_LOG("Pinching: %f\n", map.GetFloat(ButtonPinchScale)); } if (map.GetBool(ButtonRotating)) { SFW_LOG("Rotation angle: %f\n", map.GetFloat(ButtonRotateAngle)); } } SfwCloseWindow(); }
int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { MSG msg; // Windows Message Structure BOOL bDone = FALSE; // Bool Variable To Exit Loop // Ask The User Which Screen Mode They Prefer if (MessageBox(NULL, MSG_RUNINFULLSCREEN, MSG_STARTFULLSCREEN, MB_YESNO | MB_ICONQUESTION) == IDNO) { g_bFullscreen = FALSE; // Windowed Mode } // Create Our OpenGL Window if (!CreateGLWindow(WINDOW_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BIT, g_bFullscreen)) { return 0; // Quit If Window Was Not Created } while (!bDone) // Loop That Runs While done=FALSE { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) // Is There A Message Waiting? { if (msg.message == WM_QUIT) // Have We Received A Quit Message? { bDone = TRUE; // If So done=TRUE } else // If Not, Deal With Window Messages { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else // If There Are No Messages { // Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene() if (g_bActive) // Program Active? { if (g_bKeysArr[VK_ESCAPE]) // Was ESC Pressed? { bDone = TRUE; // ESC Signalled A Quit } else // Not Time To Quit, Update Screen { DrawGLScene(); // Draw The Scene SwapBuffers(hDC); // Swap Buffers (Double Buffering) if (g_bKeysArr['L'] && !g_bLPress) // L key being pressed not held? { g_bLPress = TRUE; // Become TRUE g_bLight = !g_bLight; // Toggle light TRUE/FALSE if (!g_bLight) { glDisable(GL_LIGHTING); // Disable lighting } else { glEnable(GL_LIGHTING); // Enable lighting } } if (!g_bKeysArr['L']) // Has L key been released? { g_bLPress = FALSE; // If so, become FALSE } if (g_bKeysArr['F'] && !g_bFPress) // Is F key being pressed not held? { g_bFPress = TRUE; g_uFilter += 1; if (g_uFilter > 2) { g_uFilter = 0; } } if (!g_bKeysArr['F']) { g_bFPress = FALSE; } } } if (g_bKeysArr[VK_F1]) // Is F1 Being Pressed? { g_bKeysArr[VK_F1] = FALSE; // If So Make Key FALSE KillGLWindow(); // Kill Our Current Window g_bFullscreen = !g_bFullscreen; // Toggle Full screen / Windowed Mode // Recreate Our OpenGL Window if (!CreateGLWindow(WINDOW_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BIT, g_bFullscreen)) { return 0; // Quit If Window Was Not Created } } // Handle move left-right if (g_bKeysArr[VK_LEFT]) { g_bKeysArr[VK_LEFT] = FALSE; g_MoveX -= g_MDeltaX; } if (g_bKeysArr[VK_RIGHT]) { g_bKeysArr[VK_RIGHT] = FALSE; g_MoveX += g_MDeltaX; } // Handle move up-down if (g_bKeysArr[VK_UP]) { g_bKeysArr[VK_UP] = FALSE; g_MoveY += g_MDeltaY; } if (g_bKeysArr[VK_DOWN]) { g_bKeysArr[VK_DOWN] = FALSE; g_MoveY -= g_MDeltaY; } // Handle move forward-backward if (g_bKeysArr[VK_ADD]) { g_bKeysArr[VK_ADD] = FALSE; g_MoveZ -= g_MDeltaZ; } // Handle rotate follow X asix if (g_bKeysArr[VK_INSERT]) { g_bKeysArr[VK_INSERT] = FALSE; g_RotateX += g_RDeltaX; } if (g_bKeysArr[VK_DELETE]) { g_bKeysArr[VK_DELETE] = FALSE; g_RotateX -= g_RDeltaX; } // Handle rotate follow Y asix if (g_bKeysArr[VK_HOME]) { g_bKeysArr[VK_HOME] = FALSE; g_RotateY += g_RDeltaY; } if (g_bKeysArr[VK_END]) { g_bKeysArr[VK_END] = FALSE; g_RotateY -= g_RDeltaY; } // Handle rotate follow Z axis if (g_bKeysArr[VK_PRIOR]) { g_bKeysArr[VK_PRIOR] = FALSE; //g_RotateZ += g_RDeltaZ; g_MoveZ -= 0.02f; } if (g_bKeysArr[VK_NEXT]) { g_bKeysArr[VK_NEXT] = FALSE; //g_RotateZ -= g_RDeltaZ; g_MoveZ += 0.02f; } if (g_bKeysArr[VK_SUBTRACT]) { g_bKeysArr[VK_SUBTRACT] = FALSE; g_MoveZ += g_MDeltaZ; } if (g_bKeysArr[VK_TAB]) { g_bKeysArr[VK_TAB] = FALSE; } } } // Shutdown KillGLWindow(); // Kill The Window return (msg.wParam); // Exit The Program }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nCmdShow*/) { SetDllDirectory(L""); SetTaskIDPerUUID(); CRegStdDWORD loc = CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033); long langId = loc; CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); CLangDll langDLL; hResource = langDLL.Init(_T("TortoiseIDiff"), langId); if (hResource == NULL) hResource = hInstance; CCmdLineParser parser(lpCmdLine); if (parser.HasKey(_T("?")) || parser.HasKey(_T("help"))) { TCHAR buf[1024] = { 0 }; LoadString(hResource, IDS_COMMANDLINEHELP, buf, _countof(buf)); MessageBox(NULL, buf, _T("TortoiseIDiff"), MB_ICONINFORMATION); langDLL.Close(); return 0; } MSG msg; hInst = hInstance; INITCOMMONCONTROLSEX used = { sizeof(INITCOMMONCONTROLSEX), ICC_STANDARD_CLASSES | ICC_BAR_CLASSES | ICC_WIN95_CLASSES }; InitCommonControlsEx(&used); // load the cursors we need curHand = (HCURSOR)LoadImage(hInst, MAKEINTRESOURCE(IDC_PANCUR), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE); curHandDown = (HCURSOR)LoadImage(hInst, MAKEINTRESOURCE(IDC_PANDOWNCUR), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE); std::unique_ptr<CMainWindow> mainWindow(new CMainWindow(hResource)); mainWindow->SetRegistryPath(_T("Software\\TortoiseGit\\TortoiseIDiffWindowPos")); std::wstring leftfile = parser.HasVal(_T("left")) ? parser.GetVal(_T("left")) : _T(""); std::wstring rightfile = parser.HasVal(_T("right")) ? parser.GetVal(_T("right")) : _T(""); if ((leftfile.empty()) && (lpCmdLine[0] != 0)) { int nArgs; LPWSTR * szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); if (szArglist) { if (nArgs == 3) { // Four parameters: // [0]: Program name // [1]: left file // [2]: right file if (PathFileExists(szArglist[1]) && PathFileExists(szArglist[2])) { leftfile = szArglist[1]; rightfile = szArglist[2]; } } } // Free memory allocated for CommandLineToArgvW arguments. LocalFree(szArglist); } mainWindow->SetLeft(leftfile.c_str(), parser.HasVal(_T("lefttitle")) ? parser.GetVal(_T("lefttitle")) : _T("")); mainWindow->SetRight(rightfile.c_str(), parser.HasVal(_T("righttitle")) ? parser.GetVal(_T("righttitle")) : _T("")); if (parser.HasVal(L"base")) mainWindow->SetSelectionImage(FileTypeBase, parser.GetVal(L"base"), parser.HasVal(L"basetitle") ? parser.GetVal(L"basetitle") : L""); if (parser.HasVal(L"mine")) mainWindow->SetSelectionImage(FileTypeMine, parser.GetVal(L"mine"), parser.HasVal(L"minetitle") ? parser.GetVal(L"minetitle") : L""); if (parser.HasVal(L"theirs")) mainWindow->SetSelectionImage(FileTypeTheirs, parser.GetVal(L"theirs"), parser.HasVal(L"theirstitle") ? parser.GetVal(L"theirstitle") : L""); if (parser.HasVal(L"result")) mainWindow->SetSelectionResult(parser.GetVal(L"result")); if (mainWindow->RegisterAndCreateWindow()) { HACCEL hAccelTable = LoadAccelerators(hResource, MAKEINTRESOURCE(IDR_TORTOISEIDIFF)); if (!parser.HasVal(L"left") && parser.HasVal(L"base") && !parser.HasVal(L"mine") && !parser.HasVal(L"theirs")) { PostMessage(*mainWindow, WM_COMMAND, ID_FILE_OPEN, 0); } if (parser.HasKey(_T("overlay"))) { PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_OVERLAPIMAGES, 0); } if (parser.HasKey(_T("fit"))) { PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_FITIMAGEHEIGHTS, 0); PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_FITIMAGEWIDTHS, 0); } if (parser.HasKey(_T("fitwidth"))) { PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_FITIMAGEWIDTHS, 0); } if (parser.HasKey(_T("fitheight"))) { PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_FITIMAGEHEIGHTS, 0); } if (parser.HasKey(_T("showinfo"))) { PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_IMAGEINFO, 0); } // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(*mainWindow, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; } langDLL.Close(); DestroyCursor(curHand); DestroyCursor(curHandDown); CoUninitialize(); return 1; }
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow) { WNDCLASSEX wcex; MSG Msg; HWND hWnd; // Initialize the COM system CoInitialize(NULL); // Create the window class here and register it wcex.cbSize = sizeof(wcex); wcex.style = CS_CLASSDC; wcex.lpfnWndProc = WindowProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInst; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = NULL; wcex.lpszMenuName = NULL; wcex.lpszClassName = g_szClass; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wcex)) return FALSE; // Create the main window hWnd = CreateWindow(g_szClass, g_szCaption, WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 640, 480, NULL, NULL, hInst, NULL); if(!hWnd) return FALSE; ShowWindow(hWnd, SW_NORMAL); UpdateWindow(hWnd); // Call init function and enter message pump if(DoInit(hWnd) == TRUE) { // Start message pump, waiting for user to exit ZeroMemory(&Msg, sizeof(MSG)); while(Msg.message != WM_QUIT) { if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } // Render a single frame DoFrame(); } } // Call shutdown DoShutdown(); // Unregister the window class UnregisterClass(g_szClass, hInst); // Shut down the COM system CoUninitialize(); return 0; }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(nCmdShow); SetDllDirectory(L""); SetTaskIDPerUUID(); MSG msg; HACCEL hAccelTable; CCmdLineParser parser(lpCmdLine); if (parser.HasKey(_T("?")) || parser.HasKey(_T("help"))) { TCHAR buf[1024]; LoadString(hInstance, IDS_COMMANDLINEHELP, buf, sizeof(buf)/sizeof(TCHAR)); MessageBox(NULL, buf, _T("TortoiseGitUDiff"), MB_ICONINFORMATION); return 0; } INITCOMMONCONTROLSEX used = { sizeof(INITCOMMONCONTROLSEX), ICC_STANDARD_CLASSES | ICC_BAR_CLASSES }; InitCommonControlsEx(&used); HMODULE hSciLexerDll = ::LoadLibrary(_T("SciLexer.DLL")); if (hSciLexerDll == NULL) return FALSE; CMainWindow mainWindow(hInstance); mainWindow.SetRegistryPath(_T("Software\\TortoiseGit\\UDiffViewerWindowPos")); if (parser.HasVal(_T("title"))) mainWindow.SetTitle(parser.GetVal(_T("title"))); else if (parser.HasVal(_T("patchfile"))) mainWindow.SetTitle(parser.GetVal(_T("patchfile"))); else mainWindow.SetTitle(_T("diff from pipe")); if (!mainWindow.RegisterAndCreateWindow()) { FreeLibrary(hSciLexerDll); return 0; } bool bLoadedSuccessfully = false; if ( (lpCmdLine[0] == 0) || (parser.HasKey(_T("p"))) ) { // input from console pipe // set console to raw mode DWORD oldMode; GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &oldMode); SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), oldMode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT)); bLoadedSuccessfully = mainWindow.LoadFile(GetStdHandle(STD_INPUT_HANDLE)); } else if (parser.HasVal(_T("patchfile"))) bLoadedSuccessfully = mainWindow.LoadFile(parser.GetVal(_T("patchfile"))); else if (lpCmdLine[0] != 0) bLoadedSuccessfully = mainWindow.LoadFile(lpCmdLine); if (!bLoadedSuccessfully) { FreeLibrary(hSciLexerDll); return 0; } ::ShowWindow(mainWindow.GetHWNDEdit(), SW_SHOW); ::SetFocus(mainWindow.GetHWNDEdit()); hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TORTOISEUDIFF)); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(mainWindow, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } FreeLibrary(hSciLexerDll); return (int) msg.wParam; }
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { // define our window class WNDCLASSEX wc = { 0 }; wc.cbSize = sizeof(wc); wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.lpszClassName = "Module 3"; RegisterClassExA(&wc); DWORD dwExStyle = 0; DWORD dwStyle = WS_OVERLAPPEDWINDOW; //BOOL Fullscreen = FALSE; // //if (Fullscreen) //{ // DEVMODE dmScreenSettings = { 0 }; // dmScreenSettings.dmSize = sizeof(dmScreenSettings); // dmScreenSettings.dmPelsWidth = BufferWidth; // dmScreenSettings.dmPelsHeight = BufferHeight; // dmScreenSettings.dmBitsPerPel = 32; // dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; // // if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) == //DISP_CHANGE_SUCCESSFUL) // { // dwExStyle = WS_EX_APPWINDOW; // dwStyle = WS_POPUP; // } // else // { // Fullscreen = FALSE; // } //} // create rectangle for window RECT r = { 0 }; r.right = WindowWidth; r.bottom = WindowHeight; AdjustWindowRectEx(&r, dwStyle, 0, dwExStyle); // create our window HWND MainWindow = CreateWindowEx( dwExStyle, "Module 3", "Lesson 3.5", dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, NULL, NULL, hInstance, 0); //if (Fullscreen) // SetWindowLong(MainWindow, GWL_STYLE, 0); ShowWindow(MainWindow, nShowCmd); // define our bitmap info BitMapInfo.bmiHeader.biSize = sizeof(BitMapInfo.bmiHeader); BitMapInfo.bmiHeader.biWidth = BufferWidth; BitMapInfo.bmiHeader.biHeight = -BufferHeight; BitMapInfo.bmiHeader.biPlanes = 1; BitMapInfo.bmiHeader.biBitCount = 8 * BytesPerPixel; BitMapInfo.bmiHeader.biCompression = BI_RGB; BackBuffer = malloc(BufferWidth * BufferHeight * BytesPerPixel); //if (BytesPerPixel == 1) { FILE *Palette = fopen("palette.lmp", "rb"); void *RawData = malloc(256 * 3); unsigned char* PaletteData = RawData; size_t Ret = fread(PaletteData, 1, 768, Palette); for (int i = 0; i < 256; i++) { BitMapInfo.acolors[i].rgbRed = *PaletteData++; BitMapInfo.acolors[i].rgbGreen = *PaletteData++; BitMapInfo.acolors[i].rgbBlue = *PaletteData++; } free(RawData); fclose(Palette); } FILE * Disc = fopen("DISC.lmp", "rb"); int DiscWidth, DiscHeight; size_t RetVal = fread(&DiscWidth, 1, 4, Disc); RetVal = fread(&DiscHeight, 1, 4, Disc); void* DiscData = malloc(DiscWidth * DiscHeight); RetVal = fread(DiscData, 1, DiscWidth * DiscHeight, Disc); fclose(Disc); FILE *Pause = fopen("pause.lmp", "rb"); int PauseWidth, PauseHeight; RetVal = fread(&PauseWidth, 1, 4, Pause); RetVal = fread(&PauseHeight, 1, 4, Pause); void *PauseData = malloc(PauseWidth * PauseHeight); RetVal = fread(PauseData, 1, PauseWidth * PauseHeight, Pause); fclose(Pause); MSG msg; while (Running) { while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if (BytesPerPixel == 4) { int *MemoryWalker = (int*)BackBuffer; for (int Height = 0; Height < BufferHeight; Height++) { for (int Width = 0; Width < BufferWidth; Width++) { unsigned char Red = rand() % 256; unsigned char Green = rand() % 256; unsigned char Blue = rand() % 256; *MemoryWalker++ = ((Red << 16) | (Green << 8) | Blue); } } DrawPic32(10, 10, DiscWidth, DiscHeight, DiscData, BackBuffer); DrawPic32(100, 100, PauseWidth, PauseHeight, PauseData, BackBuffer); //DrawRect(10, 10, 300, 150, 255, 0, 255, BackBuffer); } else if (BytesPerPixel == 1) { unsigned char *MemoryWalker = BackBuffer; for (int Height = 0; Height < BufferHeight; Height++) { for (int Width = 0; Width < BufferWidth; Width++) { *MemoryWalker++ = rand() % 256; } } //DrawPic8(10, 10, DiscWidth, DiscHeight, DiscData, BackBuffer); //DrawPic8(100, 100, PauseWidth, PauseHeight, PauseData, BackBuffer); //DrawRect8(10, 10, 300, 150, 1, BackBuffer); } HDC dc = GetDC(MainWindow); StretchDIBits(dc, 0, 0, WindowWidth, WindowHeight, 0, 0, BufferWidth, BufferHeight, BackBuffer, (BITMAPINFO*)&BitMapInfo, DIB_RGB_COLORS, SRCCOPY); ReleaseDC(MainWindow, dc); } free(BackBuffer); free(DiscData); free(PauseData); return EXIT_SUCCESS; }
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hInstP, LPSTR lpCmdLine, int nCmdShow) { MSG msg={0}; WNDCLASS wc; // Initialize COM if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) { Msg(TEXT("CoInitialize Failed!\r\n")); exit(1); } // Register the window class ZeroMemory(&wc, sizeof wc); wc.lpfnWndProc = WndMainProc; wc.hInstance = hInstance; wc.lpszClassName = CLASSNAME; wc.lpszMenuName = NULL; wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = NULL; if(!RegisterClass(&wc)) { Msg(TEXT("RegisterClass Failed! Error=0x%x\r\n"), GetLastError()); CoUninitialize(); exit(1); } // Create the main window. The WS_CLIPCHILDREN style is required. ghApp = CreateWindow(CLASSNAME, APPLICATIONNAME, WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT, 0, 0, hInstance, 0); if(ghApp) { HRESULT hr; // Create DirectShow graph and start capturing video hr = CaptureVideo(); if (FAILED (hr)) { CloseInterfaces(); DestroyWindow(ghApp); } else { // Don't display the main window until the DirectShow // preview graph has been created. Once video data is // being received and processed, the window will appear // and immediately have useful video data to display. // Otherwise, it will be black until video data arrives. ShowWindow(ghApp, nCmdShow); } // Main message loop while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } // Release COM CoUninitialize(); return (int) msg.wParam; }
/* Initialize(). We already have a window from the screensaver, so store it and pass along all 0's to initialize a child window. */ bool CDisplayDX::Initialize( HWND _hWnd, bool _bPreview ) { m_bScreensaver = true; m_bPreview = _bPreview; m_WindowHandle = _hWnd; HMODULE hInstance = GetModuleHandle( NULL ); WNDCLASS wc = {0}; wc.style = CS_VREDRAW | CS_HREDRAW; wc.lpfnWndProc = (WNDPROC)CDisplayDX::wndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(1)); wc.hCursor = NULL; wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = L"ElectricsheepWndClass"; RegisterClass( &wc ); if( _bPreview ) { g_bPreview = true; RECT rc; //GetWindowRect( _hWnd, &rc ); GetClientRect( _hWnd, &rc ); int32 cx = rc.right - rc.left; int32 cy = rc.bottom - rc.top; g_Log->Info( "rc: %d, %d", cx, cy ); DWORD dwStyle = WS_VISIBLE | WS_CHILD; AdjustWindowRect( &rc, dwStyle, FALSE ); m_WindowHandle = CreateWindow( L"ElectricsheepWndClass", L"Preview", dwStyle, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, _hWnd, NULL, hInstance, NULL ); g_Log->Info( "CDisplayDX::Initialize x=%u y=%u w=%u h=%u", rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top); if( m_WindowHandle == NULL ) { g_Log->Error( "CDisplayDX::Initialize unable to create window for preview" ); //ThrowStr( "Unable to create window..." ); return false; } m_Width = cx; m_Height = cy; g_Log->Info( "Screensaver preview (%dx%d)", cx, cy ); // In preview mode, "pause" (enter a limited message loop) briefly before proceeding, so the display control panel knows to update itself. m_bWaitForInputIdle = true; // Post a message to mark the end of the initial group of window messages PostMessage( m_WindowHandle, WM_USER, 0, 0 ); InvalidateRect( GetParent( _hWnd ), NULL, FALSE ); // Invalidate the hwnd so it gets drawn UpdateWindow( GetParent( _hWnd ) ); UpdateWindow( GetParent( _hWnd ) ); MSG msg; while( m_bWaitForInputIdle ) { // If GetMessage returns FALSE, it's quitting time. if( !GetMessage( &msg, m_WindowHandle, 0, 0 ) ) { // Post the quit message to handle it later PostQuitMessage(0); break; } TranslateMessage( &msg ); DispatchMessage( &msg ); } if( !InitDX9() ) return false; //ShowWindow( _hWnd, SW_SHOW ); //SetForegroundWindow( _hWnd ); SetFocus( _hWnd ); ShowCursor( true ); } else { // int32 cx = GetSystemMetrics( SM_CXSCREEN ); // int32 cy = GetSystemMetrics( SM_CYSCREEN ); RECT rc; GetWindowRect( _hWnd, &rc ); m_Width = rc.right - rc.left; m_Height = rc.bottom - rc.top; g_Log->Info( "CDisplayDX::Initialize right=%u left=%u bottom=%u top=%u", rc.right, rc.left, rc.bottom, rc.top); //DWORD exstyle = 0;//WS_EX_TOPMOST; //DWORD style = WS_CHILD | WS_VISIBLE; m_WindowHandle = _hWnd;//CreateWindowEx( exstyle, "Electricsheep", "Saver", style, 0, 0, cx, cy, _hWnd, NULL, hInstance, NULL ); if( m_WindowHandle == NULL ) { g_Log->Error( "CDisplayDX::Initialize unable to create window from _hWnd" ); return false; } g_Log->Info( "Screensaver (%dx%d)", m_Width, m_Height ); // Hide cursor. ShowCursor( false ); if( !InitDX9() ) return false; } return true; }
static int __cdecl BzipBurnLoadRom(unsigned char* Dest, int* pnWrote, int i) { #if defined (BUILD_WIN32) MSG Msg; #endif struct BurnRomInfo ri; int nWantZip = 0; TCHAR szText[128]; char* pszRomName = NULL; int nRet = 0; if (i < 0 || i >= nRomCount) { return 1; } ri.nLen = 0; BurnDrvGetRomInfo(&ri, i); // Get info // show what we're doing BurnDrvGetRomName(&pszRomName, i, 0); if (pszRomName == NULL) { pszRomName = "unknown"; } _stprintf(szText, _T("Loading")); if (ri.nType & (BRF_PRG | BRF_GRA | BRF_SND | BRF_BIOS)) { if (ri.nType & BRF_BIOS) { _stprintf (szText + _tcslen(szText), _T(" %s"), _T("BIOS ")); } if (ri.nType & BRF_PRG) { _stprintf (szText + _tcslen(szText), _T(" %s"), _T("program ")); } if (ri.nType & BRF_GRA) { _stprintf (szText + _tcslen(szText), _T(" %s"), _T("graphics ")); } if (ri.nType & BRF_SND) { _stprintf (szText + _tcslen(szText), _T(" %s"), _T("sound ")); } _stprintf(szText + _tcslen(szText), _T("(%hs)..."), pszRomName); } else { _stprintf(szText + _tcslen(szText), _T(" %hs..."), pszRomName); } ProgressUpdateBurner(ri.nLen ? 1.0 / ((double)nTotalSize / ri.nLen) : 0, szText, 0); #if defined (BUILD_WIN32) // Check for messages: while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) { DispatchMessage(&Msg); } #endif if (RomFind[i].nState == 0) { // Rom not found in zip at all return 1; } nWantZip = RomFind[i].nZip; // Which zip file it is in if (nCurrentZip != nWantZip) { // If we haven't got the right zip file currently open ZipClose(); nCurrentZip = -1; if (ZipOpen(TCHARToANSI(szBzipName[nWantZip], NULL, 0))) { return 1; } nCurrentZip = nWantZip; } // Read in file and return how many bytes we read if (ZipLoadFile(Dest, ri.nLen, pnWrote, RomFind[i].nPos)) { // Error loading from the zip file FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(nRet == 2 ? IDS_ERR_LOAD_DISK_CRC : IDS_ERR_LOAD_DISK), pszRomName, GetFilenameW(szBzipName[nCurrentZip])); FBAPopupDisplay(PUF_TYPE_WARNING); return 1; } return 0; }
int WINAPI wWinMain ( HINSTANCE hInstance , HINSTANCE prevInstance , LPWSTR cmdLine , int cmdShow ) { UNREFERENCED_PARAMETER ( prevInstance ); UNREFERENCED_PARAMETER ( cmdLine ); WNDCLASSEX wndClass = { 0 }; wndClass.cbSize = sizeof ( WNDCLASSEX ); wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WndProc; wndClass.hInstance = hInstance; wndClass.hCursor = LoadCursor ( NULL , IDC_ARROW ); wndClass.hbrBackground = ( HBRUSH ) ( COLOR_WINDOW + 1 ); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = "DX11BookWindowClass"; if( !RegisterClassEx( &wndClass )) { return -1; } RECT rc = { 0 , 0 , 640 , 480 }; AdjustWindowRect( &rc , WS_OVERLAPPEDWINDOW , FALSE ); HWND hwnd = CreateWindowEx ( WS_EX_OVERLAPPEDWINDOW, "DX11BookWindowClass" , "Blank Direct3D 11 Window" , WS_OVERLAPPEDWINDOW , CW_USEDEFAULT , CW_USEDEFAULT , rc.right - rc.left , rc.bottom - rc.top , NULL , NULL , hInstance , NULL ); /* HWND hwnd = CreateWindowA ( "DX11BookWindowClass" , "Blank Direct 3D 11 Window" , WS_OVERLAPPEDWINDOW , CW_USEDEFAULT , CW_USEDEFAULT , rc.right - rc.left , rc.bottom - rc.top , NULL , NULL , hInstance , NULL ); */ if( !hwnd ) return -1; ShowWindow( hwnd , cmdShow ); std :: auto_ptr< Dx11DemoBase >demo ( new ColorInversionDemo()); //Demo Initialize bool result = demo ->Initialize ( hInstance , hwnd ); //Error reporting if there is an issue if( result == false ) return -1; MSG msg = { 0 }; while ( msg.message != WM_QUIT ) { if( PeekMessage ( &msg , 0 , 0 , 0 , PM_REMOVE )) { TranslateMessage( & msg ); DispatchMessage ( & msg ); } else { //Update and draw demo ->Update (0.0f); demo ->Render ( ); } } //demo shutdown demo ->Shutdown( ); return static_cast<int>( msg.wParam ); }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { atexit(dumpLeaks); // _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); if (strstr(lpCmdLine, "-s") != 0) { Setup(true, false); exit(0); } lang.init(); StringCache::getInstance().init(); GetCurrentDirectory(MAX_PATH, programPath); getUserFile(settings, "meospref.xml"); Parser::test(); int rInit = (GetTickCount() / 100); InitRanom(rInit, rInit/379); tabList=new list<TabObject>; MSG msg; HACCEL hAccelTable; gdi_main = new gdioutput("main", 1.0, ANSI); gdi_extra.push_back(gdi_main); try { gEvent = new oEvent(*gdi_main); } catch (std::exception &ex) { gdi_main->alert(string("Failed to create base event: ") + ex.what()); return 0; } gEvent->loadProperties(settings); lang.get().addLangResource("English", "104"); lang.get().addLangResource("Svenska", "103"); lang.get().addLangResource("Deutsch", "105"); lang.get().addLangResource("Dansk", "106"); lang.get().addLangResource("Russian (ISO 8859-5)", "107"); lang.get().addLangResource("English (ISO 8859-2)", "108"); if (fileExist("extra.lng")) { lang.get().addLangResource("Extraspråk", "extra.lng"); } else { char lpath[260]; getUserFile(lpath, "extra.lng"); if (fileExist(lpath)) lang.get().addLangResource("Extraspråk", lpath); } string defLang = gEvent->getPropertyString("Language", "Svenska"); // Backward compatibility if (defLang=="103") defLang = "Svenska"; else if (defLang=="104") defLang = "English"; gEvent->setProperty("Language", defLang); try { lang.get().loadLangResource(defLang); } catch (std::exception &) { lang.get().loadLangResource("Svenska"); } try { char listpath[MAX_PATH]; getUserFile(listpath, ""); vector<string> res; expandDirectory(listpath, "*.lxml", res); expandDirectory(listpath, "*.listdef", res); # #ifdef _DEBUG expandDirectory(".\\Lists\\", "*.lxml", res); expandDirectory(".\\Lists\\", "*.listdef", res); #endif string err; for (size_t k = 0; k<res.size(); k++) { try { xmlparser xml(0); strcpy_s(listpath, res[k].c_str()); xml.read(listpath); xmlobject xlist = xml.getObject(0); gEvent->getListContainer().load(MetaListContainer::InternalList, xlist, true); } catch (std::exception &ex) { string errLoc = "Kunde inte ladda X\n\n(Y)#" + string(listpath) + "#" + lang.tl(ex.what()); if (err.empty()) err = errLoc; else err += "\n" + errLoc; } } if (!err.empty()) gdi_main->alert(err); } catch (std::exception &ex) { gdi_main->alert(ex.what()); //exit(1); } gEvent->openRunnerDatabase("database"); strcpy_s(szTitle, "MeOS"); strcpy_s(szWindowClass, "MeosMainClass"); strcpy_s(szWorkSpaceClass, "MeosWorkSpace"); MyRegisterClass(hInstance); registerToolbar(hInstance); string encoding = lang.tl("encoding"); gdi_main->setFont(gEvent->getPropertyInt("TextSize", 0), gEvent->getPropertyString("TextFont", "Arial"), interpetEncoding(encoding)); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } RECT rc; GetClientRect(hWndMain, &rc); SendMessage(hWndMain, WM_SIZE, 0, MAKELONG(rc.right, rc.bottom)); gdi_main->init(hWndWorkspace, hWndMain, hMainTab); gdi_main->getTabs().get(TCmpTab)->loadPage(*gdi_main); autoTask = new AutoTask(hWndMain, *gEvent, *gdi_main); autoTask->setTimers(); // Install a hook procedure to monitor the message stream for mouse // messages intended for the controls in the dialog box. g_hhk = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, (HINSTANCE) NULL, GetCurrentThreadId()); hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MEOS); initMySQLCriticalSection(true); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } tabAutoRegister(0); tabList->clear(); delete tabList; tabList=0; delete autoTask; autoTask = 0; for (size_t k = 0; k<gdi_extra.size(); k++) { if (gdi_extra[k]) { DestroyWindow(gdi_extra[k]->getHWND()); if (k < gdi_extra.size()) { delete gdi_extra[k]; gdi_extra[k] = 0; } } } gdi_extra.clear(); if (gEvent) gEvent->saveProperties(settings); delete gEvent; gEvent = 0; initMySQLCriticalSection(false); removeTempFiles(); #ifdef _DEBUG lang.get().debugDump("untranslated.txt", "translated.txt"); #endif StringCache::getInstance().clear(); lang.unload(); return msg.wParam; }
/******************************************************************** * Function : WinMain() * Purpose : Mandatory Windows Init function. ********************************************************************/ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; HWND hwnd; WNDCLASS wc; static char ClassName[] = "ChromeTestingFacility"; DDSURFACEDESC ddsd; DDSCAPS ddscaps; HRESULT ddreturn; int n; // Set all key booleans to FALSE, assume no key is pressed. bForwardKey = FALSE; bBackKey = FALSE; bLeftKey = FALSE; bRightKey = FALSE; nState = 0; nGauge = 0; lpCmdLine = lpCmdLine; hPrevInstance = hPrevInstance; RealTime = 0; /* Start of using spacebar for frameflipping. */ /* Register and realize our display window */ wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = ClassName; wc.lpszClassName = ClassName; RegisterClass(&wc); /* Initialize our test world. */ if (!InitWorld(XRES, YRES, Colormap)) { return FALSE; } /* Convert the Chrome colormap to a windows colormap. */ for (n = 0; n < 256; n++) { WinColormap[n].peRed = (unsigned char)((Colormap[n] & 0xFF0000) >> 16); WinColormap[n].peGreen = (unsigned char)((Colormap[n] & 0xFF00) >> 8); WinColormap[n].peBlue = (unsigned char)((Colormap[n] & 0xFF)); WinColormap[n].peFlags = 0; } /* Create a full screen window so that GDI won't ever be * called. */ hwnd = CreateWindowEx(WS_EX_TOPMOST, ClassName, ClassName, WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); if (hwnd == NULL) return FALSE; ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); SetFocus(hwnd); ShowCursor(FALSE); /* Remove cursor to prevent GDI from writing. */ /* Instanciate our DirectDraw object */ ddreturn = DirectDrawCreate(NULL, &lpDirectDrawObject, NULL); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } ddreturn = lpDirectDrawObject->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN| DDSCL_ALLOWMODEX); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } /* Create a palette for the surfaces. */ ddreturn = lpDirectDrawObject->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE, (LPPALETTEENTRY)WinColormap, &lpPalette, NULL); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } /* Set the video mode to XRESxYRESx8. */ ddreturn = lpDirectDrawObject->SetDisplayMode(XRES, YRES, 8); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } /* Create a default font for the application. */ AppFont = CreateFont(11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, VARIABLE_PITCH, "Comic Sans MS"); /* Create the primary surface and one back buffer surface */ ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; ddreturn = lpDirectDrawObject->CreateSurface(&ddsd, &lpPrimary, NULL); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } ddreturn = lpPrimary->SetPalette(lpPalette); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } /* Get a surface pointer to our back buffer. */ ddscaps.dwCaps = DDSCAPS_BACKBUFFER; ddreturn = lpPrimary->GetAttachedSurface(&ddscaps, &lpBackbuffer); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } /* ddreturn = lpBackbuffer->SetPalette(lpPalette); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } */ { /* Clear the background once for both buffers so we don't get anoying flicker effect. */ DDBLTFX BltFx; BltFx.dwSize = sizeof(BltFx); BltFx.dwFillColor = 255; ddreturn = lpBackbuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &BltFx); BltFx.dwSize = sizeof(BltFx); BltFx.dwFillColor = 255; ddreturn = lpPrimary->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &BltFx); } while (1) { if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!GetMessage(&msg, NULL, 0, 0)) return msg.wParam; TranslateMessage(&msg); DispatchMessage(&msg); } else { if (ActiveApp && RealTime) { // Simulation Iteration should go here. // Only do this when running Realtime. SimLoop(); } else { WaitMessage(); } } } }