C语言开发实现的虚拟桌面程序代码

来源:计算机等级考试    发布时间:2012-08-28    计算机等级考试视频    评论


  void StartExplorer()
  {
  STARTUPINFO si;
  ZeroMemory( &si, sizeof(si) );
  si.cb = sizeof(si);
  si.lpDesktop = "Virtual";
  ZeroMemory( &piExplor, sizeof(piExplor) );
  if( !CreateProcess( NULL, // No module name (use command line).
  "explorer", // Command line.
  NULL, // Process handle not inheritable.
  NULL, // Thread handle not inheritable.
  FALSE, // Set handle inheritance to FALSE.
  0, // No creation flags.
  NULL, // Use parent's environment block.
  NULL, // Use parent's starting directory.
  &si, // Pointer to STARTUPINFO structure.
  &piExplor ) // Pointer to PROCESS_INFORMATION structure.
  )
  {
  MessageBox(NULL,"无法初始化Explorer","Error",0);
  ExitProcess(1);
  }
  }
  ATOM MyRegisterClass(HINSTANCE hInstance)
  {
  WNDCLASSEX wcex;
  wcex.cbSize = sizeof(WNDCLASSEX);
  wcex.style = CS_HREDRAW | CS_VREDRAW;
  wcex.lpfnWndProc = (WNDPROC)WndProc;
  wcex.cbClsExtra = 0;
  wcex.cbWndExtra = 0;
  wcex.hInstance = hInstance;
  wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_APPLICATION);
  wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  wcex.lpszMenuName = NULL;
  wcex.lpszClassName = szAppName;
  wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_APPLICATION);
  return RegisterClassEx(&wcex);
  }
  BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  {
  hInst = hInstance; // 将实例句柄存储在全局变量中
  hwnd = CreateWindow(szAppName, TEXT ("SunBear"), WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL);
  if (!hwnd)
  {
  return FALSE;
  }
  return TRUE;
  }
  int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
  {
  static TCHAR szAppName[] = TEXT ("SunBear") ;
  MSG msg ;
  SetStartup(hInstance);
  hVirtualDesk = CreateDesktop(
  "Virtual",
  NULL,
  NULL,
  DF_ALLOWOTHERACCOUNTHOOK,
  GENERIC_ALL,
  NULL);
  hCurrent = GetThreadDesktop(GetCurrentThreadId());
  MyRegisterClass(hInstance);
  if (!InitInstance (hInstance, iCmdShow))
  {
  return FALSE;
  }
  StartExplorer(); //启动Explorer进程
  if(!RegisterHotKey(hwnd, 0x0001,MOD_ALT ,'Q'))
  {
  //处理切换虚拟桌面
  return TRUE;
  }
  if(!RegisterHotKey(hwnd, 0x0002, 0,VK_F8))
  {
  //处理退出进程
  return TRUE;
  }
  while (GetMessage (&msg, NULL, 0, 0))
  {
  TranslateMessage (&msg) ;
  DispatchMessage (&msg) ;
  }
  return 0;
  }
  LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  {
  HDC hdc ;
  PAINTSTRUCT ps ;
  static HDESK hNow = hCurrent;
  switch (message)
  {
  case WM_PAINT:
  hdc = BeginPaint (hwnd, &ps) ;
  EndPaint (hwnd, &ps) ;
  return 0 ;
  case WM_DESTROY:

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答