Windows Quiz 3
完成1234,未完成5
1
/**/
/*-------------------------------------------------------
2 POPPAD1.C -- Popup Editor using child window edit box
3 (c) Charles Petzold, 1998
4 -------------------------------------------------------*/
5 /**/ /*
6修改为 QuizZJ.cpp
7修改者 zj
8*/
9
10 #include < windows.h >
11
12 #define ID_EDIT 1
13
14 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
15
16 TCHAR szAppName[] = TEXT ( " QuizZJ " ) ;
17
18 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
19 PSTR szCmdLine, int iCmdShow)
20 {
21 HWND hwnd ;
22 MSG msg ;
23 WNDCLASS wndclass ;
24
25 wndclass.style = CS_HREDRAW | CS_VREDRAW ;
26 wndclass.lpfnWndProc = WndProc ;
27 wndclass.cbClsExtra = 0 ;
28 wndclass.cbWndExtra = 0 ;
29 wndclass.hInstance = hInstance ;
30 wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
31 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
32 wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
33 wndclass.lpszMenuName = NULL ;
34 wndclass.lpszClassName = szAppName ;
35
36 if (!RegisterClass (&wndclass))
37 {
38 MessageBox (NULL, TEXT ("This program requires Windows NT!"),
39 szAppName, MB_ICONERROR) ;
40 return 0 ;
41 }
42
43 hwnd = CreateWindow (szAppName, szAppName,
44 WS_OVERLAPPEDWINDOW,
45 CW_USEDEFAULT, CW_USEDEFAULT,
46 CW_USEDEFAULT, CW_USEDEFAULT,
47 NULL, NULL, hInstance, NULL) ;
48
49 ShowWindow (hwnd, iCmdShow) ;
50 UpdateWindow (hwnd) ;
51
52 while (GetMessage (&msg, NULL, 0, 0))
53 {
54 TranslateMessage (&msg) ;
55 DispatchMessage (&msg) ;
56 }
57 return msg.wParam ;
58}
59
60 WNDPROC OrgWndProc;
61 TCHAR * month[] =
62 {
63 TEXT("January"), TEXT("February"), TEXT("March"), TEXT("April"),
64 TEXT("May"), TEXT("June"), TEXT("July"), TEXT("August"), TEXT("September"),
65 TEXT("October"), TEXT("November"), TEXT("December")
66} ;
67
68 LRESULT CALLBACK PreWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
69 static TCHAR *sz;
70
71 switch ( uMsg ) {
72 case WM_KEYDOWN :
73 case WM_SYSKEYDOWN :
74 switch ( LOWORD(wParam) ) {
75 case VK_F1 : case VK_F2 : case VK_F3 : case VK_F4 : case VK_F5 :
76 case VK_F6 : case VK_F7 : case VK_F8 : case VK_F9 : case VK_F10 :
77 case VK_F11 : case VK_F12 :
78 if ( ::GetKeyState( VK_CONTROL ) < 0 ) {
79 sz = month[ LOWORD(wParam) - VK_F1 ];
80 while ( *sz ) {
81 ::SendMessage( hWnd, WM_CHAR, *sz, 0 );
82 ++sz;
83 }
84 return 0;
85 }
86 if ( ::GetKeyState( VK_SHIFT ) < 0 ) {
87 ::MessageBox( hWnd, TEXT("作者:zj\n学号:10092130***"), TEXT("作者信息"), MB_OK | MB_ICONINFORMATION );
88 return 0;
89 }
90 break;
91 }
92 break;
93 case WM_RBUTTONDOWN :
94 case WM_RBUTTONUP :
95 return 0;
96 case WM_LBUTTONDBLCLK :
97 {
98 // 尚未实现
99 return 0;
100
101 CHOOSEFONT cf = {0};
102 LOGFONT lf = {0};
103 HDC hdc = ::GetDC( hWnd );
104
105 cf.lStructSize = sizeof(cf);
106 cf.hwndOwner = hWnd;
107 cf.hDC = hdc;
108 cf.Flags = 0;
109 if ( ::ChooseFont( &cf ) ) {
110 }
111
112 ::ReleaseDC( hWnd, hdc );
113 }
114 return 0;
115 }
116 return ::CallWindowProc( OrgWndProc, hWnd, uMsg, wParam, lParam );
117}
118
119 LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
120 {
121 static HWND hwndEdit ;
122
123 switch (message)
124 {
125 case WM_CREATE :
126 hwndEdit = CreateWindow (TEXT ("edit"), NULL,
127 WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
128 WS_BORDER | ES_LEFT | ES_MULTILINE |
129 ES_AUTOHSCROLL | ES_AUTOVSCROLL,
130 0, 0, 0, 0, hwnd, (HMENU) ID_EDIT,
131 ((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
132 OrgWndProc = (WNDPROC)::GetWindowLong( hwndEdit, GWL_WNDPROC );
133 ::SetWindowLong( hwndEdit, GWL_WNDPROC, (LONG)PreWndProc );
134 return 0 ;
135
136 case WM_SETFOCUS :
137 SetFocus (hwndEdit) ;
138 return 0 ;
139
140 case WM_SIZE :
141 MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE) ;
142 return 0 ;
143
144 case WM_COMMAND :
145 if (LOWORD (wParam) == ID_EDIT)
146 if (HIWORD (wParam) == EN_ERRSPACE ||
147 HIWORD (wParam) == EN_MAXTEXT)
148
149 MessageBox (hwnd, TEXT ("Edit control out of space."),
150 szAppName, MB_OK | MB_ICONSTOP) ;
151 return 0 ;
152
153 case WM_DESTROY :
154 PostQuitMessage (0) ;
155 return 0 ;
156 }
157 return DefWindowProc (hwnd, message, wParam, lParam) ;
158}
159
2 POPPAD1.C -- Popup Editor using child window edit box
3 (c) Charles Petzold, 1998
4 -------------------------------------------------------*/
5 /**/ /*
6修改为 QuizZJ.cpp
7修改者 zj
8*/
9
10 #include < windows.h >
11
12 #define ID_EDIT 1
13
14 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
15
16 TCHAR szAppName[] = TEXT ( " QuizZJ " ) ;
17
18 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
19 PSTR szCmdLine, int iCmdShow)
20 {
21 HWND hwnd ;
22 MSG msg ;
23 WNDCLASS wndclass ;
24
25 wndclass.style = CS_HREDRAW | CS_VREDRAW ;
26 wndclass.lpfnWndProc = WndProc ;
27 wndclass.cbClsExtra = 0 ;
28 wndclass.cbWndExtra = 0 ;
29 wndclass.hInstance = hInstance ;
30 wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
31 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
32 wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
33 wndclass.lpszMenuName = NULL ;
34 wndclass.lpszClassName = szAppName ;
35
36 if (!RegisterClass (&wndclass))
37 {
38 MessageBox (NULL, TEXT ("This program requires Windows NT!"),
39 szAppName, MB_ICONERROR) ;
40 return 0 ;
41 }
42
43 hwnd = CreateWindow (szAppName, szAppName,
44 WS_OVERLAPPEDWINDOW,
45 CW_USEDEFAULT, CW_USEDEFAULT,
46 CW_USEDEFAULT, CW_USEDEFAULT,
47 NULL, NULL, hInstance, NULL) ;
48
49 ShowWindow (hwnd, iCmdShow) ;
50 UpdateWindow (hwnd) ;
51
52 while (GetMessage (&msg, NULL, 0, 0))
53 {
54 TranslateMessage (&msg) ;
55 DispatchMessage (&msg) ;
56 }
57 return msg.wParam ;
58}
59
60 WNDPROC OrgWndProc;
61 TCHAR * month[] =
62 {
63 TEXT("January"), TEXT("February"), TEXT("March"), TEXT("April"),
64 TEXT("May"), TEXT("June"), TEXT("July"), TEXT("August"), TEXT("September"),
65 TEXT("October"), TEXT("November"), TEXT("December")
66} ;
67
68 LRESULT CALLBACK PreWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
69 static TCHAR *sz;
70
71 switch ( uMsg ) {
72 case WM_KEYDOWN :
73 case WM_SYSKEYDOWN :
74 switch ( LOWORD(wParam) ) {
75 case VK_F1 : case VK_F2 : case VK_F3 : case VK_F4 : case VK_F5 :
76 case VK_F6 : case VK_F7 : case VK_F8 : case VK_F9 : case VK_F10 :
77 case VK_F11 : case VK_F12 :
78 if ( ::GetKeyState( VK_CONTROL ) < 0 ) {
79 sz = month[ LOWORD(wParam) - VK_F1 ];
80 while ( *sz ) {
81 ::SendMessage( hWnd, WM_CHAR, *sz, 0 );
82 ++sz;
83 }
84 return 0;
85 }
86 if ( ::GetKeyState( VK_SHIFT ) < 0 ) {
87 ::MessageBox( hWnd, TEXT("作者:zj\n学号:10092130***"), TEXT("作者信息"), MB_OK | MB_ICONINFORMATION );
88 return 0;
89 }
90 break;
91 }
92 break;
93 case WM_RBUTTONDOWN :
94 case WM_RBUTTONUP :
95 return 0;
96 case WM_LBUTTONDBLCLK :
97 {
98 // 尚未实现
99 return 0;
100
101 CHOOSEFONT cf = {0};
102 LOGFONT lf = {0};
103 HDC hdc = ::GetDC( hWnd );
104
105 cf.lStructSize = sizeof(cf);
106 cf.hwndOwner = hWnd;
107 cf.hDC = hdc;
108 cf.Flags = 0;
109 if ( ::ChooseFont( &cf ) ) {
110 }
111
112 ::ReleaseDC( hWnd, hdc );
113 }
114 return 0;
115 }
116 return ::CallWindowProc( OrgWndProc, hWnd, uMsg, wParam, lParam );
117}
118
119 LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
120 {
121 static HWND hwndEdit ;
122
123 switch (message)
124 {
125 case WM_CREATE :
126 hwndEdit = CreateWindow (TEXT ("edit"), NULL,
127 WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
128 WS_BORDER | ES_LEFT | ES_MULTILINE |
129 ES_AUTOHSCROLL | ES_AUTOVSCROLL,
130 0, 0, 0, 0, hwnd, (HMENU) ID_EDIT,
131 ((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
132 OrgWndProc = (WNDPROC)::GetWindowLong( hwndEdit, GWL_WNDPROC );
133 ::SetWindowLong( hwndEdit, GWL_WNDPROC, (LONG)PreWndProc );
134 return 0 ;
135
136 case WM_SETFOCUS :
137 SetFocus (hwndEdit) ;
138 return 0 ;
139
140 case WM_SIZE :
141 MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE) ;
142 return 0 ;
143
144 case WM_COMMAND :
145 if (LOWORD (wParam) == ID_EDIT)
146 if (HIWORD (wParam) == EN_ERRSPACE ||
147 HIWORD (wParam) == EN_MAXTEXT)
148
149 MessageBox (hwnd, TEXT ("Edit control out of space."),
150 szAppName, MB_OK | MB_ICONSTOP) ;
151 return 0 ;
152
153 case WM_DESTROY :
154 PostQuitMessage (0) ;
155 return 0 ;
156 }
157 return DefWindowProc (hwnd, message, wParam, lParam) ;
158}
159