home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / colordlg.pak / USECDLL2.CPP < prev    next >
C/C++ Source or Header  |  1997-07-23  |  3KB  |  95 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <owl\owlpch.h>
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include "cctltest.h"
  9.  
  10. extern "C" BOOL FAR PASCAL
  11.   GetColor(HWND parentHandle, COLORREF& colorBuffer);
  12.  
  13. char appName[] = "DLL Test (non-OWL app)";
  14.  
  15.  
  16. LRESULT
  17. doProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  18. {
  19.   switch (message) {
  20.     case WM_DESTROY:
  21.       PostQuitMessage(0);
  22.       break;
  23.  
  24.     case WM_COMMAND:
  25.       if (LOWORD(lParam) == 0 && wParam == CM_COLOR) {
  26.         COLORREF color = RGB(0x00, 0x00, 0x00);
  27.         char msgStr[128];
  28.         if (GetColor(hWnd, color)) {
  29.           sprintf(msgStr,
  30.            "RGB intensities:\r\n\r\n Red: %d\r\n Green: %d\r\n Blue: %d",
  31.             GetRValue(color), GetGValue(color), GetBValue(color));
  32.         } else
  33.           strcpy(msgStr, "Cancelled");
  34.         MessageBox(hWnd, msgStr, appName, MB_OK);
  35.  
  36.       } else
  37.         return DefWindowProc(hWnd, message, wParam, lParam);
  38.       break;
  39.  
  40.     default:
  41.       return DefWindowProc(hWnd, message, wParam, lParam);
  42.   }
  43.   return 0;
  44. }
  45.  
  46. #if defined(__WIN32__)
  47. LRESULT
  48. FAR PASCAL _stdcall
  49. WndProc(HWND h, UINT msg, WPARAM wParam, LPARAM lParam)
  50. {
  51.   return doProc(h, msg, wParam, lParam);
  52. }
  53. #else
  54. LRESULT
  55. FAR PASCAL __export
  56. WndProc(HWND h, UINT msg, WPARAM wParam, LPARAM lParam)
  57. {
  58.   return doProc(h, msg, wParam, lParam);
  59. }
  60. #endif
  61.  
  62. int PASCAL
  63. WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR, int cmdShow)
  64. {
  65.   if (!hPrevInstance) {
  66.     WNDCLASS wndClass;
  67.     wndClass.style         = CS_HREDRAW | CS_VREDRAW;
  68.     wndClass.lpfnWndProc   = WndProc;
  69.     wndClass.cbClsExtra    = 0;
  70.     wndClass.cbWndExtra    = 0;
  71.     wndClass.hInstance     = hInstance;
  72.     wndClass.hIcon         = LoadIcon(0, IDI_APPLICATION);
  73.     wndClass.hCursor       = LoadCursor(0, IDC_ARROW);
  74.     wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  75.     wndClass.lpszMenuName  = "COMMANDS";
  76.     wndClass.lpszClassName = appName;
  77.  
  78.     if (!RegisterClass(&wndClass))
  79.       return FALSE;
  80.   }
  81.  
  82.   HWND hWnd = CreateWindow(appName, appName, WS_OVERLAPPEDWINDOW,
  83.     CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, 0);
  84.  
  85.   ShowWindow(hWnd, cmdShow);
  86.  
  87.   MSG  msg;
  88.   while (GetMessage(&msg, 0, 0, 0)) {
  89.     TranslateMessage(&msg);
  90.     DispatchMessage(&msg);
  91.   }
  92.  
  93.   return msg.wParam;
  94. }
  95.