-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInternetApp.cpp
More file actions
826 lines (596 loc) · 22.2 KB
/
InternetApp.cpp
File metadata and controls
826 lines (596 loc) · 22.2 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
// InternetApp.cpp
#include "InternetApp.h"
// Global variables
LPTSTR g_lpszParentUrl;
LPTSTR g_lpszRequiredTagName;
LPTSTR g_lpszRequiredAttributeName;
LPTSTR g_lpszAttributeMustContain;
int TagFunction( LPCTSTR lpszTag, LPCTSTR lpszRequiredTagName, LPCTSTR lpszRequiredAttributeName, LPCTSTR lpszAttributeMustContain )
{
int nResult = -1;
// See if this is an image tag
if( HtmlFileIsTagName( lpszTag, lpszRequiredTagName ) )
{
// This is an image tag
// Allocate string memory
LPTSTR lpszAttributeUrl = new char[ STRING_LENGTH + sizeof( char ) ];
// Get attribute url
if( HtmlFileGetAttributeUrl( g_lpszParentUrl, lpszTag, lpszRequiredAttributeName, lpszAttributeUrl ) )
{
// Successfully got attribute url
// See if attribute contains required text
if( ( FindTextInString( lpszAttributeUrl, lpszAttributeMustContain ) >= 0 ) || ( lstrlen( lpszAttributeMustContain ) == 0 ) )
{
// Attribute contains required text (or required text is empty)
// Allocate string memory
LPTSTR lpszLocalFilePath = new char[ STRING_LENGTH + sizeof( char ) ];
// Add url to list view window
nResult = ListViewWindowAddItem( lpszAttributeUrl );
// Ensure that url was added to list view window
if( nResult >= 0 )
{
// Successfully added url to list view window
// Download file
if( InternetDownloadFile( lpszAttributeUrl, lpszLocalFilePath, &StatusBarWindowSetText ) )
{
// Successfully downloaded file
// Add local file path to list view window
ListViewWindowSetItemTextEx( nResult, LIST_VIEW_WINDOW_LOCAL_FILE_PATH_COLUMN_ID, lpszLocalFilePath );
} // End of successfully downloaded file
else
{
// Unable to download file
// Add local file path to list view window
ListViewWindowSetItemTextEx( nResult, LIST_VIEW_WINDOW_LOCAL_FILE_PATH_COLUMN_ID, INTERNET_UNABLE_TO_DOWNLOAD_FILE_STATUS_MESSAGE );
} // End of unable to download file
} // End of successfully added url to list view window
// Free string memory
delete [] lpszLocalFilePath;
} // End of attribute contains required text (or required text is empty)
} // End of successfully got attribute url
// Free string memory
delete [] lpszAttributeUrl;
} // End of this is an image tag
return nResult;
} // End of function TagFunction
BOOL EditWindowChangeFunction( DWORD dwTextLength )
{
BOOL bResult = FALSE;
// See if edit window contains text
if( dwTextLength )
{
// Edit window contains text
// Enable button window
ButtonWindowEnable( TRUE );
} // End of edit window contains text
else
{
// Edit window is empty
// Disable button window
ButtonWindowEnable( FALSE );
} // End of edit window is empty
return bResult;
} // End of function EditWindowChangeFunction
BOOL ListViewWindowDoubleClickFunction( LPCTSTR lpszItemText )
{
BOOL bResult = FALSE;
// Allocate string memory
LPTSTR lpszAttributeValue = new char[ STRING_LENGTH + sizeof( char ) ];
// Show tag
HtmlFileGetAttributeValue( lpszItemText, "src", lpszAttributeValue );
// Free string memory
delete [] lpszAttributeValue;
return bResult;
} // End of function ListViewWindowDoubleClickFunction
int ShowAboutMessage( HWND hWndParent )
{
int nResult = 0;
MSGBOXPARAMS mbp;
// Clear message box parameter structure
ZeroMemory( &mbp, sizeof( mbp ) );
// Initialise message box parameter structure
mbp.cbSize = sizeof( MSGBOXPARAMS );
mbp.hwndOwner = hWndParent;
mbp.hInstance = GetModuleHandle( NULL );
mbp.lpszText = ABOUT_MESSAGE_TEXT;
mbp.lpszCaption = ABOUT_MESSAGE_CAPTION;
mbp.dwStyle = ( MB_OK | MB_USERICON );
mbp.lpszIcon = MAIN_WINDOW_CLASS_ICON_NAME;
// Show message box
nResult = MessageBoxIndirect( &mbp );
return nResult;
} // End of function ShowAboutMessage
LRESULT CALLBACK MainWindowProcedure( HWND hWndMain, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
LRESULT lr = 0;
// Select message
switch( uMsg )
{
case WM_CREATE:
{
// A create message
HINSTANCE hInstance;
HFONT hFont;
// Allocate string memory
LPTSTR lpszInitialUrl = new char[ STRING_LENGTH + sizeof( char ) ];
// Get instance
hInstance = ( ( LPCREATESTRUCT )lParam )->hInstance;
// Open clipboard
if( OpenClipboard( NULL ) )
{
// Successfully opened clipboard
HANDLE hClipboard;
// Get clipboard data
hClipboard = GetClipboardData( CF_TEXT );
// Ensure that clipboard data was got
if( hClipboard )
{
// Successfully got clipboard data
LPTSTR lpszClipboard;
// Lock clipboard text into memory
lpszClipboard = ( LPTSTR )( GlobalLock( hClipboard ) );
// Ensure that clipboard text was locked into global memory
if( lpszClipboard )
{
// Successfully locked clipboard text into global memory
// Update initial url
lstrcpy( lpszInitialUrl, lpszClipboard );
// Unlock global global memory
GlobalUnlock( hClipboard );
} // End of successfully locked clipboard text into global memory
} // End of successfully got clipboard data
else
{
// Unable to get clipboard data
// Use default initial url
lstrcpy( lpszInitialUrl, DEFAULT_URL );
} // End of unable to get clipboard data
// Close clipboard
CloseClipboard();
} // End of successfully opened clipboard
else
{
// Unable to open clipboard
// Use default initial url
lstrcpy( lpszInitialUrl, DEFAULT_URL );
} // End of unable to open clipboard
// Get font
hFont = ( HFONT )GetStockObject( DEFAULT_GUI_FONT );
// Create edit window
if( EditWindowCreate( hWndMain, hInstance, lpszInitialUrl ) )
{
// Successfully created edit window
// Set edit window font
EditWindowSetFont( hFont );
// Create button window
if( ButtonWindowCreate( hWndMain, hInstance ) )
{
// Successfully created button window
// Set button window font
ButtonWindowSetFont( hFont );
// Create list view window
if( ListViewWindowCreate( hWndMain, hInstance ) )
{
// Successfully created list view window
// Set list view window font
ListViewWindowSetFont( hFont );
// Create status bar window
if( StatusBarWindowCreate( hWndMain, hInstance ) )
{
// Successfully created status bar window
// Set status bar window font
StatusBarWindowSetFont( hFont );
// Select edit window text
EditWindowSelect();
} // End of successfully created status bar window
} // End of successfully created list view window
} // End of successfully created button window
} // End of successfully created edit window
// Free string memory
delete [] lpszInitialUrl;
// Break out of switch
break;
} // End of a create message
case WM_SIZE:
{
// A size message
int nClientWidth;
int nClientHeight;
RECT rcStatus;
int nStatusWindowHeight;
int nListViewWindowHeight;
int nListViewWindowTop;
int nEditWindowWidth;
int nButtonWindowLeft;
// Store client width and height
nClientWidth = ( int )LOWORD( lParam );
nClientHeight = ( int )HIWORD( lParam );
// Size status bar window
StatusBarWindowSize();
// Get status window size
StatusBarWindowGetRect( &rcStatus );
// Calculate window sizes
nStatusWindowHeight = ( rcStatus.bottom - rcStatus.top );
nListViewWindowHeight = ( nClientHeight - ( nStatusWindowHeight + BUTTON_WINDOW_HEIGHT ) + WINDOW_BORDER_HEIGHT );
nEditWindowWidth = ( ( nClientWidth - BUTTON_WINDOW_WIDTH ) + WINDOW_BORDER_WIDTH );
// Calculate window positions
nListViewWindowTop = ( BUTTON_WINDOW_HEIGHT - WINDOW_BORDER_HEIGHT );
nButtonWindowLeft = ( nEditWindowWidth - WINDOW_BORDER_WIDTH );
// Move control windows
ListViewWindowMove( 0, nListViewWindowTop, nClientWidth, nListViewWindowHeight, TRUE );
EditWindowMove( 0, 0, nEditWindowWidth, BUTTON_WINDOW_HEIGHT, TRUE );
ButtonWindowMove( nButtonWindowLeft, 0, BUTTON_WINDOW_WIDTH, BUTTON_WINDOW_HEIGHT, TRUE );
// Break out of switch
break;
} // End of a size message
case WM_ACTIVATE:
{
// An activate message
// Focus on edit window
EditWindowSetFocus();
// Break out of switch
break;
} // End of an activate message
case WM_GETMINMAXINFO:
{
// A get min max info message
MINMAXINFO FAR *lpMinMaxInfo;
// Get min max info structure
lpMinMaxInfo = ( MINMAXINFO FAR * )lParam;
// Update min max info structure
lpMinMaxInfo->ptMinTrackSize.x = MAIN_WINDOW_MINIMUM_WIDTH;
lpMinMaxInfo->ptMinTrackSize.y = MAIN_WINDOW_MINIMUM_HEIGHT;
// Break out of switch
break;
} // End of a get min max info message
case WM_COMMAND:
{
// A command message
// Select command
switch( LOWORD( wParam ) )
{
case BUTTON_WINDOW_ID:
{
// A button window command
// Allocate string memory
LPTSTR lpszUrl = new char[ STRING_LENGTH + sizeof( char ) ];
// Get url from edit window
if( EditWindowGetText( lpszUrl, STRING_LENGTH ) )
{
// Successfully got url from edit window
// Allocate string memory
LPTSTR lpszLocalFilePath = new char[ STRING_LENGTH + sizeof( char ) ];
// Download file
if( InternetDownloadFile( lpszUrl, lpszLocalFilePath, &StatusBarWindowSetText ) )
{
// Successfully downloaded file
// Load html file
if( HtmlFileLoad( lpszLocalFilePath ) )
{
// Successfully loaded html file
int nTagCount;
// Allocate string memory
LPTSTR lpszStatusMessage = new char[ STRING_LENGTH + sizeof( char ) ];
// Update global parent url (this neesd to be done before we process the tags)
lstrcpy( g_lpszParentUrl, lpszUrl );
// Ensure that global parent url ends with a forward slash
if( g_lpszParentUrl[ lstrlen( g_lpszParentUrl ) - sizeof( char ) ] != ASCII_FORWARD_SLASH_CHARACTER )
{
// Global parent url does not end with a forward slash
// Append a forward slash onto global parent url
lstrcat( g_lpszParentUrl, ASCII_FORWARD_SLASH_STRING );
} // End of global parent url does not end with a forward slash
// Process tags
nTagCount = HtmlFileProcessTags( g_lpszRequiredTagName, g_lpszRequiredAttributeName, g_lpszAttributeMustContain, &TagFunction );
// Auto-size all list view window columns
ListViewWindowAutoSizeAllColumns()
;
// Format status message
wsprintf( lpszStatusMessage, HTML_FILE_PROCESS_TAGS_STATUS_MESSAGE_FORMAT_STRING, lpszLocalFilePath, nTagCount );
// Show status message on status bar window
StatusBarWindowSetText( lpszStatusMessage );
// Free memory
HtmlFileFreeMemory();
// Free string memory
delete [] lpszStatusMessage;
} // End of successfully loaded html file
} // End of successfully downloaded file
// Free string memory
delete [] lpszLocalFilePath;
} // End of successfully got url from edit window
// Free string memory
delete [] lpszUrl;
// Break out of switch
break;
} // End of a button window command
case IDM_FILE_EXIT:
{
// A file exit command
// Destroy main window
DestroyWindow( hWndMain );
// Break out of switch
break;
} // End of a file exit command
case IDM_HELP_ABOUT:
{
// A help about command
// Show about message
ShowAboutMessage( hWndMain );
// Break out of switch
break;
} // End of a help about command
default:
{
// Default command
// See if command message is from edit window
if( IsEditWindow( ( HWND )lParam ) )
{
// Command message is from edit window
// Handle command message from edit window
if( !( EditWindowHandleCommandMessage( wParam, lParam, &EditWindowChangeFunction ) ) )
{
// Command message was not handled from edit window
// Call default procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
} // End of command message was not handled from edit window
} // End of command message is from edit window
else
{
// Command message is not from list view window
// Call default procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
} // End of command message is not from list view window
// Break out of switch
break;
} // End of default command
}; // End of selection for command
// Break out of switch
break;
} // End of a command message
case WM_SYSCOMMAND:
{
// A system command message
// Select system command
switch( LOWORD( wParam ) )
{
case IDM_HELP_ABOUT:
{
// A help about system command
// Show about message
ShowAboutMessage( hWndMain );
// Break out of switch
break;
} // End of a help about system command
default:
{
// Default system command
// Call default procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
// Break out of switch
break;
} // End of default system command
}; // End of selection for system command
// Break out of switch
break;
} // End of a system command message
case WM_NOTIFY:
{
// A notify message
LPNMHDR lpNmHdr;
// Get notify message handler
lpNmHdr = ( LPNMHDR )lParam;
// See if notify message is from list view window
if( IsListViewWindow( lpNmHdr->hwndFrom ) )
{
// Notify message is from list view window
// Handle notify message from list view window
if( !( ListViewWindowHandleNotifyMessage( wParam, lParam, &StatusBarWindowSetText ) ) )
{
// Notify message was not handled from list view window
// Call default procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
} // End of notify message was not handled from list view window
} // End of notify message is from list view window
else
{
// Notify message is not from list view window
// Call default procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
} // End of notify message is not from list view window
// Break out of switch
break;
} // End of a notify message
case WM_CONTEXTMENU:
{
// A context menu message
HMENU hMenu;
// Load context menu
hMenu = LoadMenu( NULL, MAKEINTRESOURCE( IDR_CONTEXT_MENU ) );
// Show context menu
TrackPopupMenu( GetSubMenu( hMenu, 0 ), ( TPM_LEFTALIGN | TPM_LEFTBUTTON ), LOWORD( lParam ), HIWORD( lParam ), 0, hWndMain, NULL );
// Break out of switch
break;
} // End of a context menu message
case WM_CLOSE:
{
// A close message
// Destroy main window
DestroyWindow( hWndMain );
// Break out of switch
break;
} // End of a close message
case WM_DESTROY:
{
// A destroy message
// Terminate thread
PostQuitMessage( 0 );
// Break out of switch
break;
} // End of a destroy message
default:
{
// Default message
// Call default window procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
// Break out of switch
break;
} // End of default message
}; // End of selection for message
return lr;
} // End of function MainWindowProcedure
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow )
{
MSG msg;
// Allocate global memory
g_lpszParentUrl = new char[ STRING_LENGTH + sizeof( char ) ];
g_lpszRequiredTagName = new char[ STRING_LENGTH + sizeof( char ) ];
g_lpszRequiredAttributeName = new char[ STRING_LENGTH + sizeof( char ) ];
g_lpszAttributeMustContain = new char[ STRING_LENGTH + sizeof( char ) ];
// Clear global strings
g_lpszParentUrl[ 0 ] = ( char )NULL;
g_lpszRequiredTagName[ 0 ] = ( char )NULL;
g_lpszRequiredAttributeName[ 0 ] = ( char )NULL;
g_lpszAttributeMustContain[ 0 ] = ( char )NULL;
// Clear message structure
ZeroMemory( &msg, sizeof( msg ) );
// Connect to internet
if( InternetConnect() )
{
// Successfully connected to internet
WNDCLASSEX wcMain;
// Clear window class structure
ZeroMemory( &wcMain, sizeof( wcMain ) );
// Initialise window class structure
wcMain.cbSize = sizeof( WNDCLASSEX );
wcMain.lpfnWndProc = MainWindowProcedure;
wcMain.hInstance = hInstance;
wcMain.lpszClassName = MAIN_WINDOW_CLASS_NAME;
wcMain.style = MAIN_WINDOW_CLASS_STYLE;
wcMain.hIcon = MAIN_WINDOW_CLASS_ICON;
wcMain.hCursor = MAIN_WINDOW_CLASS_CURSOR;
wcMain.hbrBackground = MAIN_WINDOW_CLASS_BACKGROUND;
wcMain.lpszMenuName = MAIN_WINDOW_CLASS_MENU_NAME;
wcMain.hIconSm = MAIN_WINDOW_CLASS_ICON_SMALL;
// Register main window class
if( RegisterClassEx( &wcMain ) )
{
// Successfully registered main window class
HWND hWndMain;
// Create main window
hWndMain = CreateWindowEx( MAIN_WINDOW_EXTENDED_STYLE, MAIN_WINDOW_CLASS_NAME, MAIN_WINDOW_TEXT, MAIN_WINDOW_STYLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
// Ensure that main window was created
if( hWndMain )
{
// Successfully created main window
HMENU hMenuSystem;
LPWSTR *lpszArgumentList;
int nArgumentCount;
// Get system menu
hMenuSystem = GetSystemMenu( hWndMain, FALSE );
// Add separator item to system menu
InsertMenu( hMenuSystem, SYSTEM_MENU_SEPARATOR_ITEM_POSITION, ( MF_BYPOSITION | MF_SEPARATOR ), 0, NULL );
// Add about item to system menu
InsertMenu( hMenuSystem, SYSTEM_MENU_ABOUT_ITEM_POSITION, MF_BYPOSITION, IDM_HELP_ABOUT, SYSTEM_MENU_ABOUT_ITEM_TEXT );
// Get argument list
lpszArgumentList = CommandLineToArgvW( GetCommandLineW(), &nArgumentCount );
// Initialise global data
lstrcpy( g_lpszRequiredTagName, ( LPTSTR )DEFAULT_REQUIRED_TAG_NAME );
lstrcpy( g_lpszRequiredAttributeName, ( LPTSTR )DEFAULT_REQUIRED_ATTRIBUTE_NAME );
lstrcpy( g_lpszAttributeMustContain, ( LPTSTR )DEFAULT_ATTRIBUTE_MUST_CONTAIN );
// Ensure that argument list was got
if( lpszArgumentList )
{
// Successfully got argument list
int nSizeNeeded;
int nWideArgumentLength;
// Allocate string memory
LPTSTR lpszArgument = new char[ STRING_LENGTH + sizeof( char ) ];
// See if tag name argument is valid
if( nArgumentCount > INTERNET_TAG_NAME_ARGUMENT )
{
// Tag name argument is valid
// Get wide argument length
nWideArgumentLength = lstrlenW( lpszArgumentList[ INTERNET_TAG_NAME_ARGUMENT ] );
// Get size required for argument
nSizeNeeded = WideCharToMultiByte( CP_UTF8, 0, lpszArgumentList[ INTERNET_TAG_NAME_ARGUMENT ], nWideArgumentLength, NULL, 0, NULL, NULL );
// Convert argument to ansi
WideCharToMultiByte( CP_UTF8, 0, lpszArgumentList[ INTERNET_TAG_NAME_ARGUMENT ], nWideArgumentLength, lpszArgument, nSizeNeeded, NULL, NULL );
// Terminate argument
lpszArgument[ nSizeNeeded ] = ( char )NULL;
// Copy argument into required tag name
lstrcpy( g_lpszRequiredTagName, lpszArgument );
// See if attribute name argument is valid
if( nArgumentCount > INTERNET_ATTRIBUTE_NAME_ARGUMENT )
{
// Attribute name argument is valid
// Get wide argument length
nWideArgumentLength = lstrlenW( lpszArgumentList[ INTERNET_ATTRIBUTE_NAME_ARGUMENT ] );
// Get size required for argument
nSizeNeeded = WideCharToMultiByte( CP_UTF8, 0, lpszArgumentList[ INTERNET_ATTRIBUTE_NAME_ARGUMENT ], nWideArgumentLength, NULL, 0, NULL, NULL );
// Convert argument to ansi
WideCharToMultiByte( CP_UTF8, 0, lpszArgumentList[ INTERNET_ATTRIBUTE_NAME_ARGUMENT ], nWideArgumentLength, lpszArgument, nSizeNeeded, NULL, NULL );
// Terminate argument
lpszArgument[ nSizeNeeded ] = ( char )NULL;
// Copy argument into required attribute
lstrcpy( g_lpszRequiredAttributeName, lpszArgument );
// See if must contain argument is valid
if( nArgumentCount > INTERNET_ATTRIBUTE_MUST_CONTAIN_ARGUMENT )
{
// Attribute must contain argument is valid
// Get wide argument length
nWideArgumentLength = lstrlenW( lpszArgumentList[ INTERNET_ATTRIBUTE_MUST_CONTAIN_ARGUMENT ] );
// Get size required for argument
nSizeNeeded = WideCharToMultiByte( CP_UTF8, 0, lpszArgumentList[ INTERNET_ATTRIBUTE_MUST_CONTAIN_ARGUMENT ], nWideArgumentLength, NULL, 0, NULL, NULL );
// Convert argument to ansi
WideCharToMultiByte( CP_UTF8, 0, lpszArgumentList[ INTERNET_ATTRIBUTE_MUST_CONTAIN_ARGUMENT ], nWideArgumentLength, lpszArgument, nSizeNeeded, NULL, NULL );
// Terminate argument
lpszArgument[ nSizeNeeded ] = ( char )NULL;
// Copy argument into required attribute
lstrcpy( g_lpszAttributeMustContain, lpszArgument );
} // End of attribute must contain argument is valid
} // End of attribute name argument is valid
} // End of tag name argument is valid
// Free string memory
delete [] lpszArgument;
} // End of successfully got argument list
// Show main window
ShowWindow( hWndMain, nCmdShow );
// Update main window
UpdateWindow( hWndMain );
// Message loop
while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
{
// Translate message
TranslateMessage( &msg );
// Dispatch message
DispatchMessage( &msg );
}; // End of message loop
} // End of successfully main created window
else
{
// Unable to create main window
// Display error message
MessageBox( NULL, UNABLE_TO_CREATE_MAIN_WINDOW_ERROR_MESSAGE, ERROR_MESSAGE_CAPTION, ( MB_OK | MB_ICONERROR ) );
} // End of unable to create main window
} // End of successfully registered main window class
else
{
// Unable to register main window class
// Display error message
MessageBox( NULL, UNABLE_TO_REGISTER_MAIN_WINDOW_CLASS_ERROR_MESSAGE, ERROR_MESSAGE_CAPTION, ( MB_OK | MB_ICONERROR ) );
} // End of unable to register main window class
// Close internet
InternetClose();
} // End of successfully connected to internet
else
{
// Unable to connect to internet
// Display error message
MessageBox( NULL, INTERNET_UNABLE_TO_CONNECT_TO_INTERNET_ERROR_MESSAGE, ERROR_MESSAGE_CAPTION, ( MB_OK | MB_ICONERROR ) );
} // End of unable to connect to internet
// Free global memory
delete [] g_lpszParentUrl;
delete [] g_lpszRequiredTagName;
delete [] g_lpszRequiredAttributeName;
return msg.wParam;
} // End of function WinMain