Skocz do zawartości

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Zdjęcie
C++

Wyświetlanie zdjęcia na pulpicie

c++ c++ drawimage

Najlepsza odpowiedź Booom, 06.10.2019 11:46

Użyłem SetWindowLong oraz  ShowScrollBar   Dzięki

 

Poniżej daję kod gdyby ktoś potrzebował

#include <windows.h>
#include <tchar.h>

HBITMAP hBitmap;
HDC localDC;
HBITMAP hOld;
BITMAP qB;
HDC hDC;                                             // Handle (virtual memory pointer) to drawing characteristics

LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam) {
	switch (msg) {
	case WM_CREATE: {
		//MessageBox(hwnd,_T("Window Procedure Received WM_CREATE Message!"),_T("Message Report!"),MB_OK);
		return 0;
	}
	case WM_LBUTTONDOWN: {
		//MessageBox(hwnd,_T("Window Procedure Received WM_LBUTTONDOWN Message!"),_T("Message Report!"),MB_OK);
		return 0;
	}

	case WM_PAINT: {                  //At program start up the whole window is invalid so must be drawn.
		//TCHAR tmpText[]=_T("TempText");
		PAINTSTRUCT ps;
		hDC = BeginPaint(hwnd, &ps);
		BOOL qRetBlit = ::BitBlt(hDC, 0, 0, qB.bmWidth, qB.bmHeight, localDC, 0, 0, SRCCOPY);
		// Draw text on top of the image
		//int iBkMode=SetBkMode(hDC,TRANSPARENT);                   // Save Background Mode characteristic of drawing context
		//TextOut(hDC,40,20,tmpText,(int)_tcslen(tmpText));     // Draw Text
		//SetBkMode(hDC,iBkMode);                                       // Return Drawing Context To Original State
		EndPaint(hwnd, &ps);
		return 0;
	}
	case WM_DESTROY: {
		::SelectObject(localDC, hOld);
		::DeleteDC(localDC);
		::DeleteObject(hBitmap);
		PostQuitMessage(0);
		return 0;
	}
	}
	return (DefWindowProc(hwnd, msg, wParam, lParam));
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int iShow) {
	TCHAR szClassName[] = _T("Name");
	WNDCLASSEX wc;
	MSG messages;
	HWND hWnd;

	wc.lpszClassName = szClassName;                     //Important Field!  Character string identifying window class
	wc.lpfnWndProc = fnWndProc;                       //Important Field!  Function Pointer.  Address of Window Procedure
	wc.cbSize = sizeof(WNDCLASSEX);             //Those top two fields I just listed are very important.  The
	wc.style = 0;                               //others are of course necessary too, but fully understanding all
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);  //the implications of the .szClassName and .lpfnWndProc fields will
	wc.hInstance = hInstance;                       //go a long way to helping you understand Win32 coding. The
	wc.hIconSm = 0;                               //.hBrushBackground field will be the color of the Window's
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);      //background.  The .cbWndExtra field is very useful as it allows
	wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;         //you to associate object (Window) data to the instantiated Window's
	wc.cbWndExtra = 0;                               //internal structure, i.e., accomodate member data.
	wc.cbClsExtra = 0;
	wc.lpszMenuName = NULL;
	RegisterClassEx(&wc);
	hBitmap = (HBITMAP)::LoadImage(NULL, TEXT("c1.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
	GetObject(reinterpret_cast<HGDIOBJ>(hBitmap), sizeof(BITMAP), reinterpret_cast<LPVOID>(&qB));
	localDC = ::CreateCompatibleDC(hDC);
	hOld = (HBITMAP)::SelectObject(localDC, hBitmap);

	hWnd = CreateWindowEx(0, szClassName, szClassName, WS_OVERLAPPEDWINDOW, 0, 0, qB.bmWidth, qB.bmHeight, HWND_DESKTOP, 0, hInstance, 0);

	LONG lStyle = GetWindowLong(hWnd, GWL_STYLE);

	lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);

	SetWindowLong(hWnd, GWL_STYLE, lStyle);
	ShowScrollBar(hWnd, SB_VERT, FALSE);
	ShowWindow(hWnd, iShow);

	while (GetMessage(&messages, NULL, 0, 0)) {
		TranslateMessage(&messages);
		DispatchMessage(&messages);
	}
	return (int)messages.wParam;
}
Przejdź do postu


  • Nie możesz napisać tematu
  • Zaloguj się, aby dodać odpowiedź
6 odpowiedzi w tym temacie

#1 Booom

    Nowy

  • Użytkownik

Reputacja: 1
Nowy

  • Postów:6
  • Imię:Sebastian
Offline

Napisano 01.10.2019 11:14

Witam. Chciałbym napisać program, który wyświetla zdjęcie na pulpicie bez okna. Znalazłem jeden kod, ale nie mogę go skompilować

 

W załączniku dodaję przykładowe zdjęcie. z góry dziękuję

 

 

Załączone miniatury

  • c1.png

  • +
  • -
  • 0

#2 Booom

    Nowy

  • Autor tematu
  • Użytkownik

