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