C语言Dialogbox添加图片,winapi – C Win32,如何将下拉菜单添加到Win32 DialogBox

编程入门 行业动态 更新时间:2024-10-14 20:20:24

C语言Dialogbox添加图片,winapi – C Win32,<a href=https://www.elefans.com/category/jswz/34/1771359.html style=如何将下拉菜单添加到Win32 DialogBox"/>

C语言Dialogbox添加图片,winapi – C Win32,如何将下拉菜单添加到Win32 DialogBox

C Win32,如何将下拉菜单添加到Win32 DialogBox

嗨,

这是我第一次将问题发布到stackoverflow.

我试图将组合框(在menu.cpp中)添加到Win32对话框(在fingerspell.cpp中).我对Win32不太熟悉

编程和大多数msdn示例片段在窗口内绘制一个组合框.尽管Dialogbox在技术上是合适的

一个窗口但我在修改任何窗口示例代码以处理DialogBox方面没有太大进展.我真的很感激一个有效的例子.

代码的草图如下. fingerspell.cpp created实现了WinMain函数,然后调用

要在此DialogBox中绘制的其他自定义类.没有使用其他窗口控件,如按钮,文本区域等.

fingerspell.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 ;

//srand( GetTickCount( ) );

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;

}

menu.cpp的代码.我试图添加组合框的文件.

#include "fingerspell.h"

#include //include all the basics

#include //string and other mapping macros

#include

HRESULT Menu::Create( )

{

// set menu as the background

Render::SetBackground( ART_MENU );

// clear overlay

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 }, //1. about

{ 55, 212, 55 + 85, 212 + 50 }, // 2. learn

{ 67, 280, 67 + 63, 280 + 50 }, // 3. exit

{ 397, 137, 397+ 233, 137 + 50 }, // 4. Add Delete List.

{ 421, 187, 421+ 183, 187 + 50 }, // 5. add word

{ 413, 247, 413+ 201, 247 + 50 }, // 6. delete word

{ 450, 300, 450+ 124, 300 + 50 }, // 7. practice

{ 473, 349, 473 + 82, 349 + 50 }, // 8. test

};

// custom message processing

switch ( uMsg )

{

case WM_CREATE:

return OnCreate(hwnd,reinterpret_cast(lParam));

case WM_MOUSEMOVE: // move is moved, see where is it pointing to.

{

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 )

{

// set selection

Render::SetOverlay( 0, (ART) ( ART_MENU_LEARN + i ), button_rect[ i ].left, button_rect[ i ].top );

break;

}

}

}

if ( i == 8 )

{

//remove selection

Render::SetOverlay( 0, ART_NULL, 0, 0 );

}

return 0;

}

case WM_LBUTTONDOWN:

{

switch ( Render::GetOverlay( 0 ) )

{

case ART_MENU_EXIT: // done.

{

Menu::Destroy( );

Learn::Create( );

break;

}

case ART_MENU_LEARN: // done

{

Menu::Destroy( );

About::Create( );

break;

}

case ART_MENU_ABOUT: // done

{

Menu::Destroy( );

Test::Create( );

break;

}

case ART_MENU_TEST: // done.

{

Menu::Destroy( );

Practice::Create( );

break;

}

case ART_MENU_DELETEWORD: // done

{

Menu::Destroy( );

AddWord::Create( );

break;

}

case ART_MENU_ADDDELETELIST:

{

//Menu::Destroy () ;

PostQuitMessage( 0 );

break;

}

case ART_MENU_ADD:

{

Menu::Destroy( );

// About is place holder. should be AddDELETELIST

About::Create( );

break;

}

case ART_MENU_PRACTICE: // done.

{

Menu::Destroy( );

// About is place holder. shd be DELETEWORD.

About::Create( );

break;

}

}

return 0;

}

}

// default message processing

return DefWindowProc( hwnd, uMsg, wParam, lParam );

}

谢谢.

更多推荐

C语言Dialogbox添加图片,winapi – C Win32,如何将下拉菜单添加到Win32 DialogBox

本文发布于:2024-03-07 09:34:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1717462.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   菜单   语言   图片   winapi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!