VS2013新建Win32項目,選擇空項目,添加頭文件和源文件,爲了美觀程序使用duilib界面庫,有些地方須要配置一下。html
教程能夠參考:ios
http://www.cnblogs.com/Alberl/p/3342030.htmlide
通過測試代表,同一明文同一密鑰,通過不一樣的置換盒子加密,所生成的密文也不同。(也就是說,你知道了密文和密鑰,還必須知道盒子,只有他加密用的盒子才能解密,其餘盒子不能解密。)oop
實驗中的置換表都是隨機生成,以密鑰的第一個字符做爲隨機數種子(能夠按照本身的喜愛規定)。測試
DES的頭文件:ui
1 #pragma once 2 #include <UIlib.h> 3 #include <Windows.h> 4 #include<time.h> 5 using namespace DuiLib; 6 7 #ifdef _DEBUG 8 # ifdef _UNICODE 9 # pragma comment(lib, "DuiLib_ud.lib") 10 # else 11 # pragma comment(lib, "DuiLib_d.lib") 12 # endif 13 #else 14 # ifdef _UNICODE 15 # pragma comment(lib, "DuiLib_u.lib") 16 # else 17 # pragma comment(lib, "DuiLib.lib") 18 # endif 19 #endif 20 21 #include <iostream> 22 #include<math.h> 23 24 int IP_Table[65] = { 0 }; 25 int IP_1[65] = { 0 }; 26 int Ebox[49] = { 0 }; 27 int PC_1[57] = { 0 }; 28 int PC_2[49] = { 0 }; 29 int P[33] = { 0 }; 30 int SBox[8][4][16]; 31 32 const int LeftMove[17] = { 33 0, 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 34 }; 35 void char_to_bit(char c, int temp[])//一個字符(1字節)轉化爲二進制(8位) 36 { 37 for (int i = 0; i<8; i++){ 38 int a = ((c >> i) & 1); 39 temp[7 - i] = a; 40 } 41 } 42 43 //字符串CDuiString轉二進制int[](56位) 44 void str_to_bit(CDuiString str, int strbit[]){ 45 int len = str.GetLength(); 46 int i, j; 47 int temp[8]; 48 for (i = 0; i<len; i++){ 49 char c = str[i]; 50 char_to_bit(c, temp); 51 for (j = 1; j <= 8; j++){ 52 strbit[i * 8 + j] = temp[j - 1]; 53 } 54 } 55 56 } 57 58 void divisionbit(int str_bit[], int leftbit[], int rightbit[]){ 59 for (int i = 1; i<65; i++){ 60 if (i<33){ 61 leftbit[i] = str_bit[i]; 62 } 63 else{ 64 rightbit[i - 32] = str_bit[i]; 65 } 66 } 67 68 } 69 void ip_change(int str[]) //ip變換 70 { 71 int temp[65]; 72 for (int i = 1; i<65; i++){ 73 temp[i] = str[IP_Table[i]]; 74 } 75 for (int i = 1; i<65; i++){ 76 str[i] = temp[i]; 77 } 78 } 79 80 void pc1_change(int str[], int strkey[]) //pc1變換 81 { 82 int temp[57]; 83 for (int i = 1; i<57; i++){ 84 temp[i] = str[PC_1[i]]; 85 } 86 for (int i = 1; i<57; i++){ 87 strkey[i] = temp[i]; 88 } 89 90 } 91 92 //產生56位密鑰 93 void key_56(CDuiString str, int strkey[]) 94 { 95 int str_bit[57], str_t[65]; 96 str_to_bit(str, str_bit); 97 int m = 1, i, j; 98 for (i = 1, j = 1; i < 57; i++, j++) 99 { 100 if (j % 8 == 0)j++; 101 str_t[j] = str_bit[i]; 102 } 103 int sum = 0; 104 for (i = 1; i < 65; i++) 105 { 106 107 if (i % 8 == 0) 108 { 109 str_t[i] = (sum + 1) % 2; 110 sum = 0; 111 i++; 112 } 113 sum += str_t[i]; 114 } 115 pc1_change(str_t, strkey);//pc1產生56位str_bit 116 117 } 118 119 120 void extend(int str[], int extstr[])//e擴展 121 { 122 int i; 123 for (i = 1; i <= 48; i++){ 124 extstr[i] = str[Ebox[i]]; 125 } 126 127 } 128 129 130 void divisionkey(CDuiString str, int leftkey[], int rightkey[]){ 131 int strkey[57], strbit[65]; 132 133 134 key_56(str, strkey); 135 //str_to_bit(str, strbit); 136 //pc1_change(strkey, strbit); 137 138 for (int i = 1; i<57; i++){ 139 if (i<29){ 140 leftkey[i] = strkey[i]; 141 } 142 else{ 143 rightkey[i - 28] = strkey[i]; 144 } 145 } 146 147 } 148 149 void keymovebit(int strkey[], int leftkey[], int rightkey[], int i)//循環左移 150 { 151 int temp1[2]; 152 int temp2[2]; 153 if ((LeftMove[i]) == 1){ 154 temp1[0] = leftkey[1]; 155 temp1[1] = rightkey[1]; 156 for (i = 1; i<28; i++){ 157 leftkey[i] = leftkey[i + 1]; 158 rightkey[i] = rightkey[i + 1]; 159 } 160 leftkey[28] = temp1[0]; 161 rightkey[28] = temp1[1]; 162 163 } 164 else if ((LeftMove[i]) == 2){ 165 temp1[0] = leftkey[1]; 166 temp1[1] = leftkey[2]; 167 temp2[0] = rightkey[1]; 168 temp2[1] = rightkey[2]; 169 170 for (i = 1; i + 2<29; i++){ 171 leftkey[i] = leftkey[i + 2]; 172 rightkey[i] = rightkey[i + 2]; 173 } 174 leftkey[27] = temp1[0]; 175 leftkey[28] = temp1[1]; 176 177 rightkey[27] = temp2[0]; 178 rightkey[28] = temp2[1]; 179 } 180 181 int t[57], j; 182 for (j = 1; j < 57; j++) 183 { 184 if (j < 29)t[j] = leftkey[j]; 185 else t[j] = rightkey[j - 28]; 186 } 187 for (j = 1; j<49; j++){ 188 strkey[j] = t[PC_2[j]]; //pc2變換 189 } 190 //output("第一輪產生的密鑰", strbit); 191 } 192 193 void yihuo(int arr[], int brr[], int crr[], int n)//異或操做 194 { 195 int i; 196 for (i = 1; i<n; i++){ 197 crr[i] = (arr[i] + brr[i]) % 2; 198 } 199 } 200 int SboxSelect(int s[][6], int i, int num)//s盒替換 201 { 202 int x = s[i][0] * 2 + s[i][5]; 203 int y = s[i][1] * 8 + s[i][2] * 4 + s[i][3] * 2 + s[i][4]; 204 return SBox[num][x][y]; 205 } 206 207 void Pbox(int str[])//p變化 208 { 209 int tem[33]; 210 int i; 211 for (i = 1; i<33; i++){ 212 tem[i] = str[P[i]]; 213 } 214 215 for (i = 1; i<33; i++){ 216 str[i] = tem[i]; 217 } 218 } 219 220 void intto2(int t, int str[]) //將單個int轉化爲二進制 221 { 222 for (int j = 0; j < 4; j++) 223 { 224 str[3 - j] = t % 2; 225 t = t / 2; 226 } 227 } 228 229 void int_to_2(int t[], int str[])//將多個int轉化爲二進制 230 { 231 int str1[8][4]; 232 for (int i = 0; i < 8; i++) 233 { 234 for (int j = 0; j < 4; j++) 235 { 236 intto2(t[i], str1[i]); 237 //str[(i + 1) * 4 - j] = m; 238 } 239 } 240 for (int i = 0, k = 1; i < 8; i++) 241 { 242 for (int j = 0; j < 4; j++) 243 { 244 str[k] = str1[i][j]; 245 k++; 246 } 247 } 248 } 249 250 void stepbit(int leftbit[], int rightbit[], int key[])//16個循環的步驟 251 { 252 int temp1[49], temp2[50]; 253 extend(rightbit, temp1); 254 yihuo(key, temp1, temp2, 49); 255 int s[8][6], t[8]; 256 for (int n = 0, k = 1; n < 8; n++) 257 { 258 for (int m = 0; m < 6; m++) 259 { 260 s[n][m] = temp2[k]; 261 k++; 262 } 263 } 264 for (int i = 0; i < 8; i++) 265 { 266 t[i] = SboxSelect(s, i, i); //S盒變化 267 } 268 int temp[33]; 269 int_to_2(t, temp);//S和變換後的32位1-32 270 Pbox(temp);; 271 yihuo(leftbit, temp, temp1, 33); 272 for (int i = 1; i < 33; i++) 273 { 274 leftbit[i] = rightbit[i]; 275 } 276 for (int i = 1; i < 33; i++) 277 { 278 rightbit[i] = temp1[i]; 279 } 280 } 281 282 void addtomi(int leftbit[], int rightbit[], int str[])//最終合併加ip逆變化 283 { 284 int temp[65], i; 285 for (i = 1; i < 65; i++) 286 { 287 if (i < 33) 288 { 289 temp[i] = leftbit[i]; 290 } 291 else 292 { 293 temp[i] = rightbit[i - 32]; 294 } 295 } 296 for (i = 1; i < 65; i++)//ip逆變化 297 { 298 str[i] = temp[IP_1[i]]; 299 } 300 } 301 302 void copyint(int s[], int t[])//用於密鑰的複製保存 303 { 304 for (int i = 1; i < 49; i++) 305 { 306 s[i] = t[i]; 307 } 308 } 309 310 void Rand_table(int table[], int N, int size)//生成1-N隨機數填入table[] 311 { 312 int num = size; 313 for (int i = 1; i <= N; i++)//p盒,ip置換 314 { 315 if (size == 56 && i % 8 == 0)// pc-1盒 316 continue; 317 if (size == 48)num = 32; 318 319 int m = rand() % num + 1; 320 //cout<<m<<" "; 321 if (table[m] == 0) 322 { 323 table[m] = i; 324 } 325 else 326 { 327 while (table[m] != 0) 328 { 329 m++; 330 if (m>size) 331 m = 1; 332 } 333 table[m] = i; 334 } 335 } 336 if (size == 48)//E盒擴展 337 { 338 for (int j = 1; j <= 48; j++) 339 { 340 if (table[j] == 0) 341 table[j] = rand() % num + 1; 342 } 343 } 344 } 345 346 void Rand_pc2(int table[], int N) 347 { 348 for (int i = 1; i <= N; i++) 349 { 350 int m = rand() % 56 + 1; 351 table[i] = m; 352 } 353 } 354 355 void Rand_table_1(int table[], int table_1[], int size)//ip-1置換 356 { 357 for (int i = 1; i <= size; i++) 358 { 359 int m = table[i]; 360 table_1[m] = i; 361 } 362 } 363 364 365 void Rand_SBox(int table[8][4][16]) 366 { 367 for (int i = 0; i < 8; i++) 368 { 369 for (int j = 0; j < 4; j++) 370 { 371 for (int k = 0; k < 16; k++) 372 { 373 int m = rand() % 17; 374 table[i][j][k] = m; 375 } 376 } 377 } 378 } 379 380 void Destory()//將置換表歸0,將從新生成 381 { 382 memset(IP_Table, 0, sizeof(IP_Table)); 383 memset(IP_1, 0, sizeof(IP_1)); 384 memset(Ebox, 0, sizeof(Ebox)); 385 memset(PC_1, 0, sizeof(PC_1)); 386 memset(P, 0, sizeof(P)); 387 } 388 void DseInit(int n)//密鑰對第一個字符做爲隨機種子 389 { 390 srand(n); 391 Rand_table(IP_Table, 64, 64); //IP 392 Rand_table_1(IP_Table, IP_1, 64); //IP逆 393 Rand_table(Ebox, 32, 48); 394 Rand_table(PC_1, 64, 56); 395 Rand_SBox(SBox); 396 Rand_pc2(PC_2, 48); 397 Rand_table(P, 32, 32); 398 }
在main.cpp裏實現界面控件的消息響應:this
1 #pragma once 2 #include "DES.h" 3 //#include <UIlib.h> 4 //using namespace DuiLib; 5 int c = 1; 6 #ifdef _DEBUG 7 # ifdef _UNICODE 8 # pragma comment(lib, "DuiLib_ud.lib") 9 # else 10 # pragma comment(lib, "DuiLib_d.lib") 11 # endif 12 #else 13 # ifdef _UNICODE 14 # pragma comment(lib, "DuiLib_u.lib") 15 # else 16 # pragma comment(lib, "DuiLib.lib") 17 # endif 18 #endif 19 20 class CDuiFrameWnd : public CWindowWnd, public INotifyUI 21 { 22 protected: 23 CPaintManagerUI m_PaintManager; 24 25 public: 26 CDuiFrameWnd() { }; 27 UINT GetClassStyle() const { return UI_CLASSSTYLE_DIALOG; }; 28 void OnFinalMessage(HWND hWnd) { delete this; }; 29 30 void Init() 31 { 32 m_pCloseBtn = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("close"))); 33 m_pMinBtn = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("min"))); 34 m_pjiamiBtn = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("jiami"))); 35 m_pjiemiBtn = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("jiemi"))); 36 m_pkey = static_cast<CEditUI*>(m_PaintManager.FindControl(_T("key"))); 37 m_pmingwen = static_cast<CRichEditUI*>(m_PaintManager.FindControl(_T("mingwen"))); 38 m_pmiwen = static_cast<CRichEditUI*>(m_PaintManager.FindControl(_T("miwen"))); 39 m_pmingwen->SetFont(0); 40 } 41 //WindowClassName 42 LPCTSTR GetWindowClassName()const{ return _T("DUIWND"); } 43 //響應控件消息 44 void Notify(TNotifyUI& msg) 45 { 46 47 if (msg.sType == _T("click")) 48 { 49 50 if (msg.pSender == m_pCloseBtn) 51 { 52 PostQuitMessage(0); 53 return; 54 } 55 else if (msg.pSender == m_pMinBtn) 56 { 57 SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); 58 return; 59 } 60 else if (msg.pSender==m_pjiamiBtn) 61 { 62 //if (m_pmingwen) 63 CDuiString mi = L" "; 64 CDuiString str = L" "; 65 if ((m_pmingwen->GetText()).IsEmpty()) 66 { 67 MessageBox(NULL, L"輸入8位明文(如:perfect!)", NULL, 0); 68 return; 69 } 70 if ((m_pkey->GetText()).IsEmpty()) 71 { 72 MessageBox(NULL, L"輸入7位密鑰(如:zjut666)", NULL, 0); 73 return; 74 } 75 else 76 { 77 78 if ((m_pkey->GetText()).GetLength() < 7) 79 { 80 MessageBox(NULL, L"輸入7位密鑰(如:zjut666)", NULL, 0); 81 return; 82 } 83 CDuiString strlong = m_pmingwen->GetText(); 84 CDuiString key = m_pkey->GetText(); 85 86 Destory(); 87 int num = key.GetAt(0); 88 DseInit(num); 89 90 91 92 int strbit[65], leftbit[33], rightbit[33]; 93 int leftkey[29], rightkey[29], key48[50];//保存左右28位密鑰 94 95 m_pmiwen->SetText(L""); 96 int duan = ((m_pmingwen->GetText().GetLength()-1) / 8) + 1; 97 for (int l = 0; l < duan; l++) 98 { 99 for (int k = 0; k < 8; k++) 100 { 101 if (l * 8 + k == m_pmingwen->GetText().GetLength()) 102 { 103 str.SetAt( k,_T(' ')); 104 } 105 else 106 { 107 str.SetAt(k, m_pmingwen->GetText().GetAt(l * 8 + k)); 108 } 109 110 } 111 str_to_bit(str, strbit);//64位明文 112 ip_change(strbit); 113 divisionkey(key, leftkey, rightkey); 114 divisionbit(strbit, leftbit, rightbit); 115 for (int number = 1; number <= 16; number++) 116 { 117 keymovebit(key48, leftkey, rightkey, number);//strkey 1-48位位Kn字密鑰,正確 118 stepbit(leftbit, rightbit, key48); 119 } 120 addtomi(rightbit, leftbit, strbit);//左右ip逆變換 121 122 for (int i = 1; i < 65; i++) 123 { 124 if (strbit[i] == 1) 125 mi.SetAt(i-1, _T('1')); 126 else 127 mi.SetAt(i-1, _T('0')); 128 } 129 m_pmiwen->AppendText(mi); 130 } 131 } 132 } 133 else if (msg.pSender == m_pjiemiBtn) 134 { 135 CDuiString mi = L" "; 136 CDuiString str = L" "; 137 if ((m_pmingwen->GetText()).IsEmpty()) 138 { 139 MessageBox(NULL, L"輸入64位密文", NULL, 0); 140 return; 141 } 142 if ((m_pkey->GetText()).IsEmpty()) 143 { 144 MessageBox(NULL, L"輸入7位密鑰(如:zjut666)", NULL, 0); 145 return; 146 } 147 else 148 { 149 150 if ((m_pkey->GetText()).GetLength() < 7) 151 { 152 MessageBox(NULL, L"輸入7位密鑰(如:zjut666)", NULL, 0); 153 return; 154 } 155 m_pmiwen->SetText(L""); 156 CDuiString strlong = m_pmingwen->GetText(); 157 CDuiString key = m_pkey->GetText(); 158 159 160 int num = key.GetAt(0); 161 162 Destory(); 163 DseInit(num); 164 165 166 int strbit[65], leftbit[33], rightbit[33]; 167 int leftkey[29], rightkey[29], key48[50];//保存左右28位密鑰 168 int key_t[16][49]; 169 int duan = (m_pmingwen->GetText().GetLength() / 64); 170 for (int t = 0; t < duan; t++) 171 { 172 for (int j = 0; j < 64; j++) 173 { 174 175 str.SetAt(j, m_pmingwen->GetText().GetAt(t * 64 + j)); 176 } 177 for (int i = 1; i < 65; i++) 178 { 179 if (str.GetAt(i - 1) == _T('1')) 180 strbit[i] = 1; 181 else 182 strbit[i] = 0; 183 } 184 ip_change(strbit); 185 divisionbit(strbit, leftbit, rightbit); 186 divisionkey(key, leftkey, rightkey); 187 for (int number = 1; number <= 16; number++) 188 { 189 keymovebit(key48, leftkey, rightkey, number);//strkey 1-48位位Kn字密鑰,正確 190 copyint(key_t[number - 1], key48); 191 } 192 for (int m = 15; m >= 0; m--) 193 { 194 stepbit(leftbit, rightbit, key_t[m]); 195 } 196 addtomi(rightbit, leftbit, strbit); 197 198 char a[100]; 199 TCHAR p[100]; 200 int res = 0, mid = 1; 201 for (int i = 1; i <= 64; i++) 202 { 203 if (i % 8 == 0) 204 { 205 res += strbit[i]; 206 207 a[i / 8 - 1] = (char)res; 208 res = 0; 209 } 210 else{ 211 res += strbit[i] * pow(2, 8 - i % 8); 212 } 213 214 } 215 MultiByteToWideChar(CP_ACP, 0, a, -1, p, 100); 216 for (int j = 0; j<8; j++) 217 { 218 if (p[j]>0 && p[j] < 255) 219 { 220 mi.SetAt(j, p[j]); 221 222 } 223 else 224 { 225 mi.SetAt(j, _T(' ')); 226 } 227 228 } 229 m_pmiwen->AppendText(mi); 230 231 232 233 } 234 235 236 237 } 238 } 239 } 240 } 241 //響應窗口消息 242 LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 243 { 244 LONG styleValue = ::GetWindowLong(*this, GWL_STYLE); 245 styleValue &= ~WS_CAPTION; 246 ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); 247 248 m_PaintManager.Init(m_hWnd); 249 CDialogBuilder builder; 250 CControlUI* pRoot = builder.Create(_T("duilib.xml"), (UINT)0, NULL, &m_PaintManager); 251 ASSERT(pRoot && "Failed to parse XML"); 252 m_PaintManager.AttachDialog(pRoot); 253 m_PaintManager.AddNotifier(this); 254 255 Init(); 256 return 0; 257 } 258 259 LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 260 { 261 ::PostQuitMessage(0L); 262 bHandled = FALSE; 263 return 0; 264 } 265 266 LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 267 { 268 if (::IsIconic(*this)) bHandled = FALSE; 269 return (wParam == 0) ? TRUE : FALSE; 270 } 271 272 LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 273 { 274 return 0; 275 } 276 277 LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 278 { 279 return 0; 280 } 281 282 LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 283 { 284 POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); 285 ::ScreenToClient(*this, &pt); 286 287 RECT rcClient; 288 ::GetClientRect(*this, &rcClient); 289 290 RECT rcCaption = m_PaintManager.GetCaptionRect(); 291 if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \ 292 && pt.y >= rcCaption.top && pt.y < rcCaption.bottom) { 293 CControlUI* pControl = static_cast<CControlUI*>(m_PaintManager.FindControl(pt)); 294 if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0) 295 return HTCAPTION; 296 } 297 298 return HTCLIENT; 299 } 300 301 LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 302 { 303 SIZE szRoundCorner = m_PaintManager.GetRoundCorner(); 304 if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0)) { 305 CDuiRect rcWnd; 306 ::GetWindowRect(*this, &rcWnd); 307 rcWnd.Offset(-rcWnd.left, -rcWnd.top); 308 rcWnd.right++; rcWnd.bottom++; 309 HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy); 310 ::SetWindowRgn(*this, hRgn, TRUE); 311 ::DeleteObject(hRgn); 312 } 313 314 bHandled = FALSE; 315 return 0; 316 } 317 LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) 318 { 319 LRESULT lRes = 0; 320 BOOL bHandled = TRUE; 321 switch (uMsg) { 322 case WM_CREATE: lRes = OnCreate(uMsg, wParam, lParam, bHandled); break; 323 case WM_DESTROY: lRes = OnDestroy(uMsg, wParam, lParam, bHandled); break; 324 case WM_NCACTIVATE: lRes = OnNcActivate(uMsg, wParam, lParam, bHandled); break; 325 case WM_NCCALCSIZE: lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled); break; 326 case WM_NCPAINT: lRes = OnNcPaint(uMsg, wParam, lParam, bHandled); break; 327 case WM_NCHITTEST: lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled); break; 328 case WM_SIZE: lRes = OnSize(uMsg, wParam, lParam, bHandled); break; 329 default: 330 bHandled = FALSE; 331 } 332 if (bHandled) return lRes; 333 if (m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes; 334 return CWindowWnd::HandleMessage(uMsg, wParam, lParam); 335 } 336 337 338 private: 339 CButtonUI* m_pCloseBtn; 340 CButtonUI* m_pMinBtn; 341 CButtonUI* m_pjiamiBtn; 342 CButtonUI* m_pjiemiBtn; 343 CRichEditUI* m_pmingwen; 344 CRichEditUI* m_pmiwen; 345 CEditUI* m_pkey; 346 }; 347 348 349 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) 350 { 351 CPaintManagerUI::SetInstance(hInstance); 352 CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() ); 353 354 HRESULT Hr = ::CoInitialize(NULL); 355 if (FAILED(Hr)) return 0; 356 CDuiFrameWnd* pFrame = new CDuiFrameWnd(); 357 if (pFrame == NULL) return 0; 358 pFrame->Create(NULL, NULL, UI_WNDSTYLE_DIALOG, 0); 359 pFrame->CenterWindow(); 360 pFrame->ShowWindow(true); 361 362 CPaintManagerUI::MessageLoop(); 363 364 ::CoUninitialize(); 365 return 0; 366 }
界面的代碼:加密
初學者,因此代碼比較差勁。spa
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> <Window size="470,290" sizebox="4,4,6,6" caption="0,0,0,30" roundcorner="8,8"> <Font shared="true" id="0" name="幼圓" size="16" default="true" /> <VerticalLayout width="300" height="500" bkimage="skin\skin1.jpg" enabled="true"> <Button name="close" float="true" width="25" height="25" pos="444,3,0,0" normalimage="skin\sysbtn_close_normal.png" hotimage="skin\sysbtn_close_hover.png" pushedimage="skin\sysbtn_close_down.png"borderround="4,4" /> <Button name="min" float="true" width="25" height="25" pos="415,3,0,0" normalimage="skin\sysbtn_min_normal.png" hotimage="skin\sysbtn_min_hover.png" pushedimage="skin\sysbtn_min_down.png" borderround="4,4"/> <RichEdit name="mingwen" float="true" pos="20,35,450,125" bordercolor="0xFFFFFFFF" bordersize="1" borderround="6,6" bordervisible="true" vscrollbar="true" autovscroll="true"/> <Text text="密鑰:" float="true" pos="20,140,100,165" align="center"/> <Edit name="key" float="true" pos="100,135,180,165" maxchar="7" align="center" borderround="6,6" bordervisible="true"/> <Button name="jiami" float="true" pos="300,135,370,165" text="加密" normalimage="skin\normal_button.png" hotimage="skin\hot_button.png" pushedimage="skin\down_button.png" borderround="6,6"/> <Button name="jiemi" float="true" pos="380,135,450,165" text="解密" normalimage="skin\normal_button.png" hotimage="skin\hot_button.png" pushedimage="skin\down_button.png" borderround="6,6"/> <RichEdit name="miwen" float="true" pos="20,175,450,270" bordercolor="0xFFFFFFFF" bordersize="1" borderround="6,6" bordervisible="true" vscrollbar="true" autovscroll="true" /> </VerticalLayout> </Window>
實驗結果:code
程序源碼打包下載:http://pwpan.com/fs/815295171124c16e5ce7/