home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_11 / 2n11039a < prev    next >
Text File  |  1991-09-09  |  4KB  |  117 lines

  1. #include <windows.h>
  2.  
  3. /*
  4.  *  CreateDialogMenu - From dialog template, create window w/menu.
  5.  *
  6.  */
  7.  
  8. HWND    CreateDialogMenu(HANDLE Instance,
  9.             LPSTR TemplateName, HWND Parent,
  10.             FARPROC DlgFunction, LPSTR MenuName,
  11.             LONG BorderStyle)
  12.     {
  13.     HWND    NewWindow, Menu;
  14.     LONG    WindowStyle, WindowExStyle;
  15.     RECT    WindowRect, OldClient, NewClient;
  16.     int     OldWidth, NewWidth, OldHeight, NewHeight;
  17.  
  18.     NewWindow   = CreateDialog(Instance,
  19.                     TemplateName, Parent, DlgFunction);
  20.     if(NewWindow == NULL)
  21.         return NULL;
  22.     GetWindowRect(NewWindow, &WindowRect);
  23.     GetClientRect(NewWindow, &OldClient);
  24.     WindowExStyle = GetWindowLong(NewWindow, GWL_EXSTYLE);
  25.     WindowStyle     = GetWindowLong(NewWindow, GWL_STYLE);
  26.  
  27.     /* Turn off DLGMODALFRAME bit */
  28.     WindowExStyle &= ~WS_EX_DLGMODALFRAME;
  29.     SetWindowLong(NewWindow, GWL_EXSTYLE,
  30.             WindowExStyle & ~WS_EX_DLGMODALFRAME);
  31.     /* Turn on style of frame you want */
  32.     WindowStyle &= ~(WS_BORDER | WS_DLGFRAME | WS_THICKFRAME);
  33.     switch(BorderStyle)
  34.         {
  35.         case    WS_THICKFRAME   :
  36.             WindowStyle |= WS_THICKFRAME;
  37.         case    WS_DLGFRAME :
  38.             WindowStyle |= WS_DLGFRAME;
  39.             WindowStyle |= WS_BORDER;
  40.         }
  41.     SetWindowLong(NewWindow, GWL_STYLE, WindowStyle);
  42.  
  43.     SetMenu(NewWindow, LoadMenu(Instance, MenuName));
  44.     GetClientRect(NewWindow, &NewClient);
  45.  
  46.     OldWidth    = OldClient.right - OldClient.left;
  47.     NewWidth    = NewClient.right - NewClient.left;
  48.     OldHeight    = OldClient.bottom - OldClient.top;
  49.     NewHeight    = NewClient.bottom - NewClient.top;
  50.  
  51.     SetWindowPos(NewWindow, NULL, 0, 0,
  52.             (WindowRect.right-WindowRect.left) + (OldWidth - NewWidth),
  53.             (WindowRect.bottom-WindowRect.top) + (OldHeight-NewHeight),
  54.             SWP_DRAWFRAME | SWP_NOMOVE);
  55.     return NewWindow;
  56.     }
  57.  
  58.  
  59.  
  60. int PASCAL WinMain(HANDLE Instance,
  61.     HANDLE Previous, LPSTR CmdLine, int Command)
  62.     {
  63.     static  char AppName[] = "DlgMenu";
  64.     HWND        MainWindow;
  65.     MSG         Message;
  66.  
  67.     if(!Previous)
  68.         {
  69.         extern long FAR PASCAL WindProc(HWND, WORD, WORD, LONG);
  70.         WNDCLASS    WindowClass;
  71.         WindowClass.style           = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  72.         WindowClass.lpfnWndProc     = WindProc;
  73.         WindowClass.cbClsExtra      = 0;
  74.  
  75.         // Don't forget extra bytes because it is a dialog
  76.         WindowClass.cbWndExtra      = DLGWINDOWEXTRA;
  77.  
  78.         WindowClass.hInstance       = Instance;
  79.         WindowClass.hIcon           = LoadIcon(Instance, IDI_APPLICATION);
  80.         WindowClass.hCursor         = LoadCursor(NULL, IDC_ARROW);
  81.         WindowClass.hbrBackground   = GetStockObject(WHITE_BRUSH);
  82.  
  83.         WindowClass.lpszMenuName    = NULL;
  84.  
  85.         WindowClass.lpszClassName   = AppName;
  86.         RegisterClass(&WindowClass);
  87.         }
  88.  
  89.     MainWindow  = CreateDialogMenu(Instance, "DLGMENU",
  90.                         0, NULL, "MAIN_MENU", WS_THICKFRAME);
  91.     
  92.     ShowWindow(MainWindow, Command);
  93.  
  94.     while(GetMessage(&Message, NULL, 0, 0))
  95.         {
  96.         if(!IsDialogMessage(MainWindow, &Message))
  97.             {
  98.             TranslateMessage(&Message);
  99.             DispatchMessage(&Message);
  100.             }
  101.         }
  102.     return Message.wParam;
  103.     }
  104.  
  105. long FAR PASCAL WindProc(HWND WindowHandle,
  106.         WORD MsgNum, WORD WordParm, LONG LongParm)
  107.     {
  108.     switch(MsgNum)
  109.         {
  110.         case    WM_DESTROY:
  111.             PostQuitMessage(0);
  112.             return 0;
  113.         default:
  114.             return DefWindowProc(WindowHandle, MsgNum, WordParm, LongParm);
  115.         }
  116.     }
  117.