#include <windows.h> LPCTSTR strItem[] = { TEXT("Kitty on your lap") , TEXT("Tokyo mew mew") , TEXT("Magical nyan nyan TARUTO") , TEXT("Di Gi Charat") , TEXT("Nekoneko Zoo") }; LRESULT CALLBACK WndProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) { static HWND combo; int i; switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: combo = CreateWindow( TEXT("COMBOBOX") , NULL , WS_CHILD | WS_VISIBLE | CBS_SORT | CBS_SIMPLE , 0 , 0 , 300 , 300 , hwnd , (HMENU)1 , ((LPCREATESTRUCT)(lp))->hInstance , NULL ); for (i = 0 ; i < 5 ; i++) SendMessage(combo , CB_ADDSTRING , 0 , (LPARAM)strItem[i]); return 0; } return DefWindowProc(hwnd , msg , wp , lp); } int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow ) { HWND hwnd; MSG msg; WNDCLASS winc; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = WndProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL , IDI_APPLICATION); winc.hCursor = LoadCursor(NULL , IDC_ARROW); winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszMenuName = NULL; winc.lpszClassName = TEXT("KITTY"); if (!RegisterClass(&winc)) return -1; hwnd = CreateWindow( TEXT("KITTY") , TEXT("Kitty on your lap") , WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , NULL , NULL , hInstance , NULL ); if (hwnd == NULL) return -1; while(GetMessage(&msg , NULL , 0 , 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
#include <windows.h> LPCTSTR strItem[] = { TEXT("Kitty on your lap") , TEXT("Tokyo mew mew") , TEXT("Magical nyan nyan TARUTO") , TEXT("Di Gi Charat") , TEXT("Nekoneko Zoo") }; LRESULT CALLBACK WndProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) { static HWND combo; int i; switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: combo = CreateWindow( TEXT("COMBOBOX") , NULL , WS_CHILD | WS_VISIBLE | CBS_SORT | CBS_DROPDOWNLIST , 0 , 0 , 300 , 300 , hwnd , (HMENU)1 , ((LPCREATESTRUCT)(lp))->hInstance , NULL ); for (i = 0 ; i < 5 ; i++) SendMessage(combo , CB_ADDSTRING , 0 , (LPARAM)strItem[i]); return 0; } return DefWindowProc(hwnd , msg , wp , lp); } int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow ) { HWND hwnd; MSG msg; WNDCLASS winc; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = WndProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL , IDI_APPLICATION); winc.hCursor = LoadCursor(NULL , IDC_ARROW); winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszMenuName = NULL; winc.lpszClassName = TEXT("KITTY"); if (!RegisterClass(&winc)) return -1; hwnd = CreateWindow( TEXT("KITTY") , TEXT("Kitty on your lap") , WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , NULL , NULL , hInstance , NULL ); if (hwnd == NULL) return -1; while(GetMessage(&msg , NULL , 0 , 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
#include <windows.h> LPCTSTR strItem[] = { TEXT("Kitty on your lap") , TEXT("Tokyo mew mew") , TEXT("Magical nyan nyan TARUTO") , TEXT("Di Gi Charat") , TEXT("Nekoneko Zoo") }; LRESULT CALLBACK WndProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) { static HWND combo; int i; switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: combo = CreateWindow( TEXT("COMBOBOX") , NULL , WS_CHILD | WS_VISIBLE | CBS_SORT | CBS_DROPDOWNLIST , 0 , 0 , 300 , 300 , hwnd , (HMENU)1 , ((LPCREATESTRUCT)(lp))->hInstance , NULL ); for (i = 0 ; i < 5 ; i++) SendMessage(combo , CB_ADDSTRING , 0 , (LPARAM)strItem[i]); SetTimer(hwnd , 1 , 1000 , NULL); return 0; case WM_TIMER: if (SendMessage(combo , CB_GETDROPPEDSTATE , 0 , 0)) SendMessage(combo , CB_SHOWDROPDOWN , FALSE , 0); else SendMessage(combo , CB_SHOWDROPDOWN , TRUE , 0); return 0; } return DefWindowProc(hwnd , msg , wp , lp); } int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow ) { HWND hwnd; MSG msg; WNDCLASS winc; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = WndProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL , IDI_APPLICATION); winc.hCursor = LoadCursor(NULL , IDC_ARROW); winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszMenuName = NULL; winc.lpszClassName = TEXT("KITTY"); if (!RegisterClass(&winc)) return -1; hwnd = CreateWindow( TEXT("KITTY") , TEXT("Kitty on your lap") , WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , NULL , NULL , hInstance , NULL ); if (hwnd == NULL) return -1; while(GetMessage(&msg , NULL , 0 , 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }約1秒ごとにリストを開いたり閉じたりするプログラムです
定数 | 解説 |
---|---|
CBN_CLOSEUP | リストボックスが閉じられた |
CBN_DBLCLK | リストボックスの項目をダブルクリック |
CBN_DROPDOWN | リストボックスが表示されようとしている |
CBN_EDITCHANGE | エディットでテキストが変更された可能性がある |
CBN_EDITUPDATE | エディットのテキストが変更され エディットを表示しようとしている |
CBN_ERRSPACE | 十分なメモリを割り当てられない |
CBN_KILLFOCUS | キーボードフォーカスを失った |
CBN_SELCHANGE | リストボックスの選択の変更 |
CBN_SELENDCANCEL | アイテムを選択したが、その時に他のコントロールを選択 または、ダイアログボックスを閉じた |
CBN_SELENDOK | アイテムを選択し、リストを閉じる |
CBN_SETFOCUS | キーボードフォーカスを得た |
#include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) { static HWND combo , label; static TCHAR strText[1024]; switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: combo = CreateWindow( TEXT("COMBOBOX") , NULL , WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_SORT | CBS_DROPDOWNLIST , 0 , 0 , 300 , 100 , hwnd , (HMENU)1 , ((LPCREATESTRUCT)(lp))->hInstance , NULL ); SendMessage(combo , CB_DIR , DDL_READWRITE , (LPARAM)TEXT("*.*")); label = CreateWindow( TEXT("STATIC") , NULL , WS_CHILD | WS_VISIBLE , 300 , 0 , 200 , 100 , hwnd , (HMENU)2 , ((LPCREATESTRUCT)(lp))->hInstance , NULL ); return 0; case WM_COMMAND: if (HIWORD(wp) == CBN_SELCHANGE) { wsprintf(strText , TEXT("アイテム数 = %d\n選択項目 = %d") , SendMessage(combo , CB_GETCOUNT , 0 , 0) , SendMessage(combo , CB_GETCURSEL , 0 , 0) ); SetWindowText(label , strText); } return 0; } return DefWindowProc(hwnd , msg , wp , lp); } int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow ) { HWND hwnd; MSG msg; WNDCLASS winc; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = WndProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL , IDI_APPLICATION); winc.hCursor = LoadCursor(NULL , IDC_ARROW); winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszMenuName = NULL; winc.lpszClassName = TEXT("KITTY"); if (!RegisterClass(&winc)) return -1; hwnd = CreateWindow( TEXT("KITTY") , TEXT("Kitty on your lap") , WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , NULL , NULL , hInstance , NULL ); if (hwnd == NULL) return -1; while(GetMessage(&msg , NULL , 0 , 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }