Wie kann ich, in meinem Programm vom Bild paint1 beim Druck auf Paint die Position wechdeln lassen.
Bei mier scheitern alle Versuche.
Das Bild behält immer die zuerst festgelegte Position...
Bei mier scheitern alle Versuche.
Das Bild behält immer die zuerst festgelegte Position...
Code:
//==================================================== MAIN_CPP ====================================================//
#include "StdAfx.h"
#include "functions.h"
//==================================================== Variablen ====================================================//
//==================================================== Var Main ====================================================//
int iMainWindow_width = GetSystemMetrics(SM_CXSCREEN);
int iMainWindow_height = GetSystemMetrics(SM_CYSCREEN);
int iMainWindow_hor = 0;
int iMainWindow_ver = 0;
const LPCWSTR szMainWindow_ClassName = (LPCWSTR)"WndClassEx";
LPCWSTR szMainWindow_Title = (LPCWSTR)"Note Viewer";
WNDCLASSEX MainWindow_WndClassEx;
HWND MainWindow_hWnd;
//==================================================== Var Global ====================================================//
PAINTSTRUCT ps;
HDC hdc;
paint paint1;
int x= 0;
int y= 0;
LPCWSTR x2;
paint paint2;
paint paint3;
//==================================================== Funktionen ====================================================//
MSG Global_msg;
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
bool InitWndClassEx( WNDCLASSEX *WndClassEx, HINSTANCE hInstance, const char* szClassName );
//==================================================== Win Main ====================================================//
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow )
{
//==================================================== REGISTRIERUNG ====================================================//
MainWindow_WndClassEx.cbSize = sizeof( WNDCLASSEX );
MainWindow_WndClassEx.style = NULL;
MainWindow_WndClassEx.lpfnWndProc = WndProc;
MainWindow_WndClassEx.cbClsExtra = NULL;
MainWindow_WndClassEx.cbWndExtra = NULL;
MainWindow_WndClassEx.hInstance = hInstance;
MainWindow_WndClassEx.hIcon = LoadIcon (NULL, IDI_WINLOGO);
MainWindow_WndClassEx.hCursor = LoadCursor (NULL, IDC_ARROW);
MainWindow_WndClassEx.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
MainWindow_WndClassEx.lpszMenuName = NULL;
MainWindow_WndClassEx.lpszClassName = szMainWindow_ClassName;
MainWindow_WndClassEx.hIconSm = LoadIcon (NULL, IDI_WINLOGO);
if( !RegisterClassEx( &MainWindow_WndClassEx ) )
{
MessageBox( NULL, L"MainWindow_WndClassEx failed.", L"Error", MB_OK | MB_ICONERROR );
return false;
}
//==================================================== FENSTER ERSTELLEN ====================================================//
//==================================================== MainWindow_hWnd ====================================================//
MainWindow_hWnd = CreateWindowEx( WS_EX_TOPMOST,
szMainWindow_ClassName,
szMainWindow_Title,
WS_POPUP | WS_VISIBLE,
iMainWindow_hor,
iMainWindow_ver,
iMainWindow_width,
iMainWindow_height,
NULL,
NULL,
hInstance,
NULL );
if( MainWindow_hWnd == NULL )
{
MessageBox( NULL, L"Create MainWindow_hWnd failed.", L"Error", MB_OK );
return 0;
}
while( GetMessage( &Global_msg, MainWindow_hWnd, NULL, NULL ) > NULL )
{
TranslateMessage( &Global_msg );
DispatchMessage( &Global_msg );
}//while
return 0;
}//WinMain
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){
switch( msg )
{
//==================================================== Fenster Schließen ====================================================//
case WM_DESTROY:
PostQuitMessage(0);
break;
//==================================================== Tastenabfrage ====================================================//
case WM_KEYDOWN:
switch(wParam)
{
//==================================================== Escape ====================================================//
case VK_ESCAPE:
PostMessage(MainWindow_hWnd,WM_CLOSE,0,0);
break;
//==================================================== Space ====================================================//
case VK_SPACE:
PostMessage(MainWindow_hWnd,WM_CLOSE,0,0);
break;
}//wParam
break;
//==================================================== WM_CREATE ====================================================//
case WM_CREATE:
paint1.loadBmp(L"test.bmp", 400, 400);
paint2.loadBmp(L"test2.bmp", 800, 400);
break;
//==================================================== Malen ====================================================//
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
paint1.loadBmp(L"test.bmp", 400, 400);
paint1.drawBmp(hWnd, ps, hdc);
paint2.drawBmp(hWnd, ps, hdc);
EndPaint(hWnd, &ps);
break;
//==================================================== Default ====================================================//
default :
return DefWindowProc( hWnd, msg, wParam, lParam );
}//switch(msg)
return 0;
}//LRESULT
#include "StdAfx.h"
#include "functions.h"
void paint::loadBmp(LPCWSTR bmpPath, int hor, int ver)
{
this->bmpHor= hor;
this->bmpVer = ver;
this->bmpPath = bmpPath;
this->hBitmap = (HBITMAP)LoadImage(this->hInstancePicture, bmpPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
}
void paint::drawBmp(HWND hWnd, PAINTSTRUCT ps, HDC hdc)
{
this->hdcMem = CreateCompatibleDC(hdc);
this->oldBitmap = SelectObject( this->hdcMem, this->hBitmap);
GetObject (this->hBitmap, sizeof(this->bitmap), &this->bitmap);
BitBlt ( hdc, this->bmpHor, this->bmpVer, this->bitmap.bmWidth, this->bitmap.bmHeight, this->hdcMem,0, -0, SRCCOPY);
SelectObject (this->hdcMem, this->oldBitmap);
DeleteDC (this->hdcMem);
}
#include "StdAfx.h"
class paint
{
private:
HBITMAP hBitmap;
BITMAP bitmap;
HDC hdcMem;
HGDIOBJ oldBitmap;
HINSTANCE hInstancePicture;
LPCWSTR bmpPath;
int bmpHor;
int bmpVer;
public:
void loadBmp(LPCWSTR bmpPath, int hor, int ver);
void drawBmp(HWND hWnd, PAINTSTRUCT ps, HDC hdc);
};