home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 5036 / source.7z / x_dlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2011-12-13  |  4.1 KB  |  147 lines

  1. #include "xentax.h"
  2.  
  3. void CenterDialog(HWND window, bool in_parent)
  4. {
  5.  HWND dialog = window;
  6.  HWND parent = ((in_parent && GetParent(dialog)) ? GetParent(dialog) : GetDesktopWindow());
  7.  
  8.  RECT rect1; GetWindowRect(dialog, &rect1);
  9.  RECT rect2; GetWindowRect(parent, &rect2);
  10.  
  11.  int dx1 = rect1.right - rect1.left;
  12.  int dx2 = rect2.right - rect2.left;
  13.  
  14.  int dy1 = rect1.bottom - rect1.top;
  15.  int dy2 = rect2.bottom - rect2.top;
  16.  
  17.  int x = (dx2 - dx1)/2 + rect1.left;
  18.  int y = (dy2 - dy1)/2 + rect1.top;
  19.  
  20.  MoveWindow(dialog, x, y, dx1, dy1, TRUE);
  21. }
  22.  
  23. // Browse Directory Dialog
  24. int CALLBACK BrowseDirectoryDialogProc(HWND window, UINT message, LPARAM lparam, LPARAM)
  25. {
  26.  char directory[MAX_PATH];
  27.  switch(message) {
  28.    case(BFFM_INITIALIZED) : {
  29.         if(GetCurrentDirectoryA(sizeof(directory)/sizeof(char), directory))
  30.            SendMessage(window, BFFM_SETSELECTION,  1, (LPARAM)directory);
  31.         break;
  32.        }
  33.    case(BFFM_SELCHANGED) : {
  34.         if(SHGetPathFromIDListA((LPITEMIDLIST)lparam ,directory))
  35.            SendMessage(window, BFFM_SETSTATUSTEXT, 0, (LPARAM)directory);
  36.         break;
  37.        }
  38.   }
  39.  return 0;
  40. }
  41.  
  42. BOOL BrowseDirectoryDialog(HWND parent, const char* caption, char* buffer)
  43. {
  44.  char display_name[MAX_PATH];
  45.  display_name[0] = '\0';
  46.  
  47.  BROWSEINFOA bi = {
  48.   parent,
  49.   0,
  50.   display_name,
  51.   caption,
  52.   BIF_RETURNONLYFSDIRS,
  53.   BrowseDirectoryDialogProc,
  54.   0
  55.  };
  56.  
  57.  ITEMIDLIST* pIIL = ::SHBrowseForFolderA(&bi);
  58.  if(SHGetPathFromIDListA(pIIL, buffer)) {
  59.     LPMALLOC pMalloc;
  60.     HRESULT hr = SHGetMalloc(&pMalloc);
  61.     pMalloc->Free(pIIL);
  62.     pMalloc->Release();
  63.     return TRUE;
  64.    }
  65.  
  66.  return FALSE;
  67. }
  68.  
  69. // Color Dialog
  70. BOOL ColorDialog(HWND parent, COLORREF& color)
  71. {
  72.  static COLORREF custom[16] = {
  73.   RGB(  0,  0,  0), RGB(255,255,255), RGB(128,128,128), RGB(192,192,192),
  74.   RGB(128,  0,  0), RGB(  0,128,  0), RGB(  0,  0,128), RGB(128,128,  0),
  75.   RGB(128,  0,128), RGB(  0,128,128), RGB(255, 255, 0), RGB(255,  0,255),
  76.   RGB(  0,255,255), RGB(255,  0,  0), RGB(  0,255,  0), RGB(  0,  0,255)
  77.  };
  78.  CHOOSECOLOR data;
  79.  ZeroMemory(&data, sizeof(data));
  80.  data.lStructSize    = sizeof(CHOOSECOLOR);
  81.  data.hwndOwner      = parent;
  82.  data.hInstance      = NULL;
  83.  data.rgbResult      = color;
  84.  data.lpCustColors   = custom;
  85.  data.Flags          = CC_RGBINIT | CC_FULLOPEN;
  86.  data.lCustData      = 0;
  87.  data.lpfnHook       = NULL;
  88.  data.lpTemplateName = NULL;
  89.  if(ChooseColor(&data) == FALSE) return FALSE; 
  90.  else color = data.rgbResult;
  91.  return TRUE;
  92. }
  93.  
  94. // OpenSave Dialogs
  95. BOOL OpenFileDialog(HWND parent, const char* filter, const char* title, const char* defext, char* filename, char* initdir)
  96. {
  97.  char buffer1[MAX_PATH];
  98.  char buffer2[MAX_PATH];
  99.  buffer1[0] = '\0';
  100.  buffer2[0] = '\0';
  101.  
  102.  OPENFILENAMEA ofn;
  103.  ZeroMemory(&ofn, sizeof(ofn));
  104.  ofn.lStructSize     = sizeof(ofn);
  105.  ofn.hwndOwner       = parent;
  106.  ofn.hInstance       = (HINSTANCE)GetModuleHandle(0);
  107.  ofn.lpstrFilter     = filter;
  108.  ofn.lpstrFile       = buffer1;
  109.  ofn.nMaxFile        = MAX_PATH;
  110.  ofn.lpstrFileTitle  = buffer2;
  111.  ofn.nMaxFileTitle   = MAX_PATH;
  112.  ofn.lpstrInitialDir = initdir;
  113.  ofn.lpstrTitle      = title;
  114.  ofn.Flags           = OFN_FILEMUSTEXIST;
  115.  ofn.lpstrDefExt     = defext;
  116.  
  117.  if(!GetOpenFileNameA(&ofn)) return FALSE;
  118.  memmove(filename, buffer1, strlen(buffer1) + 1);
  119.  return TRUE;
  120. }
  121.  
  122. BOOL SaveFileDialog(HWND parent, const char* filter, const char* title, const char* defext, char* filename, char* initdir)
  123. {
  124.  char buffer1[MAX_PATH];
  125.  char buffer2[MAX_PATH];
  126.  buffer1[0] = '\0';
  127.  buffer2[0] = '\0';
  128.  
  129.  OPENFILENAMEA ofn;
  130.  ZeroMemory(&ofn, sizeof(ofn));
  131.  ofn.lStructSize     = sizeof(ofn);
  132.  ofn.hwndOwner       = parent;
  133.  ofn.hInstance       = (HINSTANCE)GetModuleHandle(0);
  134.  ofn.lpstrFilter     = filter;
  135.  ofn.lpstrFile       = buffer1;
  136.  ofn.nMaxFile        = MAX_PATH;
  137.  ofn.lpstrFileTitle  = buffer2;
  138.  ofn.nMaxFileTitle   = MAX_PATH;
  139.  ofn.lpstrInitialDir = initdir;
  140.  ofn.lpstrTitle      = title;
  141.  ofn.Flags           = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  142.  ofn.lpstrDefExt     = defext;
  143.  
  144.  if(!GetSaveFileNameA(&ofn)) return FALSE;
  145.  memmove(filename, buffer1, strlen(buffer1) + 1);
  146.  return TRUE;
  147. }