--- np2/win9x/dialog/d_serial.cpp 2003/11/03 00:49:55 1.8 +++ np2/win9x/dialog/d_serial.cpp 2005/02/07 14:46:15 1.11 @@ -9,10 +9,10 @@ #include "np2class.h" #include "dialog.h" #include "dialogs.h" -#include "bit2res.h" #include "pccore.h" #include "iocore.h" #include "pc9861k.h" +#include "dipswbmp.h" static const char str_none[] = "NONE"; @@ -351,22 +351,21 @@ static const PC9861MODE_T pc9861mode[2] {IDC_CH2SPEED, IDC_CH2INT, IDC_CH2MODE, &pc9861_s[2], &pc9861_s[1], 2}}; - -#define PC9861S1_X 1 -#define PC9861S2_X 10 -#define PC9861S3_X 17 -#define PC9861S_Y 1 - -#define PC9861J1_X 1 -#define PC9861J2_X 9 -#define PC9861J3_X 17 -#define PC9861J4_X 1 -#define PC9861J5_X 11 -#define PC9861J6_X 19 -#define PC9861J1_Y 4 -#define PC9861J4_Y 7 - -static SUBCLASSPROC oldidc_9861dip = NULL; +enum { + PC9861S1_X = 1, + PC9861S2_X = 10, + PC9861S3_X = 17, + PC9861S_Y = 1, + + PC9861J1_X = 1, + PC9861J2_X = 9, + PC9861J3_X = 17, + PC9861J4_X = 1, + PC9861J5_X = 11, + PC9861J6_X = 19, + PC9861J1_Y = 4, + PC9861J4_Y = 7 +}; static const UINT32 pc9861kint1[] = {0, 1, 2, 3}; static const UINT32 pc9861kint2[] = {0, 4, 5, 6}; @@ -381,34 +380,6 @@ static const UINT pc9861d2sync[] = {1, 2 static const UINT pc9861d2int[] = {0, 2, 1, 3}; -static void setdip(BYTE *image, int px, int py, int align, BYTE v, BYTE c) { - - int i, y; - - px *= 9; - px++; - py *= 9; - while(c--) { - y = py + ((v&0x01)?5:9); - for (i=0; i<3; i++) { - dlgs_linex(image, px, y+i, 7, align, 0); - } - px+=9; - v>>=1; - } -} - -static void setjmp(BYTE *image, int px, int py, int align, BYTE v, BYTE c) { - - while(c--) { - if (v & 0x01) { - dlgs_setjumpery(image, px, py, align); - } - px++; - v >>= 1; - } -} - static void pc9861getspeed(HWND hWnd, const PC9861MODE_T *m) { LRESULT r; @@ -418,8 +389,8 @@ static void pc9861getspeed(HWND hWnd, co r = SendDlgItemMessage(hWnd, m->idc_speed, CB_GETCURSEL, 0, 0); if (r != CB_ERR) { DWORD speed = r; - if (speed > ((sizeof(pc9861k_speed) / sizeof(UINT32)) - 1)) { - speed = (sizeof(pc9861k_speed) / sizeof(UINT32)) - 1; + if (speed > (NELEMENTS(pc9861k_speed) - 1)) { + speed = NELEMENTS(pc9861k_speed) - 1; } if (mode & 2) { speed += 3; @@ -452,7 +423,6 @@ static void pc9861getint(HWND hWnd, cons } } - static void pc9861getmode(HWND hWnd, const PC9861MODE_T *m) { LRESULT r; @@ -487,8 +457,8 @@ static void pc9861setmode(HWND hWnd, con speed = 0; } } - if (speed > ((sizeof(pc9861k_speed) / sizeof(UINT32)) - 1)) { - speed = (sizeof(pc9861k_speed) / sizeof(UINT32)) - 1; + if (speed > (NELEMENTS(pc9861k_speed) - 1)) { + speed = NELEMENTS(pc9861k_speed) - 1; } SendDlgItemMessage(hWnd, m->idc_speed, @@ -503,69 +473,67 @@ static void pc9861setmode(HWND hWnd, con CB_SETCURSEL, (WPARAM)intnum, (LPARAM)0); } +static void pc9861cmddipsw(HWND hWnd) { -static LRESULT CALLBACK pc9861d(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { + RECT rect1; + RECT rect2; + POINT p; + BYTE bit; - PAINTSTRUCT ps; - HDC hdc; - HBITMAP hBitmap; - HDC hMemDC; - BYTE *image; - HANDLE hwork; - BITMAPINFO *work; - BYTE *imgbtm; - int align; - - switch(msg) { - case WM_PAINT: - hdc = BeginPaint(hWnd, &ps); - if ((hwork = GlobalAlloc(GPTR, bit2res_getsize(&pc9861dip))) - == NULL) { - break; - } - if ((work = (BITMAPINFO *)GlobalLock(hwork)) == NULL) { - GlobalFree(hwork); - break; + GetWindowRect(GetDlgItem(hWnd, IDC_PC9861DIP), &rect1); + GetClientRect(GetDlgItem(hWnd, IDC_PC9861DIP), &rect2); + GetCursorPos(&p); + p.x += rect2.left - rect1.left; + p.y += rect2.top - rect1.top; + p.x /= 9; + p.y /= 9; + if ((p.y >= 1) && (p.y < 3)) { // 1段目 + if ((p.x >= 1) && (p.x < 7)) { // S1 + pc9861_s[0] ^= (1 << (p.x - 1)); + pc9861setmode(hWnd, pc9861mode); + } + else if ((p.x >= 10) && (p.x < 14)) { // S2 + pc9861_s[1] ^= (1 << (p.x - 10)); + pc9861setmode(hWnd, pc9861mode); + pc9861setmode(hWnd, pc9861mode+1); + } + else if ((p.x >= 17) && (p.x < 23)) { // S3 + pc9861_s[2] ^= (1 << (p.x - 17)); + pc9861setmode(hWnd, pc9861mode+1); + } + } + else if ((p.y >= 4) && (p.y < 6)) { // 2段目 + if ((p.x >= 1) && (p.x < 7)) { // J1 + pc9861_j[0] ^= (1 << (p.x - 1)); + } + else if ((p.x >= 9) && (p.x < 15)) { // J2 + pc9861_j[1] ^= (1 << (p.x - 9)); + } + else if ((p.x >= 17) && (p.x < 19)) { // J3 + pc9861_j[2] = (1 << (p.x - 17)); + } + } + else if ((p.y >= 7) && (p.y < 9)) { // 3段目 + if ((p.x >= 1) && (p.x < 9)) { // J4 + bit = (1 << (p.x - 1)); + if (pc9861_j[3] == bit) { + bit = 0; } - bit2res_sethead(work, &pc9861dip); - hBitmap = CreateDIBSection(hdc, work, DIB_RGB_COLORS, - (void **)&image, NULL, 0); - bit2res_setdata(image, &pc9861dip); - align = ((pc9861dip.x + 7) / 2) & ~3; - imgbtm = image + align * (pc9861dip.y - 1); - setdip(imgbtm, PC9861S1_X, PC9861S_Y, align, pc9861_s[0], 6); - setdip(imgbtm, PC9861S2_X, PC9861S_Y, align, pc9861_s[1], 4); - setdip(imgbtm, PC9861S3_X, PC9861S_Y, align, pc9861_s[2], 6); - setjmp(imgbtm, PC9861J1_X, PC9861J1_Y, align, pc9861_j[0], 6); - setjmp(imgbtm, PC9861J2_X, PC9861J1_Y, align, pc9861_j[1], 6); - setjmp(imgbtm, PC9861J3_X, PC9861J1_Y, align, pc9861_j[2], 2); - setjmp(imgbtm, PC9861J4_X, PC9861J4_Y, align, pc9861_j[3], 8); - setjmp(imgbtm, PC9861J5_X, PC9861J4_Y, align, pc9861_j[4], 6); - setjmp(imgbtm, PC9861J6_X, PC9861J4_Y, align, pc9861_j[5], 6); - if ((hMemDC = CreateCompatibleDC(hdc)) != NULL) { - SelectObject(hMemDC, hBitmap); - StretchBlt(hdc, 0, 0, pc9861dip.x, pc9861dip.y, hMemDC, - 0, 0, pc9861dip.x, pc9861dip.y, SRCCOPY); - DeleteDC(hMemDC); - } - DeleteObject(hBitmap); - EndPaint(hWnd, &ps); - GlobalUnlock(hwork); - GlobalFree(hwork); - break; - default: - return(CallWindowProc(oldidc_9861dip, hWnd, msg, wp, lp)); + pc9861_j[3] = bit; + } + else if ((p.x >= 11) && (p.x < 17)) { // J5 + pc9861_j[4] ^= (1 << (p.x - 11)); + } + else if ((p.x >= 19) && (p.x < 25)) { // J6 + pc9861_j[5] ^= (1 << (p.x - 19)); + } } - return(FALSE); } - static LRESULT CALLBACK pc9861mainProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { - RECT rect1; - RECT rect2; - POINT p; + HWND sub; BYTE r; UINT update; @@ -585,10 +553,9 @@ static LRESULT CALLBACK pc9861mainProc(H pc9861setmode(hWnd, pc9861mode); pc9861setmode(hWnd, pc9861mode+1); - oldidc_9861dip = (SUBCLASSPROC)GetWindowLong(GetDlgItem(hWnd, - IDC_PC9861DIP), GWL_WNDPROC); - SetWindowLong(GetDlgItem(hWnd, IDC_PC9861DIP), GWL_WNDPROC, - (LONG)pc9861d); + sub = GetDlgItem(hWnd, IDC_PC9861DIP); + SetWindowLong(sub, GWL_STYLE, SS_OWNERDRAW + + (GetWindowLong(sub, GWL_STYLE) & (~SS_TYPEMASK))); return(TRUE); case WM_COMMAND: @@ -624,64 +591,8 @@ static LRESULT CALLBACK pc9861mainProc(H break; case IDC_PC9861DIP: - GetWindowRect(GetDlgItem(hWnd, IDC_PC9861DIP), &rect1); - GetClientRect(GetDlgItem(hWnd, IDC_PC9861DIP), &rect2); - GetCursorPos(&p); - p.x += rect2.left - rect1.left; - p.y += rect2.top - rect1.top; - p.x /= 9; - p.y /= 9; - if ((p.y >= 1) && (p.y < 3)) { // 1段目 - if ((p.x >= 1) && (p.x < 7)) { // S1 - pc9861_s[0] ^= (1 << (p.x - 1)); - pc9861setmode(hWnd, pc9861mode); - break; - } - else if ((p.x >= 10) && (p.x < 14)) { // S2 - pc9861_s[1] ^= (1 << (p.x - 10)); - pc9861setmode(hWnd, pc9861mode); - pc9861setmode(hWnd, pc9861mode+1); - break; - } - else if ((p.x >= 17) && (p.x < 23)) { // S3 - pc9861_s[2] ^= (1 << (p.x - 17)); - pc9861setmode(hWnd, pc9861mode+1); - break; - } - } - else if ((p.y >= 4) && (p.y < 6)) { // 2段目 - if ((p.x >= 1) && (p.x < 7)) { // J1 - pc9861_j[0] ^= (1 << (p.x - 1)); - break; - } - else if ((p.x >= 9) && (p.x < 15)) { // J2 - pc9861_j[1] ^= (1 << (p.x - 9)); - break; - } - else if ((p.x >= 17) && (p.x < 19)) { // J3 - pc9861_j[2] = (1 << (p.x - 17)); - break; - } - } - else if ((p.y >= 7) && (p.y < 9)) { // 3段目 - if ((p.x >= 1) && (p.x < 9)) { // J4 - BYTE bit = (1 << (p.x - 1)); - if (pc9861_j[3] == bit) { - bit = 0; - } - pc9861_j[3] = bit; - break; - } - else if ((p.x >= 11) && (p.x < 17)) { // J5 - pc9861_j[4] ^= (1 << (p.x - 11)); - break; - } - else if ((p.x >= 19) && (p.x < 25)) { // J6 - pc9861_j[5] ^= (1 << (p.x - 19)); - break; - } - } - return(FALSE); + pc9861cmddipsw(hWnd); + break; default: return(FALSE); @@ -709,6 +620,13 @@ static LRESULT CALLBACK pc9861mainProc(H return(TRUE); } break; + + case WM_DRAWITEM: + if (LOWORD(wp) == IDC_PC9861DIP) { + dlgs_drawbmp(((LPDRAWITEMSTRUCT)lp)->hDC, + dipswbmp_get9861(pc9861_s, pc9861_j)); + } + return(FALSE); } return(FALSE); }