1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
//Main.cpp
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <tchar.h>
#include <commdlg.h>
#include "Form16.h"
LRESULT CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
EnableWindow(GetParent(hwnd),FALSE);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDD_OK:
MessageBox(hwnd,_T("You Clicked The OK Button!"),_T("OK Button Click!"),MB_OK);
SendMessage(hwnd,WM_CLOSE,0,0);
break;
case IDD_CANCEL:
MessageBox(hwnd,_T("You Clicked The Cancel Button!"),_T("Cancel Button Click!"),MB_OK);
SendMessage(hwnd,WM_CLOSE,0,0);
break;
}
return 0;
case WM_CLOSE:
EnableWindow(GetParent(hwnd),TRUE);
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
long fnWndProc_OnCreate(lpWndEventArgs Wea)
{
TCHAR szClassName[]=_T("Dialog");
TCHAR* ptrOpenFileName=NULL;
HMENU hMenu, hSubMenu;
WNDCLASSEX wc;
Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, (UINT_PTR)ID_FILE_OPEN, _T("&Open"));
AppendMenu(hSubMenu, MF_STRING, ID_FILE_SAVE, _T("&Save"));
AppendMenu(hSubMenu, MF_SEPARATOR, 0, 0);
AppendMenu(hSubMenu, MF_STRING, (UINT_PTR)ID_FILE_EXIT, _T("E&xit"));
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, _T("&File"));
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, (UINT_PTR)ID_OPTIONS,_T("&Explorer"));
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, _T("O&ptions"));
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, (UINT_PTR)IDD_ABOUT, _T("&About"));
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, _T("&Help"));
SetMenu(Wea->hWnd, hMenu);
//Then Register Window Class For Dialog Box
wc.lpszClassName=szClassName, wc.lpfnWndProc=DlgProc;
wc.cbSize=sizeof(wc), wc.style=CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra=0, wc.cbWndExtra=0;
wc.hInstance=Wea->hIns, wc.hCursor=LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW, wc.lpszMenuName=NULL;
wc.hIcon=0; wc.hIconSm=0;
RegisterClassEx(&wc);
//And finally Allocate Memory To Store File Name from Open File Dialog for
ptrOpenFileName=(TCHAR*)GlobalAlloc(GPTR,256*sizeof(TCHAR)); //later display in WM_PAINT
if(ptrOpenFileName) //handler on the main window
SetWindowLongPtr(Wea->hWnd,GWLP_USERDATA,(LONG_PTR)ptrOpenFileName);
else
return -1;
return 0;
}
long WndProc_OnFileOpen(lpWndEventArgs Wea)
{
static TCHAR szFilter[]=_T("C Files (*.C),CPP Files (*.cpp)\0*.c;*.cpp\0\0");
static TCHAR szTitleName[_MAX_FNAME+_MAX_EXT];
static TCHAR szFileName[_MAX_PATH];
TCHAR* ptrOpenFileName=NULL;
TCHAR lpszBuffer[256];
OPENFILENAME ofn;
GetCurrentDirectory(256*sizeof(TCHAR),lpszBuffer);
memset(&ofn,_T('\0'),sizeof(OPENFILENAME));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.lpstrFilter = szFilter;
ofn.nMaxFile=_MAX_PATH;
ofn.nMaxFileTitle=_MAX_FNAME+_MAX_EXT;
ofn.lpstrInitialDir = lpszBuffer;
ofn.lpstrDefExt = _T("cpp");
ofn.hInstance=GetModuleHandle(_T(""));
ofn.hwndOwner = Wea->hWnd;
ofn.Flags=OFN_HIDEREADONLY | OFN_CREATEPROMPT;
ofn.lpstrFile=szFileName;
ofn.lpstrFileTitle=szTitleName;
GetOpenFileName(&ofn);
ptrOpenFileName=(TCHAR*)GetWindowLongPtr(Wea->hWnd,GWLP_USERDATA);
_tcscpy(ptrOpenFileName,ofn.lpstrFile);
InvalidateRect(Wea->hWnd,NULL,FALSE);
return 0;
}
long WndProc_OnFileSave(lpWndEventArgs Wea)
{
static TCHAR szFilter[]=_T("C Files (*.C),CPP Files (*.cpp)\0*.c;*.cpp\0\0");
static TCHAR szTitleName[_MAX_FNAME+_MAX_EXT];
static TCHAR szFileName[_MAX_PATH];
TCHAR* ptrOpenFileName=NULL;
TCHAR lpszBuffer[256];
OPENFILENAME ofn;
GetCurrentDirectory(256*sizeof(TCHAR),lpszBuffer);
memset(&ofn,_T('\0'),sizeof(OPENFILENAME));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.lpstrFilter = szFilter;
ofn.nMaxFile=_MAX_PATH;
ofn.nMaxFileTitle=_MAX_FNAME+_MAX_EXT;
ofn.lpstrInitialDir = lpszBuffer;
ofn.lpstrDefExt = _T("cpp");
ofn.hInstance=GetModuleHandle(_T(""));
ofn.hwndOwner = Wea->hWnd;
ofn.Flags=OFN_HIDEREADONLY | OFN_CREATEPROMPT;
ofn.lpstrFile=szFileName;
ofn.lpstrFileTitle=szTitleName;
GetSaveFileName(&ofn);
ptrOpenFileName=(TCHAR*)GetWindowLongPtr(Wea->hWnd,GWLP_USERDATA);
_tcscpy(ptrOpenFileName,ofn.lpstrFile);
InvalidateRect(Wea->hWnd,NULL,FALSE);
return 0;
}
long WndProc_OnAbout(lpWndEventArgs Wea)
{
TCHAR szCap2[]=_T("An Example Program Showing How To");
TCHAR szCap1[]=_T("About This Program");
DWORD dwExStyle,dwStyle,dwSty;
HWND hDlg,hGroup;
MSG Msg;
dwExStyle = WS_EX_DLGMODALFRAME | WS_EX_CONTROLPARENT;
dwStyle = WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE;
dwSty = WS_CHILD|WS_VISIBLE;
Wea->hIns=GetModuleHandle(_T(""));
hDlg=CreateWindowEx(dwExStyle,_T("Dialog"),_T("Dialog Window"),dwStyle,175,100,400,145,Wea->hWnd,0,Wea->hIns,NULL);
hGroup=CreateWindow(_T("button"),szCap1,BS_GROUPBOX|dwSty,5,5,385,100,hDlg,(HMENU)IDD_GROUP,Wea->hIns,0);
CreateWindow(_T("button"),_T("OK"),WS_TABSTOP|dwSty,295,25,80,25,hDlg,(HMENU)IDD_OK,Wea->hIns,0);
CreateWindow(_T("button"),_T("Cancel"),WS_TABSTOP|dwSty,295,65,80,25,hDlg,(HMENU)IDD_CANCEL,Wea->hIns,0);
CreateWindow(_T("static"),szCap2,dwSty,25,25,275,25,hGroup,(HMENU)-1,Wea->hIns,0);
CreateWindow(_T("static"),_T(" Use Dialog Boxes"),dwSty,25,42,275,25,hGroup,(HMENU)-1,Wea->hIns,0);
CreateWindow(_T("static"),_T(" By Fred"),dwSty,25,72,275,25,hGroup,(HMENU)-1,Wea->hIns,0);
while(GetMessage(&Msg, NULL, 0, 0))
{
if(!IsDialogMessage(hDlg,&Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return 0;
}
long WndProc_OnOptions(lpWndEventArgs Wea)
{
system("explorer c:\\");
return 0;
}
long WndProc_OnExit(lpWndEventArgs Wea)
{
SendMessage(Wea->hWnd,WM_CLOSE,0,0);
return 0;
}
|