当前位置: 首页>>代码示例>>C++>>正文


C++ DispatchMessage函数代码示例

本文整理汇总了C++中DispatchMessage函数的典型用法代码示例。如果您正苦于以下问题:C++ DispatchMessage函数的具体用法?C++ DispatchMessage怎么用?C++ DispatchMessage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DispatchMessage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WinMain

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);
} 
开发者ID:mikanradojevic,项目名称:sdkpub,代码行数:66,代码来源:WINCAI02.C

示例2: wWinMain

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;
}
开发者ID:codrut-n,项目名称:FunTetris,代码行数:66,代码来源:Main.cpp

示例3: WinMain

/* ************************************
* 功能	显示一个窗口
**************************************/
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; 

} 
开发者ID:Trietptm-on-Coding-Algorithms,项目名称:CodeLibrary,代码行数:77,代码来源:window.cpp

示例4: WinMain


//.........这里部分代码省略.........
	}

	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,"[email protected]");
	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,
	                   &regKey,
	                   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;
}
开发者ID:AaronOpfer,项目名称:PoEPulse,代码行数:101,代码来源:main.cpp

示例5: __declspec

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);
}
开发者ID:engineer0x47,项目名称:NSIS,代码行数:62,代码来源:splash.c

示例6: vlc_mutex_lock


//.........这里部分代码省略.........
        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;
}
开发者ID:Kafay,项目名称:vlc,代码行数:101,代码来源:win32.c

示例7: _tmain

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;
}
开发者ID:vbarbarosh,项目名称:w339_winapi_env,代码行数:65,代码来源:message.c

示例8: _tWinMain

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;
}
开发者ID:alexmarsev,项目名称:traybin,代码行数:69,代码来源:traybin.cpp

示例9: WinMain

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;

}
开发者ID:DevCool,项目名称:CPP_Dev,代码行数:68,代码来源:Main.cpp

示例10: WinMain

//-----------------------------------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
	

//.........这里部分代码省略.........
开发者ID:EdwinVelazquez,项目名称:Neural-net,代码行数:101,代码来源:main.cpp

示例11: 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;
}
开发者ID:Fliper12,项目名称:darkbasicpro,代码行数:84,代码来源:xmain.cpp

示例12: mswin_display_RIP_window

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;
}
开发者ID:gurrhack,项目名称:NetHack-Android,代码行数:80,代码来源:mhrip.c

示例13: _tWinMain

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;
}
开发者ID:toughie88,项目名称:E3DSamples,代码行数:69,代码来源:Wall.cpp

示例14: wWinMain

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;
}
开发者ID:BillyKim,项目名称:directxcode,代码行数:80,代码来源:Vertex_alpha_Texture_color.cpp

示例15: ShowErrorPane

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)&paraformat);
		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);
		}
	}
}
开发者ID:TerminusEst13,项目名称:GLOOME,代码行数:97,代码来源:i_main.cpp


注:本文中的DispatchMessage函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。