Reputacja: 1
Nowy

  • Postów:6
  • Imię:Sebastian
Offline

Napisano 03.10.2019 10:05

#include <windows.h>
#include <tchar.h>

HBITMAP hBitmap;
HDC localDC;
HBITMAP hOld;
BITMAP qB;
HDC hDC;                                             // Handle (virtual memory pointer) to drawing characteristics

LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam) {
	switch (msg) {
	case WM_CREATE: {
		//MessageBox(hwnd,_T("Window Procedure Received WM_CREATE Message!"),_T("Message Report!"),MB_OK);
		return 0;
	}
	case WM_LBUTTONDOWN: {
		//MessageBox(hwnd,_T("Window Procedure Received WM_LBUTTONDOWN Message!"),_T("Message Report!"),MB_OK);
		return 0;
	}

	case WM_PAINT: {                  //At program start up the whole window is invalid so must be drawn.
		//TCHAR tmpText[]=_T("TempText");
		PAINTSTRUCT ps;
		hDC = BeginPaint(hwnd, &ps);
		BOOL qRetBlit = ::BitBlt(hDC, 0, 0, qB.bmWidth, qB.bmHeight, localDC, 0, 0, SRCCOPY);
		// Draw text on top of the image
		//int iBkMode=SetBkMode(hDC,TRANSPARENT);                   // Save Background Mode characteristic of drawing context
		//TextOut(hDC,40,20,tmpText,(int)_tcslen(tmpText));     // Draw Text
		//SetBkMode(hDC,iBkMode);                                       // Return Drawing Context To Original State
		EndPaint(hwnd, &ps);
		return 0;
	}
	case WM_DESTROY: {
		::SelectObject(localDC, hOld);
		::DeleteDC(localDC);
		::DeleteObject(hBitmap);
		PostQuitMessage(0);
		return 0;
	}
	}
	return (DefWindowProc(hwnd, msg, wParam, lParam));
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int iShow) {
	TCHAR szClassName[] = _T("Name");
	WNDCLASSEX wc;
	MSG messages;
	HWND hWnd;

	wc.lpszClassName = szClassName;                     //Important Field!  Character string identifying window class
	wc.lpfnWndProc = fnWndProc;                       //Important Field!  Function Pointer.  Address of Window Procedure
	wc.cbSize = sizeof(WNDCLASSEX);             //Those top two fields I just listed are very important.  The
	wc.style = 0;                               //others are of course necessary too, but fully understanding all
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);  //the implications of the .szClassName and .lpfnWndProc fields will
	wc.hInstance = hInstance;                       //go a long way to helping you understand Win32 coding. The
	wc.hIconSm = 0;                               //.hBrushBackground field will be the color of the Window's
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);      //background.  The .cbWndExtra field is very useful as it allows
	wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;         //you to associate object (Window) data to the instantiated Window's
	wc.cbWndExtra = 0;                               //internal structure, i.e., accomodate member data.
	wc.cbClsExtra = 0;
	wc.lpszMenuName = NULL;
	RegisterClassEx(&wc);
	hBitmap = (HBITMAP)::LoadImage(NULL, (LPCTSTR)"c1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
	GetObject(reinterpret_cast<HGDIOBJ>(hBitmap), sizeof(BITMAP), reinterpret_cast<LPVOID>(&qB));
	localDC = ::CreateCompatibleDC(hDC);
	hOld = (HBITMAP)::SelectObject(localDC, hBitmap);

	hWnd = CreateWindowEx(0, szClassName, szClassName, WS_OVERLAPPEDWINDOW, 0, 0, qB.bmWidth, qB.bmHeight, HWND_DESKTOP, 0, hInstance, 0);
	ShowWindow(hWnd, iShow);
	while (GetMessage(&messages, NULL, 0, 0)) {
		TranslateMessage(&messages);
		DispatchMessage(&messages);
	}
	return (int)messages.wParam;
}

Znalazłem taki kod, lecz wyświetla tylko puste okno bez zdjęcia :/ Jaka może być przyczyna ?


  • +
  • -
  • 0

#3 DarkGL

    Nie oddam ciasteczka !

  • Administrator

Reputacja: 6 552
Godlike

  • Postów:11 974
  • GG:
  • Steam:steam
  • Imię:Rafał
  • Lokalizacja:Warszawa
Offline

Napisano 03.10.2019 11:36

plik c1.bmp jest w folderze z exe ?
  • +
  • -
  • 1

#4 Booom

    Nowy

  • Autor tematu
  • Użytkownik

Reputacja: 1
Nowy

  • Postów:6
  • Imię:Sebastian
Offline

Napisano 03.10.2019 21:57

Tak oczywiście


  • +
  • -
  • 0

#5 Booom

    Nowy

  • Autor tematu
  • Użytkownik

Reputacja: 1
Nowy

  • Postów:6
  • Imię:Sebastian
Offline

Napisano 05.10.2019 12:54

Pomogła zmiana z 

(LPCTSTR)"c1.bmp"

na

