Jump to content
Tuts 4 You

Vertical text Scrolling


Dragon Warrior

Recommended Posts

Dragon Warrior

Hello Guys,

I was looking for a vertical text scroll engine or lib or simple sample code like u see in the about box of keygen or nfo viewer. I found diablo2oo2's scroll text lib, but it works for text horizontally. I tried downloaded some sample codes of keygen, but they include all extra things and the code is too complex to look at to figure out just how it making the text scroll vertical moving bottom-to-top n top-to-button. Can any one just put a small easy to understand sample code or hints without using any bitmap or effects. Juts simply a dialog box n text scrolling..

Thanks in advance...

Link to comment

// Setup scroller
int nLines = 0;
LPSTR lpszLine = lpszAboutText;
while(*lpszLine){
if(*lpszLine == '\n') nLines++;
lpszLine++;
}
SIZE szAboutText; HDC hdc = GetDC(hWnd);
hdcText = CreateCompatibleDC(hdc);
ndcText = SaveDC(hdcText); HFONT hfAbout = CreateFontIndirectA(&lfVerdana);
SelectObject(hdcText, hfAbout);
GetTextExtentPoint32A(hdcText, lpszAboutText, strlen(lpszAboutText), &szAboutText);
CopyRect(&rcText, &rcClient);
rcText.bottom += (szAboutText.cy * nLines);
hbmText = CreateCompatibleBitmap(hdc, rcText.right, rcText.bottom);
SelectObject(hdcText, hbmText);
ReleaseDC(hWnd, hdc); SetBkMode(hdcText, TRANSPARENT);
SetTextColor(hdcText, RGB(255, 255, 255));
rcText.top += rcClient.bottom;
DrawTextA(hdcText, lpszAboutText, strlen(lpszAboutText), &rcText, DT_CENTER);
DeleteObject(hfAbout); nOffset = 0; nOffsetMax = rcText.bottom;
SetTimer(hWnd, 1, 60, NULL);

Cheers,

Edited by SSlEvIN
Link to comment
Dragon Warrior

Please speak any more suggestions if anyone still have to say on this, though I didn't got the time to try this code yet.. I would like to know more on this if any. Will ask here for improvements later after trying it :)

Thanx

Edited by Dragon Warrior
Link to comment

.....................................................................
#pragma comment(lib, "msimg32.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdiplus.lib")#include <windows.h>
#include <commctrl.h>
#include <olectl.h>
#include <ole2.h>
#include"resource.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <Winuser.h>
#include <gdiplus.h>
..........................................................................................................................................
LOGFONTA lfVerdana = { -11, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 1, 34, "Courier New" };
LPSTR lpszAboutText =
"Some Text Here\n\n"
"Some Text Here \n"
"Some Text Here"
"\nSome Text Here\n\n"
"\nSome Text Here\n"
"-----------\n"
"Some Text Here\n"
"Some Text Here\n"
"Some Text Here\n\n"
"Some Text Here\n\n"
"Some Text Here\n"
"Some Text Here\n\n\n"
"Some Text Here\n\n";
..................................................................................................
BOOL CALLBACK AboutProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HBITMAP hbmText;
static HDC hdcText;
static int ndcText, nOffset, nOffsetMax; switch(uMsg)
{
case WM_INITDIALOG:
{
SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_TOPMOST);
hUserDll = LoadLibraryA("USER32.dll"); RECT rcClient, rcText;
GetClientRect(hWnd, &rcClient);
} // Setup scroller
int nLines = 0;
LPSTR lpszLine = lpszAboutText;
while(*lpszLine){
if(*lpszLine == '\n') nLines++;
lpszLine++;
}
SIZE szAboutText; HDC hdc = GetDC(hWnd);
hdcText = CreateCompatibleDC(hdc);
ndcText = SaveDC(hdcText); HFONT hfAbout = CreateFontIndirectA(&lfVerdana);
SelectObject(hdcText, hfAbout);
GetTextExtentPoint32A(hdcText, lpszAboutText, strlen(lpszAboutText), &szAboutText);
CopyRect(&rcText, &rcClient);
rcText.bottom += (szAboutText.cy * nLines);
hbmText = CreateCompatibleBitmap(hdc, rcText.right, rcText.bottom);
SelectObject(hdcText, hbmText);
ReleaseDC(hWnd, hdc); SetBkMode(hdcText, TRANSPARENT);
SetTextColor(hdcText, RGB(255, 255, 255); <-------- White text
rcText.top += rcClient.bottom;
DrawTextA(hdcText, lpszAboutText, strlen(lpszAboutText), &rcText, DT_CENTER);
DeleteObject(hfAbout); nOffset = 0; nOffsetMax = rcText.bottom;
SetTimer(hWnd, 1, 60, NULL);
}
return TRUE; case WM_TIMER:
{
RECT rcClient;
GetClientRect(hWnd, &rcClient); }
if(nOffset < nOffsetMax) nOffset += 1;
else nOffset = 0;
InvalidateRect(hWnd, NULL, FALSE);
}
return 0; case WM_LBUTTONDOWN:
SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
return TRUE; case WM_RBUTTONUP: SendMessage(hWnd, WM_CLOSE, 0, 0);
return TRUE; case WM_CLOSE:
KillTimer(hWnd, 1);
RestoreDC(hdcText, ndcText);
DeleteObject(hbmText);
DeleteDC(hdcText);
EndDialog(hWnd, 0);
return TRUE;
}
return FALSE;

