Subversion Repositories Aucun

Rev

Rev 116 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
114 ixe013 1
/*
2
 Copyright (c) 2008, Guillaume Seguin ([email protected])
3
 All rights reserved.
4
 
5
 Redistribution and use in source and binary forms, with or without
6
 modification, are permitted provided that the following conditions
7
 are met:
8
 
9
 1. Redistributions of source code must retain the above copyright
10
    notice, this list of conditions and the following disclaimer.
11
 
12
 2. Redistributions in binary form must reproduce the above copyright
13
    notice, this list of conditions and the following disclaimer in the
14
    documentation and/or other materials provided with the distribution.
15
 
16
 THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
17
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
 ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
20
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
 SUCH DAMAGE.
27
*/
28
 
112 ixe013 29
#include <windows.h>
114 ixe013 30
#include <lm.h>
112 ixe013 31
#include "loggedout_dlg.h"
32
#include "dlgdefs.h"
33
#include "trace.h"
114 ixe013 34
#include "settings.h"
112 ixe013 35
 
114 ixe013 36
#define _SECURE_ATL 1
37
 
38
#include <atlbase.h>
39
#include <atlapp.h>
40
#include <atlctrls.h>
41
#include "StaticPrompt.h"
42
 
43
static CStaticPromptCtrl gStaticPrompt;
44
 
45
enum
46
{
47
    IDC_SELFSERVE_FIRST = 1000,
48
    IDC_SELFSERVEPROMPT
49
};
50
 
116 ixe013 51
//Moves a control in a dialog
113 ixe013 52
void MoveControl(HWND hwndDlg, int id, int xoffset, int yoffset)
53
{
54
    HWND control = GetDlgItem(hwndDlg, id);
55
 
56
    RECT rect;
57
 
58
    //Move the bottom row controls (Ok, Cancel, Options, etc.)
59
    GetWindowRect(control, &rect);
60
    POINT p;
61
    p.x = rect.left;
62
    p.y = rect.top;
63
 
64
    ScreenToClient(hwndDlg, &p);
65
 
66
    MoveWindow(control, p.x+xoffset, p.y+yoffset, rect.right-rect.left, rect.bottom-rect.top, TRUE);
67
}
68
 
116 ixe013 69
 
70
HWND AddStaticPrompt(HWND hwndDlg)
112 ixe013 71
{
116 ixe013 72
    HWND hwndPrompt = 0;
73
    wchar_t prompt[2048];
74
    if(GetSelfServeSetting(L"Text", prompt, sizeof prompt / sizeof *prompt) == S_OK)
112 ixe013 75
    {
116 ixe013 76
        RECT rect;
77
        POINT p;
78
        int increase = 0;
79
        int margin;
112 ixe013 80
 
116 ixe013 81
        //Create a static prompt control
82
        //As far left as the static controls
83
        GetWindowRect(GetDlgItem(hwndDlg, 1506), &rect);
84
        p.x = rect.left;
85
        p.y = rect.top;
86
        ScreenToClient(hwndDlg, &p);
87
        margin = p.x;
112 ixe013 88
 
116 ixe013 89
        //On the same line as the ok buttons (they will be moved)
90
        GetWindowRect(GetDlgItem(hwndDlg, IDOK), &rect);
91
        p.x = rect.left;
92
        p.y = rect.top;
114 ixe013 93
 
116 ixe013 94
        //As far right as the Option button
95
        GetWindowRect(GetDlgItem(hwndDlg, 1514), &rect);
96
        //As far left as the Ok button
97
        rect.left = p.x;
115 ixe013 98
 
116 ixe013 99
        //Here, rect contains the outer rectangle including all buttons from the bottom row
100
        //rect = left, top and bottom of IDOK,   right of 1514 (options);
114 ixe013 101
 
116 ixe013 102
        //Now convert the top-left coordinate in client for CreateWindow
103
        ScreenToClient(hwndDlg, &p);
114 ixe013 104
 
116 ixe013 105
        //We have the top left corner and the width. Let's create the dialog so we can
106
        //compute the height of the text
107
        hwndPrompt = CreateWindowEx(0, L"STATIC", prompt, SS_LEFT|SS_NOTIFY|WS_CHILD,//|WS_VISIBLE, 
108
            p.x, p.y, rect.right-rect.left, 100, hwndDlg, (HMENU)IDC_SELFSERVEPROMPT, 0, 0);
114 ixe013 109
 
116 ixe013 110
        gStaticPrompt.SubclassWindow(hwndPrompt);
114 ixe013 111
 
116 ixe013 112
        increase = gStaticPrompt.ComputeRequiredHeight();
114 ixe013 113
 
116 ixe013 114
        gStaticPrompt.MoveWindow(p.x, p.y, rect.right-rect.left, increase);
114 ixe013 115
 
116 ixe013 116
        //Get the original window's dimension
117
        GetWindowRect(hwndDlg, &rect);
118
        //Make it bigger
119
        SetWindowPos(hwndDlg, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top+increase+margin,SWP_NOMOVE|SWP_NOZORDER);
114 ixe013 120
 
116 ixe013 121
        //Move the bottom row controls (Ok, Cancel, Options, etc.)
122
        MoveControl(hwndDlg, 24064, 0, increase+margin); //Bitmap (shows current keyboard layout)
123
        MoveControl(hwndDlg, IDOK, 0, increase+margin);  //OK button
124
        MoveControl(hwndDlg, IDCANCEL, 0, increase+margin); //Cancel button
125
        MoveControl(hwndDlg, 1501, 0, increase+margin);  //Shutdown button
126
        MoveControl(hwndDlg, 1514, 0, increase+margin);  //Option button
113 ixe013 127
 
116 ixe013 128
        AnimateWindow(hwndPrompt, 200, AW_VER_POSITIVE|AW_SLIDE);
129
    }
130
 
131
    return hwndPrompt;
132
}
133
 
