1 | #include <windows.h> |
2 | #include <windowsx.h> |
3 | #include "resource.h" |
4 | #include <stdio.h> |
5 | |
6 | HINSTANCE hInst; |
7 | |
8 | LRESULT CALLBACK MainDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam); |
9 | |
10 | LRESULT CALLBACK TxtPasswordWndProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam); |
11 | |
12 | WNDPROC lpfnTxtPasswordWndProc=NULL; |
13 | HWND hMainDlg = NULL; |
14 | HWND hwndTxtPassword = NULL; |
15 | |
16 | int WINAPI WinMain(HINSTANCE hInstance, |
17 | HINSTANCE /*hPrevInstance*/, |
18 | LPTSTR lpCmdLine, int nCmdShow) { |
19 | MSG msg; |
20 | |
21 | hMainDlg = CreateDialog(hInstance, (LPCTSTR)IDD_MAIN_DIALOG, 0,(DLGPROC)MainDlgProc); |
22 | ShowWindow(hMainDlg, nCmdShow); |
23 | hwndTxtPassword = GetDlgItem(hMainDlg,ID_TXT_PASSWORD); |
24 | lpfnTxtPasswordWndProc = (WNDPROC) SetWindowLongPtr(hwndTxtPassword, GWLP_WNDPROC, (LONG_PTR)TxtPasswordWndProc); |
25 | HWND hwndTxtPrompt = GetDlgItem(hMainDlg,ID_TXT_PROMPT); |
26 | Static_SetText(hwndTxtPrompt, lpCmdLine); |
27 | while (GetMessage(&msg, NULL, 0, 0)) { |
28 | TranslateMessage(&msg); |
29 | DispatchMessage(&msg); |
30 | } |
31 | return 0; |
32 | } |
33 | |
34 | //In Subclass Proc |
35 | LRESULT CALLBACK TxtPasswordWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
36 | { |
37 | switch(msg) { |
38 | case WM_KEYDOWN: |
39 | if (wParam==VK_RETURN) { |
40 | char s[500+1]; |
41 | Edit_GetText(hwndTxtPassword,s,500); |
42 | printf(s); |
43 | DestroyWindow(hMainDlg); |
44 | return TRUE; |
45 | } |
46 | break; |
47 | |
48 | } |
49 | |
50 | return CallWindowProc(lpfnTxtPasswordWndProc, hwnd, msg, wParam, lParam); |
51 | } |
52 | |
53 | LRESULT CALLBACK MainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/) { |
54 | switch (message) { |
55 | case WM_INITDIALOG : |
56 | return TRUE ; |
57 | case WM_COMMAND : |
58 | switch (LOWORD (wParam)) { |
59 | case IDOK : |
60 | case IDCANCEL : |
61 | DestroyWindow(hDlg); |
62 | return TRUE ; |
63 | } |
64 | break ; |
65 | case WM_CLOSE: |
66 | DestroyWindow(hDlg); |
67 | return TRUE; |
68 | case WM_DESTROY: |
69 | PostQuitMessage(0); |
70 | return TRUE; |
71 | }; |
72 | return FALSE; |
73 | } |
74 | |