Ok, here is a bit "purified" code, which of course is not mine, but I thought it was needless to say, Mate ... my coding skills sux ... :(

Cheers,

SS.

Link to comment

Seems you got carried away a little with the purification there :sweat:

:lol:

I can only agree, but sorry, cant show all ... thats why I put purification in quotation marks ... :^

:lol:

Link to comment
Dragon Warrior

I m running XpSp3 and using VC 6.0 . How do i make use of gdiplus. I tried downloading the sdk, it contains a dll named gdiplus.dll. Someone said that xp already comes with gdiplus...<br /><br />but my program just donno where to find include <gdiplus.h>.

How do i setup and configure gdiplus for VC 6 ?

(Sorry, if my question looks silly, I m just new to gdi+)

Edited by Dragon Warrior
Link to comment

My first guess would be that VC6 doesn't have the gdiplus headers at all. It's from before 2000, mind you and GDI Plus came with XP or something.

You might wanna switch to a more recent compiler (VS 2010 just got released) :geek:

Link to comment
  • 2 years later...

@SSlEVIN : Your code is not working.

Here is what I have done, actually nothing just WinMain()


#pragma comment(lib, "msimg32.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdiplus.lib")#include <windows.h>
#include <commctrl.h>
#include <olectl.h>
#include <ole2.h>
#include"resource.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <Winuser.h>
#include <gdiplus.h>HMODULE hUserDll;
LOGFONTA lfVerdana = { -11, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 1, 34, "Courier New" };
LPSTR lpszAboutText =
"Some Text Here\n\n"
"Some Text Here \n"
"Some Text Here"
"\nSome Text Here\n\n"
"\nSome Text Here\n"
"-----------\n"
"Some Text Here\n"
"Some Text Here\n"
"Some Text Here\n\n"
"Some Text Here\n\n"
"Some Text Here\n"
"Some Text Here\n\n\n"
"Some Text Here\n\n";
BOOL CALLBACK AboutProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HBITMAP hbmText;
static HDC hdcText;
static int ndcText, nOffset, nOffsetMax; switch(uMsg)
{
case WM_INITDIALOG:
{
SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_TOPMOST);
hUserDll = LoadLibraryA("USER32.dll"); RECT rcClient, rcText;
GetClientRect(hWnd, &rcClient); // Setup scroller
int nLines = 0;
LPSTR lpszLine = lpszAboutText;
while(*lpszLine)
{
if(*lpszLine == '\n') nLines++;
lpszLine++;
}
SIZE szAboutText; HDC hdc = GetDC(hWnd);
hdcText = CreateCompatibleDC(hdc);
ndcText = SaveDC(hdcText); HFONT hfAbout = CreateFontIndirectA(&lfVerdana);
SelectObject(hdcText, hfAbout);
GetTextExtentPoint32A(hdcText, lpszAboutText, strlen(lpszAboutText), &szAboutText);
CopyRect(&rcText, &rcClient);
rcText.bottom += (szAboutText.cy * nLines);
hbmText = CreateCompatibleBitmap(hdc, rcText.right, rcText.bottom);
SelectObject(hdcText, hbmText);
ReleaseDC(hWnd, hdc); SetBkMode(hdcText, TRANSPARENT);
SetTextColor(hdcText, RGB(0, 0, 255)); // Color of Text
rcText.top += rcClient.bottom;
DrawTextA(hdcText, lpszAboutText, strlen(lpszAboutText), &rcText, DT_CENTER);
DeleteObject(hfAbout); nOffset = 0; nOffsetMax = rcText.bottom;
SetTimer(hWnd, 1, 60, NULL); }
return true;
case WM_TIMER:
{
RECT rcClient;
GetClientRect(hWnd, &rcClient);
if(nOffset < nOffsetMax) nOffset += 1;
else nOffset = 0;
InvalidateRect(hWnd, NULL, FALSE);
}
return true;
case WM_CLOSE:
KillTimer(hWnd, 1);
RestoreDC(hdcText, ndcText);
DeleteObject(hbmText);
DeleteDC(hdcText);
EndDialog(hWnd, 0); return true;
}
return false;
}int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),HWND_DESKTOP,DLGPROC(&AboutProc),NULL);
}
Link to comment

Last reply prior to yours:

Posted 13 May 2010

More than 2 years since anybody has posted anything in the thread?

HR,

Ghandi

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...