Ich versuche, Text auf einem einfachen Begrüßungsbildschirm zu zeichnen, der eine Bitmap und sonst nichts anzeigt. Unten ist mein Code. Die Bitmap wird ordnungsgemäß, aber ohne Text angezeigt. Was mache ich falsch?Text auf Bitmap-Begrüßungsbildschirm (MFC) zeichnen
Ich bin verpflichtet, einige weitere "Details" vor dem Posten hinzuzufügen, weil dies vor allem Code ist: Ich bin mir nicht sicher, wo der Autor dieses Beispiel bekommen hat. Ich kann kein Beispiel für das Zeichnen von Text auf einer Bitmap finden, das der Vorgehensweise entspricht. Dank
Splash.cpp
#include "stdafx.h"
#include "Splash.h"
Splash::Splash()
{
bool b = false; //debugging
}
Splash::~Splash()
{
DestroyWindow(hSplashWnd);
}
void Splash::Init(HWND hWnd,HINSTANCE hInst,int resid)
{
hParentWindow=hWnd;
hSplashWnd=CreateWindowEx(WS_EX_CLIENTEDGE,"STATIC","",
WS_POPUP|WS_DLGFRAME|SS_BITMAP,300,300,300,300,hWnd,NULL,hInst,NULL);
SendMessage(hSplashWnd,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)LoadBitmap(hInst,MAKEINTRESOURCE(resid)));
this->SHOWING = FALSE;
}
void Splash::Show()
{
//get size of hSplashWnd (width and height)
int x, y;
int pwidth, pheight;
int tx, ty;
HDWP windefer;
RECT rect, prect;
GetClientRect(hSplashWnd,&rect);
x=rect.right;
y=rect.bottom;
//get parent screen coordinates
GetWindowRect(this->hParentWindow,&prect);
//center splash window on parent window
pwidth=prect.right-prect.left;
pheight=prect.bottom - prect.top;
int iScreenWidth, iScreenHeight, iSplashLeft, iSplashTop;
iScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
iScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
if(prect.left > iScreenWidth)
{
//On second monitor
iSplashLeft = iScreenWidth + (iScreenWidth/2) - ((rect.right - rect.left)/2);
}
else
{
//On first monitor
iSplashLeft = (iScreenWidth/2) - ((rect.right - rect.left)/2);
}
iSplashTop = (iScreenHeight/2) - ((rect.bottom - rect.top) /2);
tx = iSplashLeft;
ty = iSplashTop;
windefer=BeginDeferWindowPos(1);
DeferWindowPos(windefer,hSplashWnd,HWND_NOTOPMOST,tx,ty,50,50,SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOZORDER);
EndDeferWindowPos(windefer);
BOOL isValidWindow = IsWindow(hSplashWnd);
//##################### Draw text on the bitmap ###############
CBrush brush;
brush.CreateSolidBrush(RGB(255,0,0));
HDC hdc = GetDC(hSplashWnd);
char *text = "HELLO HELLO HELLO HELLO HELLO HELLO";
SelectObject(hdc, brush);
SetTextColor(hdc, RGB(0,255,0));
DrawTextA(hdc, text, strlen(text), &rect, DT_SINGLELINE | DT_LEFT); //DT_CENTER | DT_VCENTER);
ShowWindow(hSplashWnd,SW_SHOWNORMAL);
UpdateWindow(hSplashWnd);
this->SHOWING = TRUE;
}
void Splash::Hide()
{
ShowWindow(hSplashWnd,SW_HIDE);
this->SHOWING = FALSE;
}
Splash.h
#if !defined(AFX_SPLASH_H_INCLUDED)
#define AFX_SPLASH_H_INCLUDED
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class Splash
{
public:
void Hide();
void Show();
void Init(HWND hWnd,HINSTANCE hInst,int resid);
BOOL SHOWING;
Splash();
virtual ~Splash();
private:
UINT TimerID;
HWND hParentWindow;
HWND hSplashWnd;
};
#endif
den Bildschirm spritzen Draw:
Splash Splash1;
Splash1.Init(m_pMainWnd->m_hWnd, this->m_hInstance, IDB_BITMAP_SPLASH);
Splash.Show();
Sleep(3000);
Splash1.Hide;
Was passiert, wenn das Begrüßungsfenster ein WM_PAINT empfängt, nachdem Sie den Text gezeichnet haben? – zett42
Es wird das Fenster mit der Bitmap aktualisieren. Aber wenn Sie nicht mit Ihrem Zeichencode umgehen, wird Ihr "HALLO" verschwinden. Für einen Begrüßungsbildschirm möchten Sie sich vielleicht keine Sorgen machen. Es gibt einen besseren Code da draußen. Schau dir ein Microsoft-Beispiel an. – lakeweb
Hat dies Ihre Frage beantwortet? – lakeweb