Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
#include <windows.h> #include <tchar.h> LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); LRESULT CALLBACK DragDropProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { static PTCHAR cls_name = _T( "cls_test" ); WNDCLASS wc = { 0, WndProc, 0, 0, hInstance, LoadIcon( NULL, IDI_APPLICATION ), LoadCursor( NULL, IDC_ARROW ), GetSysColorBrush( COLOR_BTNFACE ), NULL, cls_name }; if ( !RegisterClass( &wc ) ) { return 0; } HWND hWnd = CreateWindow( cls_name, _T( "Test" ), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL ); if ( !hWnd ) { return 0; } // Create Control HWND hWndChild = CreateWindowEx( WS_EX_CLIENTEDGE, _T( "LISTBOX" ), _T( "" ), WS_CHILD | WS_VISIBLE, 10, 10, 250, 250, hWnd, NULL, hInstance, NULL ); if ( hWndChild ) { DragAcceptFiles( hWndChild, TRUE ); WNDPROC dragDropProc = MakeProcInstance( DragDropProc, hInstance ); if ( dragDropProc ) { WNDPROC oldProc = ( WNDPROC )SetWindowLong( hWndChild, GWL_WNDPROC, ( LONG )dragDropProc ); SetWindowLong( hWndChild, GWL_USERDATA, ( LONG )oldProc ); } } ShowWindow( hWnd, SW_SHOW ); UpdateWindow( hWnd ); MSG msg; while ( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } LRESULT CALLBACK DragDropProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { WNDPROC fwdProc = ( WNDPROC )GetWindowLong( hWnd, GWL_USERDATA ); switch ( msg ) { case WM_DROPFILES: { HDROP hDrop = ( HDROP )wParam; UINT count = DragQueryFile( hDrop, -1, 0, 0 ); TCHAR file[MAX_PATH]; for ( UINT i = 0; i < count; ++i ) { DragQueryFile( hDrop, i, file, MAX_PATH ); SendMessage( hWnd, LB_ADDSTRING, 0, ( LPARAM )file ); } DragFinish( hDrop ); } break; default: return fwdProc != NULL ? CallWindowProc( fwdProc, hWnd, msg, wParam, lParam ) : 0; } return 0; } LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch ( msg ) { case WM_CLOSE: PostQuitMessage(0); break; default: return DefWindowProc( hWnd, msg, wParam, lParam ); } return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
#include <windows.h> #include <tchar.h> #include <CommCtrl.h> LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); LRESULT CALLBACK DragDropProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { static PTCHAR cls_name = _T( "cls_test" ); WNDCLASS wc = { 0, WndProc, 0, 0, hInstance, LoadIcon( NULL, IDI_APPLICATION ), LoadCursor( NULL, IDC_ARROW ), GetSysColorBrush( COLOR_BTNFACE ), NULL, cls_name }; if ( !RegisterClass( &wc ) ) { return 0; } HWND hWnd = CreateWindow( cls_name, _T( "Test" ), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL ); if ( !hWnd ) { return 0; } // Create Control HWND hWndChild = CreateWindowEx( WS_EX_CLIENTEDGE, WC_LISTVIEW, _T( "" ), WS_CHILD | WS_VISIBLE | LVS_REPORT, 10, 10, 250, 250, hWnd, NULL, hInstance, NULL ); if ( hWndChild ) { LVCOLUMN column; column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; column.fmt = LVCFMT_LEFT; column.cx = 250; column.pszText = _T( "Dateiname" ); ListView_InsertColumn( hWndChild, 0, &column ); DragAcceptFiles( hWndChild, TRUE ); WNDPROC dragDropProc = MakeProcInstance( DragDropProc, hInstance ); if ( dragDropProc ) { WNDPROC oldProc = ( WNDPROC )SetWindowLong( hWndChild, GWL_WNDPROC, ( LONG )dragDropProc ); SetWindowLong( hWndChild, GWL_USERDATA, ( LONG )oldProc ); } } ShowWindow( hWnd, SW_SHOW ); UpdateWindow( hWnd ); MSG msg; while ( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } LRESULT CALLBACK DragDropProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { WNDPROC fwdProc = ( WNDPROC )GetWindowLong( hWnd, GWL_USERDATA ); switch ( msg ) { case WM_DROPFILES: { HDROP hDrop = ( HDROP )wParam; UINT count = DragQueryFile( hDrop, -1, 0, 0 ); TCHAR file[MAX_PATH]; for ( UINT i = 0; i < count; ++i ) { DragQueryFile( hDrop, i, file, MAX_PATH ); LVITEM item = {0}; item.mask = LVIF_TEXT; item.pszText = file; ListView_InsertItem( hWnd, &item ); } DragFinish( hDrop ); } break; default: return fwdProc != NULL ? CallWindowProc( fwdProc, hWnd, msg, wParam, lParam ) : 0; } return 0; } LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch ( msg ) { case WM_CLOSE: PostQuitMessage(0); break; default: return DefWindowProc( hWnd, msg, wParam, lParam ); } return 0; } |
C-/C++-Quelltext |
|
1 2 3 |
Window::CreateParams wndparams("titel", 520, 520); wndparams.windowstyle = WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX; window = CreateNewWindow(&wndparams); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Window::CreateParams::CreateParams(const char *ptitle, unsigned uwidth, unsigned uheight) { title = ptitle; width = uwidth; height = uheight; classname = 0; x = CW_USEDEFAULT; y = CW_USEDEFAULT; func = 0; extendedstyle = 0; windowstyle = WS_BORDER | WS_SYSMENU; classstyle = CS_HREDRAW | CS_VREDRAW; menu = false; fullscreen = false; clientrect = true; exit_on_close = true; visible = true; background = RGB(255, 255, 255); parent = 0; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
CWindow::CWindow(const CreateParams *p) { INITCOMMONCONTROLSEX InitCtrlEx; InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX); InitCtrlEx.dwICC = ICC_PROGRESS_CLASS; InitCommonControlsEx(&InitCtrlEx); params = *p; id = 2; painting = 0; memdc = 0; membitmap = 0; oldbitmap = 0; menu = 0; deleteonclose = false; DWORD counter = GetTickCount(); // unique windowname classname[0 ] = 'W'; classname[1 ] = 'i'; classname[2 ] = 'n'; classname[3 ] = 'd'; classname[4 ] = 'o'; classname[5 ] = 'w'; classname[6 ] = ' '; classname[7 ] = static_cast<char>((counter >> 0) & 0xff); classname[8 ] = static_cast<char>((counter >> 8) & 0xff); classname[9 ] = static_cast<char>((counter >> 16) & 0xff); classname[10] = static_cast<char>((counter >> 24) & 0xff); classname[11] = 0; if (params.classname) strcpy(classname, params.classname); if (!params.windowstyle) params.windowstyle = WS_OVERLAPPEDWINDOW; if (params.fullscreen) { params.x = 0; params.y = 0; params.width = GetSystemMetrics(SM_CXSCREEN); params.height = GetSystemMetrics(SM_CYSCREEN); params.windowstyle = WS_POPUP; } else if (params.clientrect) { RECT r; SetRect(&r, 0, 0, params.width, params.height); AdjustWindowRect(&r, params.windowstyle | WS_CAPTION, params.menu ? 1 : 0); params.width = r.right - r.left; params.height = r.bottom - r.top; } WNDCLASS wc; ZeroMemory(&wc, sizeof(wc)); wc.cbWndExtra = sizeof(this); // space for a pointer to CWindow (this-pointer) wc.hbrBackground = background = CreateSolidBrush(params.background); wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hIcon = 0; wc.hInstance = GetModuleHandle(0); wc.lpfnWndProc = WindowProc; wc.lpszClassName = classname; wc.lpszMenuName = 0; wc.style = params.classstyle; RegisterClass(&wc); // *never* fails hWnd = CreateWindowEx(params.extendedstyle | (params.fullscreen ? WS_EX_TOPMOST : 0), wc.lpszClassName, params.title, params.windowstyle, params.x, params.y, params.width, params.height, params.parent, 0, wc.hInstance, this); if (hWnd && params.visible) ShowWindow(hWnd, SW_SHOWNORMAL); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
int WINAPI WinMain(HINSTANCE, HINSTANCE, char *, int) { OleInitialize(0); InitCommonControls(); Application app; app.Run(); return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
Application::Application() { Window::CreateParams wndparams("title", 520, 520); wndparams.windowstyle = WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX; window = CreateNewWindow(&wndparams); net = CreateNewNetwork(); window->UserPointer() = this; window->SetWindowFunction(WinApiWindowFunc); // allerlei controlls erzeugen HWND hWndChild = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, "", WS_CHILD | WS_VISIBLE | LVS_REPORT, 280, 90, 220, 150, window->GetHandle(), 0, GetModuleHandle(0), 0); if ( hWndChild ) { LVCOLUMN column; column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; column.fmt = LVCFMT_LEFT; column.cx = 250; column.pszText = "Dateiname"; ListView_InsertColumn( hWndChild, 0, &column ); DragAcceptFiles( hWndChild, TRUE ); WNDPROC dragDropProc = DragDropProc; if ( dragDropProc ) { WNDPROC oldProc = ( WNDPROC )SetWindowLong( hWndChild, GWL_WNDPROC, ( LONG )dragDropProc ); SetWindowLong( hWndChild, GWL_USERDATA, ( LONG )oldProc ); } } // ... |
Werbeanzeige