Операционная система Microsoft Windows 3.1 для программиста -том 2


Листинг 2.30. Файл combo\combo.cpp - часть 2


aWndClass = RegisterClass(&wc); return (aWndClass != 0); }

// ===================================== // Функция WndProc // =====================================

LRESULT CALLBACK _export WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HWND hComboBox; static HWND hButton;

switch (msg) { case WM_CREATE: { hComboBox = CreateWindow("ComboBox", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_AUTOHSCROLL | CBS_SIMPLE, 30, 30, 200, 200, hwnd, (HMENU) ID_LIST, hInst, NULL);

SendMessage(hComboBox, CB_DIR, DDL_READWRITE | DDL_READONLY | DDL_HIDDEN | DDL_SYSTEM | DDL_DIRECTORY | DDL_DRIVES | DDL_ARCHIVE, (LPARAM)(LPSTR)"*.*");

hButton = CreateWindow("button", "OK", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 250, 30, 50, 20, hwnd, (HMENU) ID_BUTTON, hInst, NULL);

return 0; }

case WM_SETFOCUS: { SetFocus(hComboBox); return 0; }

case WM_COMMAND: { if(wParam == ID_LIST) { if(HIWORD(lParam) == (unsigned)CBN_ERRSPACE) { MessageBox(hwnd, "Мало памяти", szWindowTitle, MB_OK); }

else if(HIWORD(lParam) == CBN_DBLCLK) { SendMessage(hwnd, WM_COMMAND, ID_BUTTON, 0L); return 0; }

else if(HIWORD(lParam) == CBN_SELCHANGE) { int uSelectedItem, nSize; char Buffer[256]; HDC hdc;

uSelectedItem = (int)SendMessage(hComboBox, CB_GETCURSEL, 0, 0L);

if(uSelectedItem != CB_ERR) { // Получаем строку SendMessage(hComboBox, CB_GETLBTEXT, uSelectedItem, (LPARAM)Buffer);

hdc = GetDC(hwnd); nSize = lstrlen(Buffer);

TextOut(hdc, 250, 60, (LPSTR)" ", 25); TextOut(hdc, 250, 60, (LPSTR)Buffer, nSize);

ReleaseDC(hwnd, hdc); } } }

else if(wParam == ID_BUTTON) { int uSelectedItem; char Buffer[256];

uSelectedItem = (int)SendMessage(hComboBox, CB_GETCURSEL, 0, 0L); if(uSelectedItem != LB_ERR) { SendMessage(hComboBox, CB_GETLBTEXT, uSelectedItem, (LPARAM)Buffer); if(Buffer[0] == '[') { Buffer[lstrlen(Buffer) - 1] = '\0'; if(chdir(&Buffer[1]) != 0) { Buffer[3] = '\0'; lstrcat(Buffer, ":\\"); if(chdir(&Buffer[2]) == 0) { AnsiLowerBuff(&Buffer[2], 1); setdisk(Buffer[2] - 'a'); } } SendMessage(hComboBox, CB_RESETCONTENT, 0, 0L); SendMessage(hComboBox, CB_DIR, DDL_READWRITE | DDL_READONLY | DDL_HIDDEN | DDL_SYSTEM | DDL_DIRECTORY | DDL_DRIVES | DDL_ARCHIVE, (LPARAM)(LPSTR)"*.*"); } else { MessageBox(hwnd, Buffer, szWindowTitle, MB_OK); } } } return 0; }

case WM_PAINT: { HDC hdc; PAINTSTRUCT ps;

hdc = BeginPaint(hwnd, &ps); TextOut(hdc, 30, 10, "Выберите файл, каталог или диск", 31); EndPaint(hwnd, &ps); return 0; }

case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hwnd, msg, wParam, lParam); }

Файл определения модуля приложения COMBO приведен в листинге 2.31.




Начало  Назад  Вперед