2011년9월23일_winAPI_에디트, 리스트박스, 콤보박스,




시간 으뉴







참조(Reference)




DSCN4462 DSCN4463 DSCN4464 DSCN4465




● 에디트 박스

   1: //MsgProc.cpp
   2:  
   3: #include "MsgProc.h"
   4:  
   5: HWND hEdit;
   6: TCHAR str[128];
   7:  
   8: LRESULT OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
   9: {
  10:     hEdit=CreateWindow(TEXT("edit"),NULL,WS_CHILD | WS_VISIBLE | WS_BORDER | 
  11:         ES_AUTOHSCROLL,10,10,200,25,hWnd,(HMENU)ID_EDIT,g_hInst,NULL);
  12:     return 0;
  13: }
  14:  
  15: LRESULT OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
  16: {
  17:     switch (LOWORD(wParam)) {
  18:     case ID_EDIT:
  19:         switch (HIWORD(wParam)) {
  20:         case EN_CHANGE:
  21:             GetWindowText(hEdit,str,128);
  22:             SetWindowText(hWnd,str);
  23:         }
  24:     }
  25:  
  26:     return 0;
  27: }
  28:  
  29: LRESULT OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
  30: {
  31:  
  32:     return 0;
  33: }
  34:  
  35: LRESULT OnRButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
  36: {
  37:  
  38:     return 0;
  39: }
  40:  
  41:  
  42: LRESULT OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
  43: {
  44:  
  45:     return 0;
  46: }
  47:  
  48: LRESULT OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
  49: {
  50:     return 0;
  51: }
  52:  
  53: LRESULT OnLButtonDBLCLK(HWND hWnd, WPARAM wParam, LPARAM lParam)
  54: {
  55:  
  56:     return 0;
  57: }
  58:  
  59:  
  60: LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
  61: {
  62:     HDC hdc;
  63:     PAINTSTRUCT ps;
  64:  
  65:     hdc = BeginPaint(hWnd, &ps);
  66:  
  67:  
  68:     EndPaint(hWnd, &ps);
  69:  
  70:     return 0;
  71: }
  72:  
  73: LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
  74: {
  75:     PostQuitMessage(0);
  76:     return 0;
  77: }


image


● 에디트도 윈도우다

   1: //MsgProc.cpp
   2:  
   3: #include "MsgProc.h"
   4:  
   5: HWND hEdit;
   6: int nTop=10;
   7: BOOL bShow=TRUE;
   8:  
   9:  
  10: LRESULT OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
  11: {
  12:     hEdit=CreateWindow(TEXT("edit"),NULL,WS_CHILD | WS_VISIBLE | WS_BORDER | 
  13:         ES_AUTOHSCROLL,10,nTop,200,25,hWnd,(HMENU)ID_EDIT,g_hInst,NULL);
  14:     SetWindowText(hEdit,TEXT("에디트도 윈도우다"));
  15:     return 0;
  16: }
  17:  
  18: LRESULT OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
  19: {
  20:  
  21:     return 0;
  22: }
  23:  
  24: LRESULT OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
  25: {
  26:         nTop+=10;
  27:         MoveWindow(hEdit,10,nTop,200,25,TRUE);
  28:     return 0;
  29: }
  30:  
  31: LRESULT OnRButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
  32: {
  33:     if (bShow) {
  34:         bShow=FALSE;
  35:         ShowWindow(hEdit,SW_HIDE);
  36:     } else {
  37:         bShow=TRUE;
  38:         ShowWindow(hEdit,SW_SHOW);
  39:     }
  40:     return 0;
  41: }
  42:  
  43:  
  44: LRESULT OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
  45: {
  46:  
  47:     return 0;
  48: }
  49:  
  50: LRESULT OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
  51: {
  52:     return 0;
  53: }
  54:  
  55: LRESULT OnLButtonDBLCLK(HWND hWnd, WPARAM wParam, LPARAM lParam)
  56: {
  57:  
  58:     return 0;
  59: }
  60:  
  61:  
  62: LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
  63: {
  64:     HDC hdc;
  65:     PAINTSTRUCT ps;
  66:     TCHAR *Mes=TEXT("왼쪽 클릭:에디트 이동, 오른쪽 클릭:보임/숨김");
  67:  
  68:     hdc = BeginPaint(hWnd, &ps);
  69:     TextOut(hdc,200,100,Mes,lstrlen(Mes));
  70:  
  71:     EndPaint(hWnd, &ps);
  72:  
  73:     return 0;
  74: }
  75:  
  76: LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
  77: {
  78:     PostQuitMessage(0);
  79:     return 0;
  80: }

image image image


