combo box items doesn't appear created in MFC project using VS2010

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi <br/>
I had problem with my dialog that I create it using <br/>
add -> resource -> dialog<br/>
then I design it by drop the combo box in it using the tool box available in visual studio<br/>
then I put the combo box items by write it in the data label of the combo properties<br/>
when I add this dialog to my code the items does not appear<br/>
I thought that I have to add it by addString function in the class that handle the dialog but it also did not work<br/>
can you help me to fix this problem please<br/>
<br/>
<br/>
the class that call the dialog:<br/>
Code:
<br/>
#include "StdAfx.h"<br/>
#include <windows.h><br/>
#include <iostream><br/>
#include <math.h><br/>
#include "measures.h"<br/>
#include "resource.h"<br/>
using namespace std;<br/>
<br/>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;<br/>
BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);<br/>
<br/>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)<br/>
<br/>
{<br/>
<span style="white-space:pre <br/>
static TCHAR szAppName[] = TEXT ("SineWave") ;<br/>
HWND hwnd ;<br/>
<br/>
MSG msg ;<br/>
WNDCLASS wndclass ;<br/>
wndclass.style = CS_HREDRAW | CS_VREDRAW ;<br/>
wndclass.lpfnWndProc = WndProc ;<br/>
wndclass.cbClsExtra = 0 ;<br/>
wndclass.cbWndExtra = 0 ;<br/>
wndclass.hInstance = hInstance ;<br/>
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;<br/>
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;<br/>
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;<br/>
wndclass.lpszMenuName = NULL ;<br/>
wndclass.lpszClassName = szAppName ;<br/>
<br/>
if (!RegisterClass (&wndclass))<br/>
{<br/>
MessageBox (NULL, TEXT ("Program requires Windows NT!"), szAppName, MB_ICONERROR) ;<br/>
return 0 ;<br/>
}<br/>
<br/>
hwnd = CreateWindow (szAppName, TEXT ("My prog"),<br/>
WS_OVERLAPPEDWINDOW,<br/>
CW_USEDEFAULT, CW_USEDEFAULT,<br/>
CW_USEDEFAULT, CW_USEDEFAULT,<br/>
NULL, NULL, hInstance, NULL) ;<br/>
//SW_SHOWMAXIMIZED for program window<br/>
ShowWindow (hwnd, iCmdShow) ;<br/>
UpdateWindow (hwnd) ;<br/>
<br/>
while (GetMessage (&msg, NULL, 0, 0))<br/>
{<br/>
TranslateMessage (&msg) ;<br/>
DispatchMessage (&msg) ;<br/>
}<br/>
return msg.wParam ;<br/>
}<br/>
<br/>
<br/>
// function to draw the curves<br/>
void DrawBezier (HDC hdc, POINT apt[])<br/>
   {<br/>
      <br/>
<span style="white-space:pre   PolyBezier (hdc, apt, 4) ;<br/>
      <br/>
   }<br/>
<br/>
<br/>
<br/>
<br/>
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)<br/>
{<br/>
static int cxChar, iVertPos, iHorzPos,cxCaps, cyChar, cxClient, cyClient, iMaxWidth ;<br/>
HDC hdc ;<br/>
int m; // choose measure<br/>
PAINTSTRUCT ps ;<br/>
TEXTMETRIC tm ;<br/>
<br/>
static POINT p[4];<br/>
static HINSTANCE hInstance ;<br/>
switch (message)<br/>
{<br/>
<span style="white-space:pre case WM_CREATE:<br/>
<br/>
hdc = GetDC (hwnd) ;<br/>
GetTextMetrics (hdc, &tm) ;<br/>
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;<br/>
<br/>
// the program menues<br/>
HMENU  hmenu, hSubMenu;<br/>
hmenu = CreateMenu();<br/>
hSubMenu = CreatePopupMenu();<br/>
AppendMenu(hSubMenu, MF_STRING, IDM_FILE_NEW, "&NEW");<br/>
AppendMenu(hSubMenu, MF_STRING, IDM_FILE_EXIT, "E&xit");<br/>
AppendMenu(hmenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");<br/>
SetMenu(hwnd, hmenu);<br/>
<br/>
<br/>
<br/>
ReleaseDC (hwnd, hdc) ;<br/>
<br/>
return 0 ;<br/>
<br/>
<br/>
case WM_SIZE:<br/>
cxClient = LOWORD (lParam) ;<br/>
cyClient = HIWORD (lParam) ;<br/>
return 0 ;<br/>
<br/>
<br/>
case WM_PAINT:<br/>
// some code ..<br/>
<br/>
<br/>
<br/>
<br/>
case WM_COMMAND: // here to handle the new type of messeges related to the program<br/>
         switch(LOWORD(wParam))<br/>
         {<br/>
<span style="white-space:pre // draw new pattern<br/>
<span style="white-space:pre   case IDM_FILE_NEW:<br/>
<span style="white-space:pre  <br/>
<span style="white-space:pre    DialogBox (hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, AboutDlgProc);<br/>
<br/>
<span style="white-space:pre   <br/>
<br/>
<span style="white-space:pre   // close the program<br/>
<span style="white-space:pre   case IDM_FILE_EXIT:<br/>
                  PostQuitMessage(0);<br/>
                  break;<br/>
<br/>
         }<br/>
<span style="white-space:pre  <br/>
<br/>
case WM_DESTROY:<br/>
PostQuitMessage (0) ;<br/>
return 0 ;<br/>
}<br/>
<br/>
return DefWindowProc (hwnd, message, wParam, lParam) ;<br/>
}<br/>
<br/>
BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)<br/>
{<br/>
<span style="white-space:pre switch (message)<br/>
{<br/>
<br/>
<span style="white-space:pre case WM_INITDIALOG :<br/>
<span style="white-space:pre <br/>
<span style="white-space:pre <br/>
     return TRUE ;<br/>
<br/>
      case WM_COMMAND :<br/>
<br/>
      switch (LOWORD (wParam))<br/>
             {<br/>
              case IDOK :<br/>
<span style="white-space:pre          EndDialog(hDlg, IDOK);<br/>
<span style="white-space:pre                break;<br/>
<br/>
<span style="white-space:pre  case IDC_COMBO1 :<br/>
<span style="white-space:pre  <br/>
            <br/>
<span style="white-space:pre  break;<br/>
              case IDCANCEL :<br/>
                  EndDialog (hDlg, 0) ;<br/>
<br/>
                   return TRUE ;<br/>
            }<br/>
            <br/>
            }<br/>
           return FALSE ;<br/>
<br/>
          }<br/>