TEXT("c1.bmp")

Tylko że zdjęcie jest w oknie. Jak można się pozbyć okna, albo zrobić je niewidzialne ?


  • +
  • -
  • 0

#6 Rivit

    Godlike

  • Support Team

Reputacja: 1 319
Godlike

  • Postów:4 380
Offline

Napisano 05.10.2019 13:23

Patrzyłeś tu: https://docs.microso...g/window-styles ?


  • +
  • -
  • 1

#7 Booom

    Nowy

  • Autor tematu
  • Użytkownik

Reputacja: 1
Nowy

  • Postów:6
  • Imię:Sebastian
Offline

Napisano 06.10.2019 11:46   Najlepsza odpowiedź

Użyłem SetWindowLong oraz  ShowScrollBar   Dzięki

 

Poniżej daję kod gdyby ktoś potrzebował

#include <windows.h>
#include <tchar.h>

HBITMAP hBitmap;
HDC localDC;
HBITMAP hOld;
BITMAP qB;
HDC hDC;                                             // Handle (virtual memory pointer) to drawing characteristics

LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam) {
	switch (msg) {
	case WM_CREATE: {
		//MessageBox(hwnd,_T("Window Procedure Received WM_CREATE Message!"),_T("Message Report!"),MB_OK);
		return 0;
	}
	case WM_LBUTTONDOWN: {
		//MessageBox(hwnd,_T("Window Procedure Received WM_LBUTTONDOWN Message!"),_T("Message Report!"),MB_OK);
		return 0;
	}

	case WM_PAINT: {                  //At program start up the whole window is invalid so must be drawn.
		//TCHAR tmpText[]=_T("TempText");
		PAINTSTRUCT ps;
		hDC = BeginPaint(hwnd, &ps);
		BOOL qRetBlit = ::BitBlt(hDC, 0, 0, qB.bmWidth, qB.bmHeight, localDC, 0, 0, SRCCOPY);
		// Draw text on top of the image
		//int iBkMode=SetBkMode(hDC,TRANSPARENT);                   // Save Background Mode characteristic of drawing context
		//TextOut(hDC,40,20,tmpText,(int)_tcslen(tmpText));     // Draw Text
		//SetBkMode(hDC,iBkMode);                                       // Return Drawing Context To Original State
		EndPaint(hwnd, &ps);
		return 0;
	}
	case WM_DESTROY: {
		::SelectObject(localDC, hOld);
		::DeleteDC(localDC);
		::DeleteObject(hBitmap);
		PostQuitMessage(0);
		return 0;
	}
	}
	return (DefWindowProc(hwnd, msg, wParam, lParam));
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int iShow) {
	TCHAR szClassName[] = _T("Name");
	WNDCLASSEX wc;
	MSG messages;
	HWND hWnd;

	wc.lpszClassName = szClassName;                     //Important Field!  Character string identifying window class
	wc.lpfnWndProc = fnWndProc;                       //Important Field!  Function Pointer.  Address of Window Procedure
	wc.cbSize = sizeof(WNDCLASSEX);             //Those top two fields I just listed are very important.  The
	wc.style = 0;                               //others are of course necessary too, but fully understanding all
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);  //the implications of the .szClassName and .lpfnWndProc fields will
	wc.hInstance = hInstance;                       //go a long way to helping you understand Win32 coding. The
	wc.hIconSm = 0;                               //.hBrushBackground field will be the color of the Window's
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);      //background.  The .cbWndExtra field is very useful as it allows
	wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;         //you to associate object (Window) data to the instantiated Window's
	wc.cbWndExtra = 0;                               //internal structure, i.e., accomodate member data.
	wc.cbClsExtra = 0;
	wc.lpszMenuName = NULL;
	RegisterClassEx(&wc);
	hBitmap = (HBITMAP)::LoadImage(NULL, TEXT("c1.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
	GetObject(reinterpret_cast<HGDIOBJ>(hBitmap), sizeof(BITMAP), reinterpret_cast<LPVOID>(&qB));
	localDC = ::CreateCompatibleDC(hDC);
	hOld = (HBITMAP)::SelectObject(localDC, hBitmap);

	hWnd = CreateWindowEx(0, szClassName, szClassName, WS_OVERLAPPEDWINDOW, 0, 0, qB.bmWidth, qB.bmHeight, HWND_DESKTOP, 0, hInstance, 0);

	LONG lStyle = GetWindowLong(hWnd, GWL_STYLE);

	lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);

	SetWindowLong(hWnd, GWL_STYLE, lStyle);
	ShowScrollBar(hWnd, SB_VERT, FALSE);
	ShowWindow(hWnd, iShow);

	while (GetMessage(&messages, NULL, 0, 0)) {
		TranslateMessage(&messages);
		DispatchMessage(&messages);
	}
	return (int)messages.wParam;
}

  • +
  • -
  • 1





Również z jednym lub większą ilością słów kluczowych: c++, c++ drawimage

Użytkownicy przeglądający ten temat: 0

0 użytkowników, 0 gości, 0 anonimowych