● 리스트 박스

   1: //MsgProc.cpp
   2:  
   3: #include "MsgProc.h"
   4:  
   5: TCHAR *Items[] = 
   6: {
   7:     TEXT("Apple"),
   8:     TEXT("Orange"),
   9:     TEXT("Melon"),
  10:     TEXT("Grape"),
  11:     TEXT("Strawberry")
  12: };
  13:  
  14: HWND hList;
  15: TCHAR str[128];
  16:  
  17:  
  18: LRESULT OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
  19: {
  20:     int i;
  21:  
  22:     hList = CreateWindow(TEXT("listbox"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER |
  23:         LBS_NOTIFY, 10, 10, 100, 200, hWnd, (HMENU)ID_LISTBOX, g_hInst, NULL);
  24:  
  25:     for(i = 0 ; i < 5 ; i++)
  26:     {
  27:         SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)Items[i]);
  28:     }
  29:  
  30:     return 0;
  31: }
  32:  
  33: LRESULT OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
  34: {
  35:     int i;
  36:  
  37:     switch(LOWORD(wParam))
  38:     {
  39:     case ID_LISTBOX:
  40:         switch(HIWORD(wParam))
  41:         {
  42:         case LBN_SELCHANGE:
  43:             i = SendMessage(hList, LB_GETCURSEL, 0, 0);
  44:             SendMessage(hList, LB_GETTEXT, i, (LPARAM)str);
  45:             SetWindowText(hWnd, str);
  46:             break;
  47:         }
  48:     }
  49:  
  50:     return 0;
  51: }
  52:  
  53: LRESULT OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
  54: {
  55:     return 0;
  56: }
  57:  
  58: LRESULT OnRButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
  59: {
  60:     return 0;
  61: }
  62:  
  63:  
  64: LRESULT OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
  65: {
  66:  
  67:     return 0;
  68: }
  69:  
  70: LRESULT OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
  71: {
  72:     return 0;
  73: }
  74:  
  75: LRESULT OnLButtonDBLCLK(HWND hWnd, WPARAM wParam, LPARAM lParam)
  76: {
  77:  
  78:     return 0;
  79: }
  80:  
  81:  
  82: LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
  83: {
  84:     HDC hdc;
  85:     PAINTSTRUCT ps;
  86:  
  87:     hdc = BeginPaint(hWnd, &ps);
  88:     TextOut(hdc, 100, 100, TEXT(str), lstrlen(str));    //출력 앙대 ㅠㅠ,
  89:     EndPaint(hWnd, &ps);
  90:  
  91:     return 0;
  92: }
  93:  
  94: LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
  95: {
  96:     PostQuitMessage(0);
  97:     return 0;
  98: }


image image image


● 콤보박스

   1: //MsgProc.cpp
   2:  
   3: #include "MsgProc.h"
   4:  
   5: #define ID_COMBOBOX 100
   6: TCHAR *Items[]={TEXT("Apple"),TEXT("Orange"),TEXT("Melon"),TEXT("Grape"),
   7:     TEXT("Strawberry")};
   8: HWND hCombo;
   9:  
  10:  
  11: LRESULT OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
  12: {
  13:     int i;
  14:  
  15:     hCombo=CreateWindow(TEXT("combobox"),NULL,WS_CHILD | WS_VISIBLE | 
  16:         CBS_DROPDOWNLIST,10,10,100,200,hWnd,(HMENU)ID_COMBOBOX,g_hInst,NULL);
  17:     for (i=0;i<5;i++) {
  18:         SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)Items[i]);
  19:     }
  20:  
  21:     return 0;
  22: }
  23:  
  24: LRESULT OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
  25: {
  26:     int i;
  27:     TCHAR str[128];
  28:  
  29:     switch (LOWORD(wParam)) {
  30:     case ID_COMBOBOX:
  31:         switch (HIWORD(wParam)) {
  32:         case CBN_SELCHANGE:
  33:             i=SendMessage(hCombo, CB_GETCURSEL,0,0);
  34:             SendMessage(hCombo, CB_GETLBTEXT, i, (LPARAM)str);
  35:             SetWindowText(hWnd, str);
  36:             break;
  37:         case CBN_EDITCHANGE:
  38:             GetWindowText(hCombo, str, 128);
  39:             SetWindowText(hWnd,str);
  40:             break;
  41:         }
  42:     }
  43:  
  44:     return 0;
  45: }
  46:  
  47: LRESULT OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
  48: {
  49:     return 0;
  50: }
  51:  
  52: LRESULT OnRButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
  53: {
  54:     return 0;
  55: }
  56:  
  57:  
  58: LRESULT OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
  59: {
  60:  
  61:     return 0;
  62: }
  63:  
  64: LRESULT OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
  65: {
  66:     return 0;
  67: }
  68:  
  69: LRESULT OnLButtonDBLCLK(HWND hWnd, WPARAM wParam, LPARAM lParam)
  70: {
  71:  
  72:     return 0;
  73: }
  74:  
  75:  
  76: LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
  77: {
  78:     HDC hdc;
  79:     PAINTSTRUCT ps;
  80:  
  81:     hdc = BeginPaint(hWnd, &ps);
  82:     EndPaint(hWnd, &ps);
  83:  
  84:     return 0;
  85: }
  86:  
  87: LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
  88: {
  89:     PostQuitMessage(0);
  90:     return 0;
  91: }



image image image

전체소스코드압축: API_project.zip