C ++ Win32, How to add a drop-down menu to a Win32 dialog
Hi,
This is my first quesiton post on stackoverflow.
I am trying to add combobox (in menu.cpp) to Win32 Dialogbox (in fingerpell.cpp). I am not very fluent in Win32 programming, and most fragments of the msdn example cross out the combo box inside the window. Although Dialogbox is technically a window, but I have not made much progress in modifying any code in the sample window to handle DialogBox. I would really appreciate a working example.
A rough sketch of the code is as follows. fingerpell.cpp creates implements the WinMain function, and then calls other custom classes to draw inside this DialogBox. No other window controls, such as buttons, text area, etc., are used.
code for fingerpell.cpp
#include "fingerspell.h"
extern "C" __declspec(dllexport)bool isGloveDriverInstalled();
extern "C" __declspec(dllimport)bool initialize();
#define RUN( x ) if ( SUCCEEDED( result ) ) { result = x; }
BOOL g_fullscreen = FALSE;
bool portReady;
INT_PTR CALLBACK OptionDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_INITDIALOG:
if (wParam == IDOK)
return TRUE ;
else
return FALSE ;
break;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED) {
if (LOWORD(wParam) == IDOK) {
g_fullscreen = TRUE;
EndDialog (hwndDlg, 1) ;
}
else if (LOWORD(wParam) == ID_WINDOW_OPT) {
g_fullscreen = FALSE;
EndDialog (hwndDlg, 1) ;
}
else {
EndDialog (hwndDlg, 0) ;
}
return TRUE ;
}
default:
return FALSE;
break ;
}
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
INT_PTR DispOption = DialogBox (hInstance, MAKEINTRESOURCE(IDD_DISPLAY_OPTIONS), NULL, OptionDialogProc) ;
if (DispOption == 0)
return 0 ;
HRESULT result = S_OK;
if (!isGloveDriverInstalled())
{
portReady = FALSE;
MessageBox(NULL, "The Glove Driver is not istalled ", "Error", MB_OK );
}
else
{
if (!initialize())
{
portReady = FALSE;
MessageBox(NULL, "Error Opening Com Port", "Error", MB_OK );
}
else
{
portReady = TRUE;
}
}
RUN( Words ::Create ( "default.txt" ) );
RUN( Window::Create ( ) );
RUN( Render::Create ( ) );
RUN( Art ::Create ( ) );
RUN( Menu ::Create ( ) );
RUN( Window::MessageLoop( ) );
RUN( Menu ::Destroy ( ) );
RUN( Art ::Destroy ( ) );
RUN( Render::Destroy ( ) );
RUN( Window::Destroy ( ) );
RUN( Words ::Destroy ( ) );
if ( FAILED( result ) )
{
MessageBox( GetDesktopWindow( ), "Warning - Fail Code Detected", "Fingerspell 2002", MB_ICONWARNING | MB_OK );
}
return result;
}
code for menu.cpp. file where im trying to add combobox.
#include "fingerspell.h"
#include <windows.h> //include all the basics
#include <tchar.h> //string and other mapping macros
#include <string>
HRESULT Menu::Create( )
{
Render::SetBackground( ART_MENU );
Render::Reset( );
Window::SetProc( Proc );
return S_OK;
}
HRESULT Menu::Destroy( void )
{
return S_OK;
}
LRESULT CALLBACK Menu::Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
DWORD i ;
const static RECT button_rect[ 8 ] =
{
{ 52, 139, 52 + 101, 139 + 50 },
{ 55, 212, 55 + 85, 212 + 50 },
{ 67, 280, 67 + 63, 280 + 50 },
{ 397, 137, 397+ 233, 137 + 50 },
{ 421, 187, 421+ 183, 187 + 50 },
{ 413, 247, 413+ 201, 247 + 50 },
{ 450, 300, 450+ 124, 300 + 50 },
{ 473, 349, 473 + 82, 349 + 50 },
};
switch ( uMsg )
{
case WM_CREATE:
return OnCreate(hwnd,reinterpret_cast<CREATESTRUCT*>(lParam));
case WM_MOUSEMOVE:
{
int xPos = GET_X_LPARAM( lParam );
int yPos = GET_Y_LPARAM( lParam );
for ( i = 0; i < 8; i++ )
{
if ( xPos >= button_rect[ i ].left && yPos >= button_rect[ i ].top )
{
if ( xPos < button_rect[ i ].right && yPos < button_rect[ i ].bottom )
{
Render::SetOverlay( 0, (ART) ( ART_MENU_LEARN + i ), button_rect[ i ].left, button_rect[ i ].top );
break;
}
}
}
if ( i == 8 )
{
Render::SetOverlay( 0, ART_NULL, 0, 0 );
}
return 0;
}
case WM_LBUTTONDOWN:
{
switch ( Render::GetOverlay( 0 ) )
{
case ART_MENU_EXIT:
{
Menu::Destroy( );
Learn::Create( );
break;
}
case ART_MENU_LEARN:
{
Menu::Destroy( );
About::Create( );
break;
}
case ART_MENU_ABOUT:
{
Menu::Destroy( );
Test::Create( );
break;
}
case ART_MENU_TEST:
{
Menu::Destroy( );
Practice::Create( );
break;
}
case ART_MENU_DELETEWORD:
{
Menu::Destroy( );
AddWord::Create( );
break;
}
case ART_MENU_ADDDELETELIST:
{
PostQuitMessage( 0 );
break;
}
case ART_MENU_ADD:
{
Menu::Destroy( );
About::Create( );
break;
}
case ART_MENU_PRACTICE:
{
Menu::Destroy( );
About::Create( );
break;
}
}
return 0;
}
}
return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
Thank.