2010-03-31 47 views
0

win32的Windows應用程序,並希望捕獲全屏和刪除窗口的邊框顯示任何一個告訴我如何,如果這個窗口捕獲鼠標鍵盤控件,那麼它會是理想的?我有一個win32的Windows應用程序,並希望捕獲全屏和刪除窗口的邊框顯示?

// MonitorScreen.cpp : Defines the entry point for the application. // 

#include "stdafx.h" 
#include "MonitorScreen.h 

#define MAX_LOADSTRING 100 

// Global Variables: HINSTANCE hInst;        // current instance TCHAR szTitle[MAX_LOADSTRING];     // The title bar text TCHAR szWindowClass[MAX_LOADSTRING];   // the main window class name 

// Forward declarations of functions included in this code module: ATOM    MyRegisterClass(HINSTANCE hInstance); BOOL    InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); 

int APIENTRY _tWinMain(HINSTANCE hInstance, 
        HINSTANCE hPrevInstance, 
        LPTSTR lpCmdLine, 
        int  nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); 

    // TODO: Place code here. MSG msg; HACCEL hAccelTable; 

    // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MONITORSCREEN, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); 

    // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) {  return FALSE; } 

    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MONITORSCREEN)); 

    // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) {  if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))   {   TranslateMessage(&msg);    DispatchMessage(&msg);  } } 

    return (int) msg.wParam; } 



// // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage are only necessary if you want this code // to be compatible with Win32 systems prior to the 'RegisterClassEx' // function that was added to Windows 95. It is important to call this function // so that the application will get 'well formed' small icons associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) {  WNDCLASSEX wcex; 

    int s =sizeof(WNDCLASSEX); wcex.cbSize =sizeof(WNDCLASSEX); 

    wcex.style   = DESKTOP_HOOKCONTROL ;//CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra  = 0; wcex.cbWndExtra  = 0; wcex.hInstance  = NULL;//hInstance;  wcex.hIcon   = NULL;//LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MONITORSCREEN)); wcex.hCursor  = NULL;//LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(9); wcex.lpszMenuName = NULL;//MAKEINTRESOURCE(IDC_MONITORSCREEN); wcex.lpszClassName = szWindowClass; wcex.hIconSm  = NULL;//LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); 

    return RegisterClassEx(&wcex); } 

// // FUNCTION: InitInstance(HINSTANCE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // //  In this function, we save the instance handle in a global variable and //  create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; 

    hInst = hInstance; // Store instance handle in our global variable 

    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 
     CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); 

    if (!hWnd) { 
     return FALSE; } 

    ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); 

    return TRUE; } 

// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps;  HDC hdc; 

    switch (message) { case WM_COMMAND:  wmId = LOWORD(wParam);  wmEvent 
= HIWORD(wParam);  // Parse the menu selections:  switch (wmId)  {  case IDM_ABOUT:    DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);   break;  case IDM_EXIT:   DestroyWindow(hWnd);   break;  default:   return DefWindowProc(hWnd, message, wParam, lParam);  }  break; case WM_PAINT:  hdc = BeginPaint(hWnd, &ps);  // TODO: Add any drawing code here...  EndPaint(hWnd, &ps);  break; case WM_DESTROY:  PostQuitMessage(0);   break; default:  return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } 

// Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam);  switch (message) { case WM_INITDIALOG:   return (INT_PTR)TRUE; 

    case WM_COMMAND:  if (LOWORD(wParam) 
== IDOK || LOWORD(wParam) == IDCANCEL)  {   EndDialog(hDlg, LOWORD(wParam));   return (INT_PTR)TRUE;  }  break; } return (INT_PTR)FALSE; } 
+0

你試過了什麼?這是一個簡單的谷歌問題。 – RvdK 2010-03-31 07:29:43

+1

@PoweRoy:允許和鼓勵「谷歌問題」。 – 2010-03-31 07:31:27

+1

好吧,我要發佈我的龐大代碼。 – Badr 2010-03-31 07:32:12

回答

1

我打算假設你實際上並不想捕捉屏幕,你的問題沒有意義。我猜你只是想讓你的窗口最大化,佔據整個屏幕。把生成的模板代碼回到從前的樣子,只是改變的ShowWindow電話:

