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
| LRESULT CALLBACK ParameterWnd::myProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
ParameterWnd* my_data;
WCHAR wcTemp[STRING_MAXIMAL_SIZE];
RECT windowRect;
std::string TempString;
my_data = (ParameterWnd*)GetWindowLong(hwnd,0);
switch(msg)
{
// Allocate a new CustCtrl class for this window.
case WM_CREATE:
{
CREATESTRUCT* stCreate = (CREATESTRUCT*)lParam;
stParameterDiagKv* receivedParam;
WCHAR buttonClass[50] = {0};
WCHAR editClass[50] = {0};
unsigned long buttonStyle = 0L;
unsigned long editStyle = 0L;
int numberWidth = 30;
//affects the datas to myself
my_data = new ParameterWnd(hwnd);
SetWindowLong(hwnd,0,(LONG)my_data);
//Get parameter datas
receivedParam = (stParameterDiagKv*)stCreate->lpCreateParams;
my_data->my_parameter.id = receivedParam->id;
my_data->my_parameter.ecuValue = receivedParam->ecuValue;
my_data->my_parameter.wishedValue = receivedParam->wishedValue;
if(my_data->my_parameter.id != -1)
{
swprintf_s(buttonClass, STRING_MAXIMAL_SIZE, L"%s", INFOBUTTON_CLASSNAME);
buttonStyle = WS_CHILD | WS_VISIBLE;
swprintf_s(editClass, STRING_MAXIMAL_SIZE, L"%s", L"EDIT");
// editStyle = WS_CHILD |WS_VISIBLE|WS_BORDER|ES_NUMBER;
editStyle = WS_CHILD |WS_VISIBLE|WS_BORDER;
}
else
{
swprintf_s(buttonClass, STRING_MAXIMAL_SIZE, L"%s", L"BUTTON");
buttonStyle = WS_CHILD | WS_VISIBLE;
swprintf_s(editClass, STRING_MAXIMAL_SIZE, L"%s", L"BUTTON");
editStyle = WS_CHILD | WS_VISIBLE;
}
//create all buttons that will show the parameter datas
GetClientRect(hwnd, &windowRect);
// Ici, on crée les autres boutons...
// Le code est supprimé
// Là, on crée le bouton sous la forme d'une editbox
if(my_data->my_parameter.id != -1)
{
_ultow(my_data->my_parameter.wishedValue,wcTemp,10);
}
else
{
swprintf_s(wcTemp, STRING_MAXIMAL_SIZE, L"%s", L"Value");
}
//Calculate edit box size depending on systeme we are on
int editboxPosX;
int editboxWidthX;
editboxPosX = windowRect.left + 6*(windowRect.right - windowRect.left)/8+ numberWidth;
editboxWidthX = (windowRect.right - windowRect.left)/8;
my_data->hValue = CreateWindow( editClass, wcTemp,
editStyle,
editboxPosX,
windowRect.top,
editboxWidthX,
windowRect.bottom - windowRect.top,
hwnd,
(HMENU)ID_EDIT_BOX, // C'est ici que le menu de l'edit box est créé....
stCreate->hInstance,
NULL);
}
return (my_data != NULL);
case WM_KEYDOWN:
switch(wParam)
{
case VK_RETURN:
MessageBox(NULL, L"Return pressed",L"Info", MB_OK);
break;
case VK_NEXT:
MessageBox(NULL, L"Page down pressed",L"Info", MB_OK);
break;
case VK_PRIOR:
MessageBox(NULL, L"Page up pressed",L"Info", MB_OK);
break;
}
break;
case WM_COMMAND:
{
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch(wmId)
{
case ID_EDIT_BOX:
if((my_data->my_parameter.id != -1) &&
((wmEvent == EN_UPDATE) || (wmEvent == EN_CHANGE) || (wmEvent > EN_SETFOCUS) ))
{
wcTemp[0] = 50;
if(SendMessage(my_data->hValue, EM_GETLINE, 0, (LPARAM)wcTemp) == 0)
{
// The string is empty
return 0;
}
//convert received string into integer and send it over CAN
my_data->my_parameter.wishedValue = _wtoi(wcTemp);
//analyse entered value
// my_data->my_parameter.wishedValue = my_data->my_parameter.wishedValue - (my_data->my_parameter.wishedValue%my_data->my_parameter.step);
// my_data->my_parameter.wishedValue = max(my_data->my_parameter.wishedValue, my_data->my_parameter.minValue);
// my_data->my_parameter.wishedValue = min(my_data->my_parameter.wishedValue, my_data->my_parameter.maxValue);
my_data->my_parameter.wishedValue = CheckValue(my_data->my_parameter.wishedValue, my_data->my_parameter.type, my_data->my_parameter.step);
DiagKv_ChangeWishedValue(&my_data->my_parameter);
if(my_data->my_parameter.ecuValue != my_data->my_parameter.wishedValue)
{
//Change button with "set" message
swprintf_s(wcTemp, L"%s", L"SET");
SendMessage(my_data->hValidate, WM_SETTEXT, 0, (LPARAM)wcTemp);
}
else
{
//Change button with "set" message
swprintf_s(wcTemp, L"%s", L"OK");
SendMessage(my_data->hValidate, WM_SETTEXT, 0, (LPARAM)wcTemp);
}
}
break;
}
}
break;
case WM_QUIT:
UnhookWindowsHookEx(hookClavier);
MessageBox(0, L"Fin", L"",0x10);
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
} |
Partager