<br/>
<br/>
<br/>
<br/>
// the class that handle the dialog: .cpp<br/>
<br/>
Code:
<br/>
// mydialog.cpp : implementation file<br/>
//<br/>
<br/>
#include "stdafx.h"<br/>
#include "patternMaker.h"<br/>
#include "mydialog.h"<br/>
#include "afxdialogex.h"<br/>
<br/>
<br/>
// mydialog dialog<br/>
<br/>
IMPLEMENT_DYNAMIC(mydialog, CDialogEx)<br/>
<br/>
mydialog::mydialog(CWnd* pParent /*=NULL*/)<br/>
<span style="white-space:pre : CDialogEx(mydialog::IDD, pParent)<br/>
{<br/>
<br/>
}<br/>
<br/>
mydialog::~mydialog()<br/>
{<br/>
}<br/>
<br/>
void mydialog::DoDataExchange(CDataExchange* pDX)<br/>
{<br/>
<span style="white-space:pre CDialogEx::DoDataExchange(pDX);<br/>
<span style="white-space:pre DDX_Control(pDX, IDC_COMBO1, m_combostate);<br/>
}<br/>
<br/>
<br/>
BEGIN_MESSAGE_MAP(mydialog, CDialogEx)<br/>
<span style="white-space:pre ON_CBN_SELCHANGE(IDC_COMBO1, &mydialog::OnCbnSelchangeCombo1)<br/>
END_MESSAGE_MAP()<br/>
<br/>
<br/>
// mydialog message handlers<br/>
<br/>
<br/>
void mydialog::OnCbnSelchangeCombo1()<br/>
{<br/>
<span style="white-space:pre // TODO: Add your control notification handler code here<br/>
}<br/>
<br/>
<br/>
BOOL mydialog::OnInitDialog()<br/>
{<br/>
<span style="white-space:pre CDialogEx::OnInitDialog();<br/>
<br/>
<span style="white-space:pre m_combostate.AddString("2");<br/>
<span style="white-space:pre m_combostate.SetCurSel(0);<br/>
<br/>
<span style="white-space:pre return TRUE;  // return TRUE unless you set the focus to a control<br/>
<span style="white-space:pre // EXCEPTION: OCX Property Pages should return FALSE<br/>
}<br/>
<br/>
<br/>
<br/>
// the class that handle the dialog .h<br/>
<br/>
Code:
<br/>
#pragma once<br/>
#include "afxwin.h"<br/>
<br/>
<br/>
// mydialog dialog<br/>
<br/>
class mydialog : public CDialogEx<br/>
{<br/>
<span style="white-space:pre DECLARE_DYNAMIC(mydialog)<br/>
<br/>
public:<br/>
<span style="white-space:pre mydialog(CWnd* pParent = NULL);   // standard constructor<br/>
<span style="white-space:pre virtual ~mydialog();<br/>
<br/>
// Dialog Data<br/>
<span style="white-space:pre enum { IDD = IDD_DIALOG1 };<br/>
<br/>
protected:<br/>
<span style="white-space:pre virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support<br/>
<br/>
<span style="white-space:pre DECLARE_MESSAGE_MAP()<br/>
<br/>
public:<br/>
<span style="white-space:pre afx_msg void OnCbnSelchangeCombo1();<br/>
<span style="white-space:pre CComboBox m_combostate;<br/>
<span style="white-space:pre virtual BOOL OnInitDialog();<br/>
};<br/>
<br/>

View the full article
 
Back
Top