main.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 3k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <shlobj.h>
  4. #include "resource.h"
  5. #include "debug.h"
  6. #include "nsc.h"
  7. typedef struct {
  8.     HWND hDlg;
  9.     HWND hwndNSC;
  10. } DLGDATA;
  11. BOOL CALLBACK DlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  12. {
  13.     DLGDATA * pdd = (DLGDATA *)GetWindowLong(hDlg, DWL_USER);
  14.     switch (uMessage) {
  15.     case WM_INITDIALOG:
  16.         SetWindowLong(hDlg, DWL_USER, lParam);
  17. pdd = (DLGDATA *)lParam;
  18. pdd->hDlg = hDlg;
  19. pdd->hwndNSC = GetDlgItem(hDlg, IDC_USER1);
  20. SetWindowLong(pdd->hwndNSC, GWL_STYLE, NSS_DROPTARGET | GetWindowLong(pdd->hwndNSC, GWL_STYLE));
  21. {
  22.             NSC_SETROOT sr = {NSSR_CREATEPIDL, NULL, (LPCITEMIDLIST)CSIDL_FAVORITES, 5, NULL};
  23.             // NSC_SETROOT sr = {NSSR_CREATEPIDL, NULL, (LPCITEMIDLIST)CSIDL_FAVORITES, 10, NULL};
  24.     // SetWindowLong(pdd->hwndNSC, GWL_STYLE, GetWindowLong(pdd->hwndNSC, GWL_STYLE));
  25.     SetWindowLong(pdd->hwndNSC, GWL_STYLE, NSS_SHOWNONFOLDERS | GetWindowLong(pdd->hwndNSC, GWL_STYLE));
  26.     NameSpace_SetRoot(pdd->hwndNSC, &sr);
  27. }
  28.         break;
  29.     case WM_COMMAND:
  30.         switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  31.         case IDOK:
  32.         case IDCANCEL:
  33.     EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  34.         }
  35.         break;
  36.     case WM_NOTIFY:
  37.         switch (((NMHDR *)lParam)->code) {
  38.         // case PSN_SETACTIVE:
  39.         // case PSN_APPLY:
  40.          break;
  41. default:
  42.     return FALSE;
  43.         }
  44.         break;
  45.     default:
  46.         return FALSE;
  47.     }
  48.     return TRUE;
  49. }
  50. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR pszCmdLine, int nCmdShow)
  51. {
  52.     DLGDATA dd;
  53.     NameSpace_RegisterClass(hInst);
  54.     OleInitialize(NULL);
  55.     DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc, (LPARAM)&dd);
  56.     OleUninitialize();
  57.     return 0;
  58. }
  59. // stolen from the CRT, used to shirink our code
  60. int _stdcall WinMainCRTStartup(void)
  61. {
  62.     int i;
  63.     STARTUPINFO si;
  64.     LPSTR pszCmdLine = GetCommandLine();
  65.     if ( *pszCmdLine == '"' ) {
  66.         /*
  67.          * Scan, and skip over, subsequent characters until
  68.          * another double-quote or a null is encountered.
  69.          */
  70.         while ( *++pszCmdLine && (*pszCmdLine
  71.           != '"') );
  72.         /*
  73.          * If we stopped on a double-quote (usual case), skip
  74.          * over it.
  75.          */
  76.         if ( *pszCmdLine == '"' )
  77.          pszCmdLine++;
  78.     }
  79.     else {
  80.         while (*pszCmdLine > ' ')
  81.          pszCmdLine++;
  82.     }
  83.     /*
  84.      * Skip past any white space preceeding the second token.
  85.      */
  86.     while (*pszCmdLine && (*pszCmdLine <= ' ')) {
  87.         pszCmdLine++;
  88.     }
  89.     si.dwFlags = 0;
  90.     GetStartupInfoA(&si);
  91.     i = WinMain(GetModuleHandle(NULL), NULL, pszCmdLine,
  92.                    si.dwFlags & STARTF_USESHOWWINDOW ? si.wShowWindow : SW_SHOWDEFAULT);
  93.     // Since we now have a way for an extension to tell us when it is finished,
  94.     // we will terminate all processes when the main thread goes away.
  95.     ExitProcess(i);
  96.     return i; // We only come here when we are not the shell...
  97. }