sppmacd Temat założony przez niniejszego użytkownika |
[WinAPI] Problem przy zwracaniu nieliczbowych wartości z dialogu » 2016-08-25 17:32:32 Witam. Mam problem przy zwracaniu nieliczbowych wartosci z dialogu. Przy kompilacji pojawia sie log: C:\programy\machigen\main.cpp:176:0: error: unterminated argument list invoking macro "DialogBoxA" C:\programy\machigen\main.cpp:7:20: warning: deprecated conversion from string constant to 'LPSTR {aka char*}' [-Wwrite-strings] C:\programy\machigen\main.cpp: In function 'BOOL DlgAddCmd(HWND, UINT, WPARAM, LPARAM)': C:\programy\machigen\main.cpp:108:18: error: jump to case label [-fpermissive] C:\programy\machigen\main.cpp:96:23: error: crosses initialization of 'DWORD dlugosc' C:\programy\machigen\main.cpp:94:22: error: crosses initialization of 'HWND__* hCmd' C:\programy\machigen\main.cpp:93:22: error: crosses initialization of 'HWND__* hCmdName' C:\programy\machigen\main.cpp:90:32: error: crosses initialization of 'ADDCMDDIALOG* ldr' In file included from c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/windows.h:55:0, from C:\programy\machigen\main.cpp:1: c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/winuser.h:4389:19: error: 'DialogBoxA' was not declared in this scope c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/winuser.h:4389:19: error: expected ';' at end of input c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/winuser.h:4389:19: error: expected '}' at end of input c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/winuser.h:4389:19: error: expected '}' at end of input c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/winuser.h:4389:19: error: expected '}' at end of input c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/winuser.h:4389:19: error: expected '}' at end of input Process terminated with status 1 (0 minute(s), 0 second(s)) 12 error(s), 1 warning(s) (0 minute(s), 0 second(s))
Mój kod to:
#include <windows.h> #include <commctrl.h> #include <stdio.h> #include "resource.h"
HINSTANCE hInst; LPSTR NazwaKlasy = "Klasa Okienka"; MSG Komunikat;
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ); BOOL CALLBACK DlgMain( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
HMENU hMenu = LoadMenu( hInst, MAKEINTRESOURCE( 200 ) );
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { WNDCLASSEX wc; wc.cbSize = sizeof( WNDCLASSEX ); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 ); wc.lpszMenuName = NULL; wc.lpszClassName = NazwaKlasy; wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION ); if( !RegisterClassEx( & wc ) ) { MessageBox( NULL, "Wysoka Komisja odmawia rejestracji tego okna!", "Niestety...", MB_ICONEXCLAMATION | MB_OK ); return 1; } HWND hwnd; hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, NazwaKlasy, "MachiGen", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, NULL, hMenu, hInstance, NULL ); if( hwnd == NULL ) { MessageBox( NULL, "Okno odmówi³o przyjœcia na œwiat!", "Ale kicha...", MB_ICONEXCLAMATION ); return 1; } ShowWindow( hwnd, nCmdShow ); UpdateWindow( hwnd ); while( GetMessage( & Komunikat, NULL, 0, 0 ) ) { TranslateMessage( & Komunikat ); DispatchMessage( & Komunikat ); } return Komunikat.wParam; }
BOOL CALLBACK DlgAddCmd( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch( uMsg ) { case WM_INITDIALOG: { } return TRUE; case WM_CLOSE: { EndDialog( hwndDlg, 0 ); } return TRUE; case WM_COMMAND: { switch( LOWORD( wParam ) ) { case IDCANCEL: EndDialog( hwndDlg, IDCANCEL ); break; case IDOK: ADDCMDDIALOG * ldr = new ADDCMDDIALOG(); ZeroMemory( & ldr, sizeof( ADDCMDDIALOG ) ); HWND hCmdName = GetDlgItem( hwndDlg, ADDCMD_CMDNAME ); HWND hCmd = GetDlgItem( hwndDlg, ADDCMD_CMDBNAME ); DWORD dlugosc = GetWindowTextLength( hCmdName ); ldr->StringCmd = new char[ dlugosc + 1 ]; GetWindowText( hCmdName, ldr->StringCmd, dlugosc + 1 ); dlugosc = GetWindowTextLength( hCmd ); ldr->StringCmdName = new char[ dlugosc + 1 ]; GetWindowText( hCmd, ldr->StringCmdName, dlugosc + 1 ); EndDialog( hwndDlg,( int ) ldr ); delete ldr; break; case DEF_CCOMPOSITE: DialogBox( hInst, MAKEINTRESOURCE( DLG_CCREATOR, NULL,( DLGPROC ) DlgAddCmd ); break; } } return TRUE; } return FALSE; }
BOOL CALLBACK DlgMain1( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch( uMsg ) { case WM_INITDIALOG: { } return TRUE; case WM_CLOSE: { EndDialog( hwndDlg, 0 ); } return TRUE; case WM_COMMAND: { switch( LOWORD( wParam ) ) { case IDCANCEL: EndDialog( hwndDlg, IDCANCEL ); } } return TRUE; } return FALSE; }
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_CLOSE: DestroyWindow( hwnd ); break; case WM_DESTROY: PostQuitMessage( 0 ); break; case WM_COMMAND: switch( LOWORD( wParam ) ) { case MI_END: PostQuitMessage( 0 ); break; case MI_ADDCMD: DialogBox( hInst, MAKEINTRESOURCE( DLG_MAIN ), NULL,( DLGPROC ) DlgMain ); break; case MI_CCREATOR: DialogBox( hInst, MAKEINTRESOURCE( DLG_CCREATOR ), NULL,( DLGPROC ) DlgAddCmd ); } default: return DefWindowProc( hwnd, msg, wParam, lParam ); } return 0; }
#ifndef IDC_STATIC #define IDC_STATIC (-1) #endif
#define DEF_CCOMPOSITE 1
#define DLG_MAIN 100 #define DLG_CCREATOR 110
#define MAINMENU 200 #define MI_END 201 #define MI_ADDCMD 202 #define MI_CCREATOR 203
struct ADDCMDDIALOG { char * StringCmd; char * StringCmdName; int cmdX; int cmdY; int cmdZ; }; #define ADDCMD_CNAMELABEL 101 #define ADDCMD_CMDNAME 102 #define ADDCMD_CMDSGBOX 103 #define ADDCMD_CX 104 #define ADDCMD_CY 105 #define ADDCMD_CZ 106 #define ADDCMD_CXL 104 #define ADDCMD_CYL 105 #define ADDCMD_CZL 106 #define ADDCMD_CMDBNAME 107
#include <windows.h> #include <commctrl.h> #include <richedit.h> #include "resource.h"
LANGUAGE 0, SUBLANG_NEUTRAL DLG_MAIN DIALOG 0, 0, 260, 140 STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU CAPTION "New Command Block" FONT 10, "Ms Shell Dlg" { DEFPUSHBUTTON "&Done", IDOK, 70, 120, 50, 15 PUSHBUTTON "&Cancel", IDCANCEL, 130, 120, 50, 15 LTEXT "Command:", ADDCMD_CNAMELABEL, 10, 10, 60, 33 EDITTEXT ADDCMD_CMDNAME, 10, 20, 210, 40, WS_BORDER | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL PUSHBUTTON "Command Creator", DEF_CCOMPOSITE, 150, 5, 70, 15 LTEXT "X:", ADDCMD_CXL, 10, 66, 15, 15 EDITTEXT ADDCMD_CX, 20, 65, 10, 10 LTEXT "Y:", ADDCMD_CYL, 35, 66, 15, 15 EDITTEXT ADDCMD_CY, 45, 65, 10, 10 LTEXT "Z:", ADDCMD_CZL, 60, 66, 15, 15 EDITTEXT ADDCMD_CZ, 70, 65, 10, 10 }
200 MENU { POPUP "&File" { MENUITEM "E&nd\tAlt + F4", MI_END } POPUP "&Edit" { MENUITEM "Add Command\tCtrl + Shift + C", MI_ADDCMD } POPUP "&Help" { MENUITEM "Command Creator", MI_CCREATOR } }
Prosze o pomoc! |