ShowWindow(hWnd, SW_MAXIMIZE); 
+0

只有最大化不是我要捕捉整個屏幕甚至任務欄和禁用鼠標和鍵盤的要求,這是實際的要求,但首先我想捕捉整個屏幕。 – Badr 2010-03-31 09:34:41

+0

當你不斷談論「捕捉」時,你不會得到任何地方。這意味着完全不同的東西。 Windows不允許程序完全控制機器。 – 2010-03-31 09:48:39

+0

@HansPassant:我認爲他希望(想要)截取整個桌面並將該圖像用作全屏無邊界窗口的背景。然後他想捕捉鼠標(和鍵盤)。聽起來像他希望他的應用程序欺騙人們認爲他們正常使用Windows,但相反... – d7samurai 2014-02-18 10:17:06

1

發現這對谷歌:Difficulties with Screen Capture, C/C++... 試着理解代碼並將其調整到您的需要。

void CaptureScreen(LPCTSTR lpszFilePathName) 
{ 
     BITMAPFILEHEADER  bmfHeader; 
     BITMAPINFO     *pbminfo; 
     HBITMAP      hBMP; 
     CFile      oFile; 

     CDC   *pDC   = GetWindowDC(); 
     INT   nSizeImage  = 1024 * 768 * 3; 
     CHAR  *pBuff   = new CHAR[sizeof(BITMAPINFOHEADER) + nSizeImage]; 
     pbminfo      = (BITMAPINFO *)pBuff; 
     hBMP      = (HBITMAP)pDC->GetCurrentBitmap()->m_hObject; 

     ZeroMemory(pbminfo, sizeof(BITMAPINFO)); 

     pbminfo->bmiHeader.biSize   = sizeof(BITMAPINFOHEADER); 

     GetDIBits(pDC->m_hDC, 
        hBMP, 
        0, 
        1, 
        NULL, 
        pbminfo, 
        DIB_RGB_COLORS); 

     GetDIBits(pDC->m_hDC, 
        hBMP, 
        0, 
        pbminfo->bmiHeader.biHeight, 
        pBuff + sizeof(BITMAPINFOHEADER), 
        pbminfo, 
        DIB_RGB_COLORS); 

     ReleaseDC(pDC); 

     bmfHeader.bfType   = 0x4d42; /*"BM"*/ 
     bmfHeader.bfSize   = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + nSizeImage; 
     bmfHeader.bfReserved1  = 0; 
     bmfHeader.bfReserved2  = 0; 
     bmfHeader.bfOffBits   = (DWORD) sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); 

     oFile.Open(lpszFilePathName, CFile::modeWrite | CFile::modeCreate); 

     oFile.Write(&bmfHeader, sizeof(BITMAPFILEHEADER)); 
     oFile.Write(pBuff, sizeof(BITMAPINFOHEADER) + pbminfo->bmiHeader.biSizeImage); 
     delete []pBuff; 
     oFile.Close(); 
} 
+0

它似乎用戶不想捕獲屏幕,但想要最大化應用程序。所以忽略答案。 – RvdK 2010-03-31 10:05:37

1

我想你想使用OpenGL或DirectX和調用全屏模式爲您的應用程序。當然會有一些你不能攔截的按鍵,比如安全注意序列(通常是CTRL + ALT + DEL),但是大部分與計算機的交互都會直接指向你的程序。

1

率先拿到了全屏幕,你應該輸入: 的ShowWindow(HWND,SW_SHOWMAXIMIZED) 秒以除去邊框或者女巫是所謂的窗口風格,你應該輸入您CreateWindow函數(的地方粗框你把你的風格(WS_)): CreateWindow(你的班級, 窗口名稱, WS_POPUP | WS_BORDER, 你的參數的其餘部分爲創建窗口func。

PS:WS_BORDER只是個1個PX黑色邊框這樣你就可以知道哪裏是窗口,如果它沒有被最小化,並在woth相同的背景顏色窗口的頂部,你可以刪除它,只要你想要 你也不會能夠最小化,最大化,關閉帶有內置按鈕的窗口,因爲他們不會在那裏,所以如果你想關閉應用程序,只需按下一個按鈕,在按下時發送PostQuitMessage。

祝你好運

相關問題