My Project
combobox.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 #include "../stdafx.h"
3 #include "combobox.h"
4 
6 {
7 
8 }
9 
11 {
12  this->ID = ID;
13 }
14 
15 Combobox::Combobox(int X, int Y, int HEIGHT, int WIDTH, WCHAR* TEXT)
16 {
17  this->create(X, Y, HEIGHT, WIDTH, TEXT);
18 }
19 
21 {
22  this->remove();
23 }
24 
25 HWND Combobox::create(int X, int Y, int HEIGHT, int WIDTH, WCHAR* TEXT)
26 {
27  if (this->chWnd)
28  {
29  return this->chWnd;
30  }
31  this->chWnd = CreateWindowExW(NULL, TEXT("COMBOBOX"), TEXT(""),
32  WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_AUTOHSCROLL,
33  X, Y, WIDTH, 30,
34  this->hWnd, (HMENU)this->ID, this->hInst, NULL);
35 
36  this->addItem(TEXT);
37 
38  HFONT hfont = CreateFont(HEIGHT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("Arial"));
39  SendMessage(this->chWnd, WM_SETFONT, (WPARAM)hfont, 0);
40 
41  return this->chWnd;
42 }
43 
44 void Combobox::addItem(WCHAR* item)
45 {
46  WCHAR buf[100];
47  memset(&buf, 0, sizeof(buf));
48  wcscpy_s(buf, sizeof(buf) / sizeof(WCHAR), (WCHAR*)item);
49  SendMessage(this->chWnd, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)buf);
50  SendMessage(this->chWnd, CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
51 }
52 
54 {
55  return ComboBox_GetCurSel(this->chWnd);
56 }
57 
59 {
60  return this->chWnd;
61 }
62 
64 {
65  DestroyWindow(GetDlgItem(this->hWnd, this->ID));
66  this->chWnd = NULL;
67 }
static HINSTANCE hInst
Definition: interface.h:61
int getCurrentItem()
Definition: combobox.cpp:53
Combobox()
Definition: combobox.cpp:5
HWND create(int X, int Y, int HEIGHT, int WIDTH, WCHAR *TEXT) override
Definition: combobox.cpp:25
HWND getHWND()
Definition: combobox.cpp:58
void addItem(WCHAR *item)
Definition: combobox.cpp:44
Combobox interface class.
~Combobox()
Definition: combobox.cpp:20
void remove() override
Definition: combobox.cpp:63
static HWND hWnd
Definition: interface.h:60