Al's Programming Resource Homepage  Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

winfuncs.cpp

Go to the documentation of this file.
00001 #include <windows.h>
00002 #include <math.h>
00003 #include "resource.rh"
00004 #include "shared.h"
00005 #include "mmgr.h"
00006 
00007 #define BUFFER_SIZE 256
00008 
00009 extern int DialogInUse;
00010 extern float lightColor[3];
00011 extern HWND hWnd;
00012 extern int testint;
00013 extern float testfloat;
00014 extern char teststring[64];
00015 
00016 HWND hWndOfDlg;
00017 OPENFILENAME ofn;
00018 char CurrentDirectory[MAX_PATH];
00019 
00020 // Initialization dialog process
00021 BOOL CALLBACK NameOfProc(HWND hwnd,UINT Message, WPARAM wParam, LPARAM /*lParam*/)
00022 {
00023   hWndOfDlg = hwnd;
00024   char szText[BUFFER_SIZE];
00025 
00026   switch(Message)
00027   {
00028     case WM_INITDIALOG:
00029       hWndOfDlg = hwnd;
00030       GetCurrentDirectory(MAX_PATH, CurrentDirectory);
00031 
00032       SendDlgItemMessage(hwnd, IDC_DLG_TEXT1, EM_SETLIMITTEXT, (WPARAM)BUFFER_SIZE - 1, (LPARAM)0);
00033       SendDlgItemMessage(hwnd, IDC_DLG_TEXT2, EM_SETLIMITTEXT, (WPARAM)BUFFER_SIZE - 1, (LPARAM)0);
00034       SendDlgItemMessage(hwnd, IDC_DLG_TEXT3, EM_SETLIMITTEXT, (WPARAM)BUFFER_SIZE - 1, (LPARAM)0);
00035 
00036       SetDlgItemText(hWndOfDlg, IDC_DLG_TEXT1, "1");
00037 
00038       SetDlgItemText(hWndOfDlg, IDC_DLG_TEXT2, "1.0");
00039 
00040       SetDlgItemText(hWndOfDlg, IDC_DLG_TEXT3, "One");
00041     return TRUE;
00042 
00043   case WM_COMMAND:
00044     switch(LOWORD(wParam))
00045     {
00046 
00047     case IDCANCEL:
00048           EndDialog(hwnd, IDCANCEL);
00049     return TRUE;
00050 
00051     case IDOK:
00052       GetDlgItemText(hwnd, IDC_DLG_TEXT1, szText, BUFFER_SIZE);
00053       testint = atoi(szText);
00054       GetDlgItemText(hwnd, IDC_DLG_TEXT2, szText, BUFFER_SIZE);
00055       testfloat = atof(szText);
00056       GetDlgItemText(hwnd, IDC_DLG_TEXT3, szText, BUFFER_SIZE);
00057       sprintf(teststring, "%s", szText);
00058       EndDialog(hwnd, IDOK);
00059     return TRUE;
00060 
00061     case IDC_DLG_SETPATH:
00062       ZeroMemory(&ofn, sizeof(ofn));
00063       ofn.lStructSize = sizeof(ofn);
00064       ofn.hwndOwner = hWndOfDlg;
00065       ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0\0";
00066       ofn.lpstrFile = teststring;
00067       ofn.nMaxFile = MAX_PATH;
00068       ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
00069       ofn.lpstrDefExt = "txt";
00070       if(GetOpenFileName(&ofn))
00071           SetDlgItemText(hWndOfDlg, IDC_DLG_TEXT3, teststring);
00072     return TRUE;
00073 
00074     }
00075     break;
00076   }
00077   return FALSE;
00078 }
00079 
00080 // Hook function for color common dialog window
00081 UINT APIENTRY ColorDialogHook(HWND hdlg, UINT msg, WPARAM, LPARAM)
00082 {
00083     switch (msg)
00084     {
00085         case WM_INITDIALOG:
00086         {
00087             if(DialogInUse == 1)  // Ambient
00088                 SetWindowText(hdlg, "Choose Ambient Color");
00089             if(DialogInUse == 2)  // Diffuse
00090                 SetWindowText(hdlg, "Choose Diffuse Color");
00091             if(DialogInUse == 3)  // Specular
00092                 SetWindowText(hdlg, "Choose Specular Color");
00093             return TRUE;
00094         }
00095 
00096         default:
00097             return FALSE;
00098     }
00099 }
00100 
00101 void GetLightColor()
00102 {
00103     COLORREF colors[16];
00104     COLORREF colorRGB = RGB(lightColor[0]*255, lightColor[1]*255, lightColor[2]*255);
00105     CHOOSECOLOR colorDialog;
00106     memset(&colorDialog,0,sizeof(colorDialog));
00107     memset(colors,255,sizeof(colors));
00108     colorDialog.lStructSize = sizeof(CHOOSECOLOR);
00109     colorDialog.hwndOwner = hWnd;
00110     colorDialog.rgbResult = colorRGB;
00111     colorDialog.lpCustColors = colors;
00112     colorDialog.Flags = CC_FULLOPEN | CC_RGBINIT | CC_ENABLEHOOK;
00113     colorDialog.lpfnHook = (LPCCHOOKPROC)ColorDialogHook;
00114     ChooseColor(&colorDialog);
00115     lightColor[0] = (float)GetRValue(colorDialog.rgbResult)/255;
00116     lightColor[1] = (float)GetGValue(colorDialog.rgbResult)/255;
00117     lightColor[2] = (float)GetBValue(colorDialog.rgbResult)/255;
00118 }

Generated on Fri Dec 23 05:17:02 2005 for Dialogs, Text & FPS by doxygen1.2.15