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
|
HFONT GetFont(int Width,int Height,wstring type,bool italics,bool underline,int boldness)
{
HFONT hf;
hf = CreateFont(Height,Width,0,0,boldness,italics,underline,0,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY,VARIABLE_PITCH,type.c_str());
return hf;
}
int wStoI(wstring source)
{
wstringstream conv;
int result;
conv<<source;
conv>>result;
return result;
}
int fontW;
int fontH;
wstring font;
bool italics;
bool bBold;
bool line;
bool Create = true;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int bold;
HWND hEdit = 0;
int ID;
int YESNO;
wstring text;
wstring cText;
HFONT hf;
switch (message)
{
case WM_CREATE:
if(Create)
{
Create = false;
hEdit = CreateWindow(L"EDIT",0,WS_VISIBLE | WS_CHILD | ES_MULTILINE | ES_AUTOHSCROLL |ES_AUTOVSCROLL | WS_BORDER | WS_HSCROLL |WS_VSCROLL ,50,25,500,500,hWnd, (HMENU)EDIT,hInst,0);
}
if(bChanged){
if(bBold){bold = FW_BOLD;}
if(!bBold){bold = FW_DONTCARE;}
hf = GetFont(fontW,fontH,font,italics,line,bold);
SendMessage(hEdit,WM_SETFONT,(WPARAM)hf,0);
SendMessage(hWnd,WM_SETFONT,(WPARAM)hf,0);
}
break;
case WM_COMMAND:
ID = LOWORD(wParam);
switch(ID)
{
case ID_FONT_VERANDER:
DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),0,ChangeFontCB);
if(bChanged){
if(bBold){bold = FW_BOLD;}
if(!bBold){bold = FW_DONTCARE;}
hf = GetFont(fontW,fontH,font,italics,line,bold);
SendMessage(hEdit,WM_SETFONT,(WPARAM)hf,0);
SendMessage(hWnd,WM_CREATE,(WPARAM)hf,0);
}
break;
case ID_FILE_OPEN :
Open(hWnd);
break;
case ID_FILE_SAVE:
Save(hWnd);
break;
case ID_FILE_NEW:
YESNO = ::MessageBox(hWnd,L"do you want to save first?",L"save?",MB_YESNO);
switch(YESNO)
{
case IDYES:
Save(hWnd);
SetDlgItemText(hWnd,EDIT,L"");
break;
case IDNO:
SetDlgItemText(hWnd,EDIT,L"");
break;
}
break;
case ID_CODEEREN_CODEER:
YESNO = ::MessageBoxW(hWnd,L"some things go lost in the coding/decoding proces, do you want to continue?\n\ this function should only be used in single sentences.",L"warnig",MB_YESNO);
switch(YESNO)
{
case IDNO:
break;
case IDYES:
text = readTextBox(hWnd,EDIT);
encode(text,cText);
SetDlgItemText(hWnd,EDIT,cText.c_str());
break;
}
break;
case ID_CODEEREN_DECODEER:
cText = readTextBox(hWnd,EDIT);
decode(cText,text);
SetDlgItemText(hWnd,EDIT,text.c_str());
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
BOOL CALLBACK ChangeFontCB(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int ID;
switch(uMsg)
{
case WM_INITDIALOG:
return true;
case WM_COMMAND:
ID = LOWORD(wParam);
switch(ID)
{
case IDOK:
font = readTextBox(hWnd,IDC_TYPE);
fontW = wStoI( readTextBox(hWnd,IDC_WIDTH));
fontH= wStoI( readTextBox(hWnd,IDC_HEIGHT));
bChanged = true;
EndDialog(hWnd,2);
return true;
break;
case IDC_ITALICS:
if(italics){italics = false;}
if(!italics){italics = true;}
break;
case IDC_VET:
if(bBold){bBold = false;}
if(!bBold){bBold = true;}
break;
case IDC_LINE:
if(line){line = false;}
if(!line){line = true;}
break;
}
break;
case WM_CLOSE:
EndDialog(hWnd,2);
break;
default:
return false;
}
return 0;
}
|