int CFeedIcoItemListCtrl::GetGroupCount() { int groupCount = 0; if (thePrefs.GetWindowsVersion() >= _WINVER_VISTA_ ) { groupCount = SNDMSG((m_hWnd), LVM_GETGROUPCOUNT, (WPARAM)0, (LPARAM)0); } else { CFeedCatalogs & feedCatalogs = CFeedCatalogs::GetInstance(); for ( CFeedCatalogs::iterator it = feedCatalogs.GetBegin(); it != feedCatalogs.GetEnd(); ++it ) { FeedCatalog & feedCatlog = it->second; if ( feedCatlog.IsTop() && feedCatlog.GetFeedCount() > 0 ) { groupCount++; } } } return groupCount; }
int snd_pcm_channel_info_shm(snd_pcm_t *pcm, snd_pcm_channel_info_t *info, int shmid) { switch (pcm->access) { case SND_PCM_ACCESS_MMAP_INTERLEAVED: case SND_PCM_ACCESS_RW_INTERLEAVED: info->first = info->channel * pcm->sample_bits; info->step = pcm->frame_bits; break; case SND_PCM_ACCESS_MMAP_NONINTERLEAVED: case SND_PCM_ACCESS_RW_NONINTERLEAVED: info->first = 0; info->step = pcm->sample_bits; break; default: SNDMSG("invalid access type %d", pcm->access); return -EINVAL; } info->addr = 0; if (pcm->hw_flags & SND_PCM_HW_PARAMS_EXPORT_BUFFER) { info->type = SND_PCM_AREA_SHM; info->u.shm.shmid = shmid; info->u.shm.area = NULL; } else info->type = SND_PCM_AREA_LOCAL; return 0; }
static snd_pcm_sframes_t snd_pcm_mmap_write_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas, snd_pcm_uframes_t offset, snd_pcm_uframes_t size) { snd_pcm_uframes_t xfer = 0; if (snd_pcm_mmap_playback_avail(pcm) < size) { SNDMSG("too short avail %ld to size %ld", snd_pcm_mmap_playback_avail(pcm), size); return -EPIPE; } while (size > 0) { const snd_pcm_channel_area_t *pcm_areas; snd_pcm_uframes_t pcm_offset; snd_pcm_uframes_t frames = size; snd_pcm_sframes_t result; snd_pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames); snd_pcm_areas_copy(pcm_areas, pcm_offset, areas, offset, pcm->channels, frames, pcm->format); result = snd_pcm_mmap_commit(pcm, pcm_offset, frames); if (result < 0) return xfer > 0 ? (snd_pcm_sframes_t)xfer : result; offset += result; xfer += result; size -= result; } return (snd_pcm_sframes_t)xfer; }
LVGROUP CFeedIcoItemListCtrl::GetGroupInfoByIndex(int iGroupId, UINT mask) { LVGROUP lg = {0}; lg.cbSize = sizeof(lg); lg.mask = mask;//这里只需要ID VERIFY( SNDMSG((m_hWnd), LVM_GETGROUPINFOBYINDEX, (WPARAM)(iGroupId), (LPARAM)(&lg)) ); return lg; }
/* called in pcm lock */ snd_pcm_sframes_t snd_pcm_read_mmap(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size) { snd_pcm_uframes_t xfer = 0; snd_pcm_sframes_t err = 0; if (! size) return 0; while (xfer < size) { snd_pcm_uframes_t frames = size - xfer; snd_pcm_uframes_t cont = pcm->buffer_size - offset; if (cont < frames) frames = cont; switch (pcm->access) { case SND_PCM_ACCESS_MMAP_INTERLEAVED: { const snd_pcm_channel_area_t *a = snd_pcm_mmap_areas(pcm); char *buf = snd_pcm_channel_area_addr(a, offset); snd_pcm_unlock(pcm); /* to avoid deadlock */ err = _snd_pcm_readi(pcm, buf, frames); snd_pcm_lock(pcm); if (err >= 0) frames = err; break; } case SND_PCM_ACCESS_MMAP_NONINTERLEAVED: { snd_pcm_uframes_t channels = pcm->channels; unsigned int c; void *bufs[channels]; const snd_pcm_channel_area_t *areas = snd_pcm_mmap_areas(pcm); for (c = 0; c < channels; ++c) { const snd_pcm_channel_area_t *a = &areas[c]; bufs[c] = snd_pcm_channel_area_addr(a, offset); } snd_pcm_unlock(pcm); /* to avoid deadlock */ err = _snd_pcm_readn(pcm->fast_op_arg, bufs, frames); snd_pcm_lock(pcm); if (err >= 0) frames = err; break; } default: SNDMSG("invalid access type %d", pcm->access); return -EINVAL; } if (err < 0) break; xfer += frames; offset = (offset + frames) % pcm->buffer_size; } if (xfer > 0) return xfer; return err; }
CRect CFeedIcoItemListCtrl::GetRectbyGroupID(int nGroupID, UINT mask) { if (nGroupID >= GetGroupCount() || nGroupID < 0) { return CRect(0,0,0,0); } CRect rect(0,mask,0,0); VERIFY( SNDMSG((m_hWnd), LVM_GETGROUPRECT, (WPARAM)(nGroupID), (LPARAM)(RECT*)(&rect)) ); return rect; }
/** * name: ProfileList_GetItemText * desc: returns the text of a listview item * param: hList - handle to listview control * iItem - item index * iSubItem - subitem (column) index * pszText - pointer of a buffer to retrieve the text * ccText - number of maximal characters pszText can take * return: number of read characters **/ static INT ProfileList_GetItemText(HWND hList, INT iItem, INT iSubItem, LPTSTR pszText, INT ccText) { LVITEM lvi; TCHAR szNull[2]; lvi.mask = LVIF_TEXT; lvi.iItem = iItem; lvi.iSubItem = iSubItem; lvi.cchTextMax = ccText ? ccText : 2; lvi.pszText = pszText ? pszText : szNull; return SNDMSG(hList, LVM_GETITEMTEXT, iItem, (LPARAM)&lvi); }
static int snd_ctl_hw_read(snd_ctl_t *handle, snd_ctl_event_t *event) { snd_ctl_hw_t *hw = handle->private_data; ssize_t res = read(hw->fd, event, sizeof(*event)); if (res <= 0) return -errno; if (CHECK_SANITY(res != sizeof(*event))) { SNDMSG("snd_ctl_hw_read: read size error (req:%d, got:%d)\n", sizeof(*event), res); return -EINVAL; } return 1; }
/** * \brief Wait for a HCTL to become ready (i.e. at least one event pending) * \param hctl HCTL handle * \param timeout maximum time in milliseconds to wait * \return a positive value on success otherwise a negative error code * \retval 0 timeout occurred * \retval 1 an event is pending */ int snd_hctl_wait(snd_hctl_t *hctl, int timeout) { struct pollfd *pfd; unsigned short *revents; int i, npfds, pollio, err, err_poll; npfds = snd_hctl_poll_descriptors_count(hctl); if (npfds <= 0 || npfds >= 16) { SNDERR("Invalid poll_fds %d\n", npfds); return -EIO; } pfd = alloca(sizeof(*pfd) * npfds); revents = alloca(sizeof(*revents) * npfds); err = snd_hctl_poll_descriptors(hctl, pfd, npfds); if (err < 0) return err; if (err != npfds) { SNDMSG("invalid poll descriptors %d\n", err); return -EIO; } do { pollio = 0; err_poll = poll(pfd, npfds, timeout); if (err_poll < 0) { if (errno == EINTR) continue; return -errno; } if (! err_poll) break; err = snd_hctl_poll_descriptors_revents(hctl, pfd, npfds, revents); if (err < 0) return err; for (i = 0; i < npfds; i++) { if (revents[i] & (POLLERR | POLLNVAL)) return -EIO; if ((revents[i] & (POLLIN | POLLOUT)) == 0) continue; pollio++; } } while (! pollio); return err_poll > 0 ? 1 : 0; }
//--------------------------------------------------------------------------- void __fastcall TPlayerAreaForm::PasLibVlcPlayer1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(Button == mbLeft) { ReleaseCapture(); SNDMSG(Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); MainForm->PlayerAreaFrames[Tag]->XSpinEdit->OnChange = 0; MainForm->PlayerAreaFrames[Tag]->YSpinEdit->OnChange = 0; MainForm->PageControl1->ActivePageIndex = Tag; int m = MainForm->PlayerAreaFrames[Tag]->MonitorComboBox->ItemIndex; MainForm->PlayerAreaFrames[Tag]->XSpinEdit->Value = Left - Screen->Monitors[m]->Left; MainForm->PlayerAreaFrames[Tag]->YSpinEdit->Value = Top - Screen->Monitors[m]->Top; MainForm->PlayerAreaFrames[Tag]->XSpinEdit->OnChange = MainForm->PlayerAreaFrames[Tag]->OnPlayerAreaChange; MainForm->PlayerAreaFrames[Tag]->YSpinEdit->OnChange = MainForm->PlayerAreaFrames[Tag]->OnPlayerAreaChange; } }
int snd_pcm_munmap(snd_pcm_t *pcm) { int err; unsigned int c; assert(pcm); if (CHECK_SANITY(! pcm->mmap_channels)) { SNDMSG("Not mmapped"); return -ENXIO; } if (pcm->mmap_shadow) return pcm->ops->munmap(pcm); for (c = 0; c < pcm->channels; ++c) { snd_pcm_channel_info_t *i = &pcm->mmap_channels[c]; unsigned int c1; size_t size = i->first + i->step * (pcm->buffer_size - 1) + pcm->sample_bits; if (!i->addr) continue; for (c1 = c + 1; c1 < pcm->channels; ++c1) { snd_pcm_channel_info_t *i1 = &pcm->mmap_channels[c1]; size_t s; if (i1->addr != i->addr) continue; i1->addr = NULL; s = i1->first + i1->step * (pcm->buffer_size - 1) + pcm->sample_bits; if (s > size) size = s; } size = (size + 7) / 8; size = page_align(size); switch (i->type) { case SND_PCM_AREA_MMAP: err = munmap(i->addr, size); if (err < 0) { SYSERR("mmap failed"); return -errno; } errno = 0; break; case SND_PCM_AREA_SHM: if (i->u.shm.area) { snd_shm_area_destroy(i->u.shm.area); i->u.shm.area = NULL; if (pcm->access == SND_PCM_ACCESS_MMAP_INTERLEAVED || pcm->access == SND_PCM_ACCESS_RW_INTERLEAVED) { unsigned int c1; for (c1 = c + 1; c1 < pcm->channels; c1++) { snd_pcm_channel_info_t *i1 = &pcm->mmap_channels[c1]; if (i1->u.shm.area) { snd_shm_area_destroy(i1->u.shm.area); i1->u.shm.area = NULL; } } } } break; case SND_PCM_AREA_LOCAL: free(i->addr); break; default: assert(0); } i->addr = NULL; } err = pcm->ops->munmap(pcm); if (err < 0) return err; free(pcm->mmap_channels); free(pcm->running_areas); pcm->mmap_channels = NULL; pcm->running_areas = NULL; return 0; }
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: { INITCOMMONCONTROLSEX icx; icx.dwSize = sizeof(INITCOMMONCONTROLSEX); icx.dwICC = ICC_BAR_CLASSES; InitCommonControlsEx(&icx); hTrackBar = CreateWindow( TRACKBAR_CLASS, "", TBS_HORZ | TBS_BOTH | TBS_AUTOTICKS | TBS_FIXEDLENGTH | TBS_ENABLESELRANGE | WS_CHILD | WS_VISIBLE, 10, 260, 375, 40, hWnd, NULL, hInst, NULL ); assert(hTrackBar != NULL); SNDMSG(hTrackBar, TBM_SETTHUMBLENGTH, 20, 0); SNDMSG(hTrackBar, TBM_SETRANGEMAX, TRUE, 100); // create the TrueType (scalable) font HDC hDC = GetDC(hWnd); try { // see Chapter 4 for the definition of MakeFont hTTFont = font::MakeFont(hDC, "Impact", 72); if (!hTTFont) throw; } catch (...) { ReleaseDC(hWnd, hDC); } ReleaseDC(hWnd, hDC); break; } case WM_HSCROLL: { if (reinterpret_cast<HWND>(lParam) == hTrackBar) { // // adjust the scaling factor according to // the position of the trackbar's slider // scale = static_cast<double>( (SNDMSG(hTrackBar, TBM_GETPOS, 0, 0) + 1) / 50.0 ); InvalidateRect(hWnd, NULL, true); } break; } case WM_ERASEBKGND: { LRESULT res = DefWindowProc(hWnd, msg, wParam, lParam); HDC hDC = reinterpret_cast<HDC>(wParam); HFONT hOldFont = static_cast<HFONT>( SelectObject(hDC, hTTFont) ); try { SetBkMode(hDC, TRANSPARENT); // open a path bracket if (!BeginPath(hDC)) throw; // record the text to the path TextOut(hDC, 10, 10, pText, lstrlen(pText)); // close the path bracket and // select the path into hDC EndPath(hDC); // determine the number of endpoints in the path const int num_points = GetPath(hDC, NULL, NULL, 0); if (num_points > 0) { // make room for the POINTs and vertex types POINT* pPEnds = new POINT[num_points]; unsigned char* pTypes = new unsigned char[num_points]; try { // get the path's description int num_got = GetPath(hDC, pPEnds, pTypes, num_points); if (num_got > 0) { // start a new path bracket if (!BeginPath(hDC)) throw; // scale each point in the description int iPoint; for (iPoint = 0; iPoint < num_got; ++iPoint) { pPEnds[iPoint].x = static_cast<LONG>( scale * pPEnds[iPoint].x + 0.5 ); pPEnds[iPoint].y = static_cast<LONG>( scale * pPEnds[iPoint].y + 0.5 ); } for (iPoint = 0; iPoint < num_points; ++iPoint) { // handle the MoveToEx case if (pTypes[iPoint] == PT_MOVETO) { MoveToEx( hDC, pPEnds[iPoint].x, pPEnds[iPoint].y, NULL ); } // handle the LineTo case else if ( pTypes[iPoint] == PT_LINETO || pTypes[iPoint] == (PT_LINETO | PT_CLOSEFIGURE) ) { LineTo(hDC, pPEnds[iPoint].x, pPEnds[iPoint].y); } // handle the PolyBezierTo case else if ( pTypes[iPoint] == PT_BEZIERTO || pTypes[iPoint] == (PT_BEZIERTO | PT_CLOSEFIGURE) ) { PolyBezierTo(hDC, pPEnds + iPoint, 3); iPoint += 2; } } // close the new path bracket EndPath(hDC); // stroke and fill the new path StrokeAndFillPath(hDC); } } catch (...) { // clean up delete [] pTypes; delete [] pPEnds; throw; } // clean up delete [] pTypes; delete [] pPEnds; } // ... } catch (...) { SelectObject(hDC, hOldFont); } SelectObject(hDC, hOldFont); return res; } case WM_SIZE: { MoveWindow( hTrackBar, 0, HIWORD(lParam) - 40, LOWORD(lParam), 40, false ); break; } case WM_DESTROY: { // clean up DeleteObject(hTTFont); PostQuitMessage(0); break; } } return DefWindowProc(hWnd, msg, wParam, lParam); }
int snd_pcm_mmap(snd_pcm_t *pcm) { int err; unsigned int c; assert(pcm); if (CHECK_SANITY(! pcm->setup)) { SNDMSG("PCM not set up"); return -EIO; } if (CHECK_SANITY(pcm->mmap_channels || pcm->running_areas)) { SNDMSG("Already mmapped"); return -EBUSY; } err = pcm->ops->mmap(pcm); if (err < 0) return err; if (pcm->mmap_shadow) return 0; pcm->mmap_channels = calloc(pcm->channels, sizeof(pcm->mmap_channels[0])); if (!pcm->mmap_channels) return -ENOMEM; pcm->running_areas = calloc(pcm->channels, sizeof(pcm->running_areas[0])); if (!pcm->running_areas) { free(pcm->mmap_channels); pcm->mmap_channels = NULL; return -ENOMEM; } for (c = 0; c < pcm->channels; ++c) { snd_pcm_channel_info_t *i = &pcm->mmap_channels[c]; i->channel = c; err = snd_pcm_channel_info(pcm, i); if (err < 0) return err; } for (c = 0; c < pcm->channels; ++c) { snd_pcm_channel_info_t *i = &pcm->mmap_channels[c]; snd_pcm_channel_area_t *a = &pcm->running_areas[c]; char *ptr; size_t size; unsigned int c1; if (i->addr) { a->addr = i->addr; a->first = i->first; a->step = i->step; continue; } size = i->first + i->step * (pcm->buffer_size - 1) + pcm->sample_bits; for (c1 = c + 1; c1 < pcm->channels; ++c1) { snd_pcm_channel_info_t *i1 = &pcm->mmap_channels[c1]; size_t s; if (i1->type != i->type) continue; switch (i1->type) { case SND_PCM_AREA_MMAP: if (i1->u.mmap.fd != i->u.mmap.fd || i1->u.mmap.offset != i->u.mmap.offset) continue; break; case SND_PCM_AREA_SHM: if (i1->u.shm.shmid != i->u.shm.shmid) continue; break; case SND_PCM_AREA_LOCAL: break; default: assert(0); } s = i1->first + i1->step * (pcm->buffer_size - 1) + pcm->sample_bits; if (s > size) size = s; } size = (size + 7) / 8; size = page_align(size); switch (i->type) { case SND_PCM_AREA_MMAP: ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, i->u.mmap.fd, i->u.mmap.offset); if (ptr == MAP_FAILED) { SYSERR("mmap failed"); return -errno; } i->addr = ptr; break; case SND_PCM_AREA_SHM: if (i->u.shm.shmid < 0) { int id; /* FIXME: safer permission? */ id = shmget(IPC_PRIVATE, size, 0666); if (id < 0) { SYSERR("shmget failed"); return -errno; } i->u.shm.shmid = id; ptr = shmat(i->u.shm.shmid, 0, 0); if (ptr == (void *) -1) { SYSERR("shmat failed"); return -errno; } /* automatically remove segment if not used */ if (shmctl(id, IPC_RMID, NULL) < 0){ SYSERR("shmctl mark remove failed"); return -errno; } i->u.shm.area = snd_shm_area_create(id, ptr); if (i->u.shm.area == NULL) { SYSERR("snd_shm_area_create failed"); return -ENOMEM; } if (pcm->access == SND_PCM_ACCESS_MMAP_INTERLEAVED || pcm->access == SND_PCM_ACCESS_RW_INTERLEAVED) { unsigned int c1; for (c1 = c + 1; c1 < pcm->channels; c1++) { snd_pcm_channel_info_t *i1 = &pcm->mmap_channels[c1]; if (i1->u.shm.shmid < 0) { i1->u.shm.shmid = id; i1->u.shm.area = snd_shm_area_share(i->u.shm.area); } } } } else { ptr = shmat(i->u.shm.shmid, 0, 0); if (ptr == (void*) -1) { SYSERR("shmat failed"); return -errno; } } i->addr = ptr; break; case SND_PCM_AREA_LOCAL: ptr = malloc(size); if (ptr == NULL) { SYSERR("malloc failed"); return -errno; } i->addr = ptr; break; default: assert(0); } for (c1 = c + 1; c1 < pcm->channels; ++c1) { snd_pcm_channel_info_t *i1 = &pcm->mmap_channels[c1]; if (i1->type != i->type) continue; switch (i1->type) { case SND_PCM_AREA_MMAP: if (i1->u.mmap.fd != i->u.mmap.fd || i1->u.mmap.offset != i->u.mmap.offset) continue; break; case SND_PCM_AREA_SHM: if (i1->u.shm.shmid != i->u.shm.shmid) continue; /* follow thru */ case SND_PCM_AREA_LOCAL: if (pcm->access != SND_PCM_ACCESS_MMAP_INTERLEAVED && pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) continue; break; default: assert(0); } i1->addr = i->addr; } a->addr = i->addr; a->first = i->first; a->step = i->step; } return 0; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HBITMAP hBitmap; static BYTE oldpai = (BYTE)-1; static BYTE oldx; static BYTE oldy; static BYTE autoiti1, autoiti2; static BYTE zansuu; switch (msg) { case WM_COMMAND: switch (LOWORD(wParam)) { case ID_HINT: if (zansuu) { iti2pai[autoiti1] += 72; iti2pai[autoiti2] += 72; InvalidateRect(hWnd, 0, 0); UpdateWindow(hWnd); if2Space(autoiti1, autoiti2, 1); for (int i = 0; i<4; ++i) { if (pai2iti[4 * (iti2pai[autoiti1] - 72) + i] == autoiti1) { pai2iti[4 * (iti2pai[autoiti1] - 72) + i] = 0; } if (pai2iti[4 * (iti2pai[autoiti1] - 72) + i] == autoiti2) { pai2iti[4 * (iti2pai[autoiti1] - 72) + i] = 0; } } iti2pai[autoiti1] = (BYTE)-1; iti2pai[autoiti2] = (BYTE)-1; --zansuu; if (!zansuu){ g_hHook = SetWindowsHookEx( WH_CBT, CBTProc, 0, GetCurrentThreadId() ); MessageBox( hWnd, TEXT("完了。"), TEXT("四川省"), 0); } else if (!GetHint(&autoiti1, &autoiti2)) { zansuu = 0; g_hHook = SetWindowsHookEx( WH_CBT, CBTProc, 0, GetCurrentThreadId() ); MessageBox( hWnd, TEXT("手詰まりです。"), TEXT("四川省"), 0); } } break; case ID_NEWGAME: { int i, j = 0; for (i = 0; i<MAX_KOMASUU; ++i) { if (i<X_NUM || i>X_NUM*(Y_NUM - 1) || i%X_NUM == 0 || i%X_NUM == X_NUM - 1) { iti2pai[i] = (BYTE)-1; continue; } iti2pai[i] = j / 4; pai2iti[j] = i; j++; } for (i = 0; i<MAX_KOMASUU; ++i) { if (i<X_NUM || i>X_NUM*(Y_NUM - 1) || i%X_NUM == 0 || i%X_NUM == X_NUM - 1) continue; do{ j = rand() % MAX_KOMASUU; } while (j<X_NUM || j>X_NUM*(Y_NUM - 1) || j%X_NUM == 0 || j%X_NUM == X_NUM - 1); koukan(i, j); } zansuu = 72; if (!GetHint(&autoiti1, &autoiti2)) { zansuu = 0; g_hHook = SetWindowsHookEx( WH_CBT, CBTProc, 0, GetCurrentThreadId() ); MessageBox( hWnd, TEXT("手詰まりです。"), TEXT("四川省"), 0); } InvalidateRect(hWnd, 0, 0); } break; } break; case WM_LBUTTONDOWN: if (zansuu) { InvalidateRect(hWnd, NULL, 0); UpdateWindow(hWnd); RECT rect; int xPos = GET_X_LPARAM(lParam) / PAI_WIDTH; int yPos = GET_Y_LPARAM(lParam) / PAI_HEIGHT; if (iti2pai[xPos%X_NUM + yPos*X_NUM] == (BYTE)-1) break;//空白をクリックしても何も起こらない if (oldpai == (BYTE)-1) { iti2pai[xPos%X_NUM + yPos*X_NUM] += 72; SetRect( &rect, PAI_WIDTH*xPos, PAI_HEIGHT*yPos, PAI_WIDTH + PAI_WIDTH*xPos, PAI_HEIGHT + PAI_HEIGHT*yPos ); InvalidateRect(hWnd, &rect, 0); oldpai = iti2pai[xPos%X_NUM + yPos*X_NUM]; oldx = xPos; oldy = yPos; } else { if (xPos == oldx&&yPos == oldy)//1番目と同じ座標 { iti2pai[xPos%X_NUM + yPos*X_NUM] -= 72; SetRect( &rect, PAI_WIDTH*xPos, PAI_HEIGHT*yPos, PAI_WIDTH + PAI_WIDTH*xPos, PAI_HEIGHT + PAI_HEIGHT*yPos); InvalidateRect(hWnd, &rect, 0); } else { iti2pai[xPos%X_NUM + yPos*X_NUM] += 72; SetRect( &rect, PAI_WIDTH*xPos, PAI_HEIGHT*yPos, PAI_WIDTH + PAI_WIDTH*xPos, PAI_HEIGHT + PAI_HEIGHT*yPos); InvalidateRect(hWnd, &rect, 0); UpdateWindow(hWnd); if (oldpai == iti2pai[xPos%X_NUM + yPos*X_NUM] && if2Space( xPos%X_NUM + yPos*X_NUM, oldx%X_NUM + oldy*X_NUM, 1)) { BOOL b = FALSE; for (int i = 0; i<4; ++i) { if (pai2iti[4 * (oldpai - 72) + i] == oldx%X_NUM + oldy*X_NUM) { if (!b && (pai2iti[4 * (oldpai - 72) + i] == autoiti1 || pai2iti[4 * (oldpai - 72) + i] == autoiti2)) b = TRUE; pai2iti[4 * (oldpai - 72) + i] = 0; } if (pai2iti[4 * (oldpai - 72) + i] == xPos%X_NUM + yPos*X_NUM) { if (!b && (pai2iti[4 * (oldpai - 72) + i] == autoiti1 || pai2iti[4 * (oldpai - 72) + i] == autoiti2)) b = TRUE; pai2iti[4 * (oldpai - 72) + i] = 0; } } iti2pai[xPos%X_NUM + yPos*X_NUM] = (BYTE)-1; iti2pai[oldx%X_NUM + oldy*X_NUM] = (BYTE)-1; zansuu--; if (!zansuu){ g_hHook = SetWindowsHookEx( WH_CBT, CBTProc, 0, GetCurrentThreadId()); MessageBox( hWnd, TEXT("完了。"), TEXT("四川省"), 0); } else if (b&& !GetHint(&autoiti1, &autoiti2)) { zansuu = 0; g_hHook = SetWindowsHookEx( WH_CBT, CBTProc, 0, GetCurrentThreadId() ); MessageBox( hWnd, TEXT("手詰まりです。"), TEXT("四川省"), 0); } } else { iti2pai[xPos%X_NUM + yPos*X_NUM] -= 72; iti2pai[oldx%X_NUM + oldy*X_NUM] -= 72; SetRect( &rect, PAI_WIDTH*xPos, PAI_HEIGHT*yPos, PAI_WIDTH + PAI_WIDTH*xPos, PAI_HEIGHT + PAI_HEIGHT*yPos); InvalidateRect(hWnd, &rect, 0); SetRect( &rect, PAI_WIDTH*oldx, PAI_HEIGHT*oldy, PAI_WIDTH + PAI_WIDTH*oldx, PAI_HEIGHT + PAI_HEIGHT*oldy); InvalidateRect(hWnd, &rect, 0); } } oldpai = (BYTE)-1; } } break; case WM_TIMER: KillTimer(hWnd, 0x1234); InvalidateRect(hWnd, 0, 0); break; case WM_CREATE: srand(GetTickCount()); hBitmap = LoadBitmap( GetModuleHandle(0), MAKEINTRESOURCE(IDB_BITMAP1)); SNDMSG(hWnd, WM_COMMAND, ID_NEWGAME, 0); break; case WM_ERASEBKGND: return 1; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); HDC hdc_mem = CreateCompatibleDC(hdc); SelectObject(hdc_mem, hBitmap); for (int i = 0; i<MAX_KOMASUU; ++i) { if (iti2pai[i] == (BYTE)-1) { RECT rect; SetRect( &rect, PAI_WIDTH*(i%X_NUM), PAI_HEIGHT*(i / X_NUM), PAI_WIDTH + PAI_WIDTH*(i%X_NUM), PAI_HEIGHT + PAI_HEIGHT*(i / X_NUM)); COLORREF clrPrev = SetBkColor(hdc, RGB(0, 128, 0)); ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0); SetBkColor(hdc, clrPrev); } else { BitBlt( hdc, (i%X_NUM)*PAI_WIDTH, (i / X_NUM)*PAI_HEIGHT, PAI_WIDTH, PAI_HEIGHT, hdc_mem, iti2pai[i] % 72 * PAI_WIDTH, (iti2pai[i]<36) ? 0 : PAI_HEIGHT, SRCCOPY); } } DeleteDC(hdc_mem); EndPaint(hWnd, &ps); } break; case WM_DESTROY: DeleteObject(hBitmap); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0; }
int snd_timer_hw_open(snd_timer_t **handle, const char *name, int dev_class, int dev_sclass, int card, int device, int subdevice, int mode) { int fd, ver, tmode, ret; snd_timer_t *tmr; struct snd_timer_select sel; *handle = NULL; tmode = O_RDONLY; if (mode & SND_TIMER_OPEN_NONBLOCK) tmode |= O_NONBLOCK; fd = snd_open_device(SNDRV_FILE_TIMER, tmode); if (fd < 0) return -errno; if (ioctl(fd, SNDRV_TIMER_IOCTL_PVERSION, &ver) < 0) { ret = -errno; close(fd); return ret; } if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_TIMER_VERSION_MAX)) { close(fd); return -SND_ERROR_INCOMPATIBLE_VERSION; } if (mode & SND_TIMER_OPEN_TREAD) { int arg = 1; if (ver < SNDRV_PROTOCOL_VERSION(2, 0, 3)) { ret = -ENOTTY; goto __no_tread; } if (ioctl(fd, SNDRV_TIMER_IOCTL_TREAD, &arg) < 0) { ret = -errno; __no_tread: close(fd); SNDMSG("extended read is not supported (SNDRV_TIMER_IOCTL_TREAD)"); return ret; } } memset(&sel, 0, sizeof(sel)); sel.id.dev_class = dev_class; sel.id.dev_sclass = dev_sclass; sel.id.card = card; sel.id.device = device; sel.id.subdevice = subdevice; if (ioctl(fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0) { ret = -errno; close(fd); return ret; } tmr = (snd_timer_t *) calloc(1, sizeof(snd_timer_t)); if (tmr == NULL) { close(fd); return -ENOMEM; } tmr->type = SND_TIMER_TYPE_HW; tmr->version = ver; tmr->mode = tmode; tmr->name = strdup(name); tmr->poll_fd = fd; tmr->ops = &snd_timer_hw_ops; INIT_LIST_HEAD(&tmr->async_handlers); *handle = tmr; return 0; }
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode) { int fd, ver; char filename[sizeof(SNDRV_FILE_CONTROL) + 10]; int fmode; snd_ctl_t *ctl; snd_ctl_hw_t *hw; int err; *handle = NULL; if (CHECK_SANITY(card < 0 || card >= 32)) { SNDMSG("Invalid card index %d", card); return -EINVAL; } sprintf(filename, SNDRV_FILE_CONTROL, card); if (mode & SND_CTL_READONLY) fmode = O_RDONLY; else fmode = O_RDWR; if (mode & SND_CTL_NONBLOCK) fmode |= O_NONBLOCK; if (mode & SND_CTL_ASYNC) fmode |= O_ASYNC; fd = snd_open_device(filename, fmode); if (fd < 0) { snd_card_load(card); fd = snd_open_device(filename, fmode); if (fd < 0) return -errno; } if (ioctl(fd, SNDRV_CTL_IOCTL_PVERSION, &ver) < 0) { err = -errno; close(fd); return err; } if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_CTL_VERSION_MAX)) { close(fd); return -SND_ERROR_INCOMPATIBLE_VERSION; } hw = calloc(1, sizeof(snd_ctl_hw_t)); if (hw == NULL) { close(fd); return -ENOMEM; } hw->card = card; hw->fd = fd; hw->protocol = ver; err = snd_ctl_new(&ctl, SND_CTL_TYPE_HW, name); if (err < 0) { close(fd); free(hw); return err; } ctl->ops = &snd_ctl_hw_ops; ctl->private_data = hw; ctl->poll_fd = fd; *handle = ctl; return 0; }
//------------------------------------------------------------------------ //! Find the group-id below the given point //! //! @param point Mouse position //! @return ID of the group //------------------------------------------------------------------------ int CGridListCtrlGroups::GroupHitTest(const CPoint& point) { if (!IsGroupViewEnabled()) return -1; if (HitTest(point)!=-1) return -1; if (IsGroupStateEnabled()) { #if _WIN32_WINNT >= 0x0600 #ifdef ListView_HitTestEx #ifdef LVHT_EX_GROUP #ifdef ListView_GetGroupInfoByIndex LVHITTESTINFO lvhitinfo = {0}; lvhitinfo.pt = point; ListView_HitTestEx(m_hWnd, &lvhitinfo); if ((lvhitinfo.flags & LVHT_EX_GROUP)==0) return -1; LVGROUP lg = {0}; lg.cbSize = sizeof(lg); lg.mask = LVGF_GROUPID; VERIFY( ListView_GetGroupInfoByIndex(m_hWnd, lvhitinfo.iGroup, &lg) ); return lg.iGroupId; #endif #endif #endif #endif } if (IsGroupStateEnabled()) { // Running on Vista or newer, but compiled without _WIN32_WINNT >= 0x0600 #ifndef LVM_GETGROUPINFOBYINDEX #define LVM_GETGROUPINFOBYINDEX (LVM_FIRST + 153) #endif #ifndef LVM_GETGROUPCOUNT #define LVM_GETGROUPCOUNT (LVM_FIRST + 152) #endif #ifndef LVM_GETGROUPRECT #define LVM_GETGROUPRECT (LVM_FIRST + 98) #endif #ifndef LVGGR_HEADER #define LVGGR_HEADER (1) #endif LRESULT groupCount = SNDMSG((m_hWnd), LVM_GETGROUPCOUNT, (WPARAM)0, (LPARAM)0); if (groupCount <= 0) return -1; for(int i = 0 ; i < groupCount; ++i) { LVGROUP lg = {0}; lg.cbSize = sizeof(lg); lg.mask = LVGF_GROUPID; VERIFY( SNDMSG((m_hWnd), LVM_GETGROUPINFOBYINDEX, (WPARAM)(i), (LPARAM)(&lg)) ); CRect rect(0,LVGGR_HEADER,0,0); VERIFY( SNDMSG((m_hWnd), LVM_GETGROUPRECT, (WPARAM)(lg.iGroupId), (LPARAM)(RECT*)(&rect)) ); if (rect.PtInRect(point)) return lg.iGroupId; } // Don't try other ways to find the group return -1; } // We require that each group contains atleast one item if (GetItemCount()==0) return -1; // This logic doesn't support collapsible groups int nFirstRow = -1; CRect gridRect; GetWindowRect(&gridRect); for(CPoint pt = point ; pt.y < gridRect.bottom ; pt.y += 2) { nFirstRow = HitTest(pt); if (nFirstRow!=-1) break; } if (nFirstRow==-1) return -1; int nGroupId = GetRowGroupId(nFirstRow); // Extra validation that the above row belongs to a different group int nAboveRow = GetNextItem(nFirstRow,LVNI_ABOVE); if (nAboveRow!=-1 && nGroupId==GetRowGroupId(nAboveRow)) return -1; return nGroupId; }