134
INT_PTR CALLBACK MyWlxWkstaLoggedOutSASDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
135
{
136
    static HWND hwndPrompt = 0;
137
    bool handled = false;
138
    INT_PTR result = 0;
139
 
140
    switch(uMsg)
141
    {
142
    case WM_INITDIALOG :
114 ixe013 143
        {
116 ixe013 144
            SetWindowPos(hwndDlg, 0, 287, 298, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
145
 
146
            result = gDialogsProc[LOGGED_OUT_SAS_dlg].originalproc(hwndDlg, uMsg, wParam, lParam);;
147
            handled = true;
148
 
149
            //TODO : Do no display all the time, detect a bad password attempt
117 ixe013 150
            hwndPrompt = AddStaticPrompt(hwndDlg);
114 ixe013 151
        }
152
        break;
116 ixe013 153
 
113 ixe013 154
    case WM_COMMAND :
114 ixe013 155
        if((HIWORD(wParam) == STN_CLICKED) && (LOWORD(wParam == IDC_SELFSERVEPROMPT)))
113 ixe013 156
        {
114 ixe013 157
                wchar_t username[255];
113 ixe013 158
 
114 ixe013 159
                GetSelfServeSetting(L"Username", username, sizeof username / sizeof *username);
160
                TRACE(L"Switching to selfservice user %s\n", username);
161
 
113 ixe013 162
                ShowWindow(GetDlgItem(hwndDlg, 1502), SW_HIDE); //Username
163
                ShowWindow(GetDlgItem(hwndDlg, 1503), SW_HIDE); //Password
164
                ShowWindow(GetDlgItem(hwndDlg, 1504), SW_HIDE); //Domain
165
 
114 ixe013 166
                //TODO : Change selfservice password here
167
                USER_INFO_1003 ui;
168
                ui.usri1003_password = L"asdf1243";
169
 
170
                NetUserSetInfo(0, username, 1003, (LPBYTE)&ui, 0);
171
                SetDlgItemText(hwndDlg, 1502, username);
172
                SetDlgItemText(hwndDlg, 1503, ui.usri1003_password);
113 ixe013 173
        }
174
        break;
116 ixe013 175
    case WM_DESTROY:
176
        hwndPrompt = 0;
177
        break;
112 ixe013 178
    }
116 ixe013 179
 
112 ixe013 180
 
116 ixe013 181
    if(!handled)
182
        result = gDialogsProc[LOGGED_OUT_SAS_dlg].originalproc(hwndDlg, uMsg, wParam, lParam);
183
 
184
    return result;
112 ixe013 185
}