Hello!
I have a problem creating a window with a vertical scroll bar.
Here's what I try to do:

HWND InitializeCustomItem(....
.......
g_hWnd = CreateWindow(appName, appName,
WS_VISIBLE | WS_CHILD | WS_VSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 0,
hwndParent, NULL, g_hInst, NULL) ;

SCROLLINFO si;
ZeroMemory(&si, sizeof(si));
si.cbSize = sizeof(si);

si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE |
SIF_DISABLENOSCROLL;

si.nPos = 50;
si.nPage = 100;
si.nMin = 0;
si.nMax = appHeight;
SetScrollInfo(g_hWnd, SB_VERT, &si, TRUE);

. SetWindowLong(g_hWnd, GWL_WNDPROC, (LONG) WndProc);
....

}

LRESULT CALLBACK WndProc (HWND hwnd, UINT uimessage, WPARAM wParam,
LPARAM lParam)
{
.....
I set appHeight to 120 at the beginning.
In response to WM_TODAYCUSTOM_QUERYREFRESHCACHE , I set the ptli->cyp
to appHeight and return true (only once, of course, except for
resizes)
Later I create a bitmap:

case WM_CREATE:
{
if (!done_once) {
hBitmap = Test_NewDIBSection(appWidth, /
*appHeight*/480, (void **)
&bitmapa);
hDC = GetDC(hwnd);
hDCMem = CreateCompatibleDC(hDC);
hOldBitmap = (HBITMAP) SelectObject(hDCMem,
hBitmap);
done_once = true;
}
....
}

which works fine, however this bitmap is limited to the appHeight
size, while
I would very much like to scroll it down to see more. My window's
scroll bar appears, but it doesn't move, as if everything there is to
see is already shown. Also, the main today screen scroll bar appears
if necessary - and it works fine, scrolling my bitmap, but
unfortunately I need the internal scroll bar.
I understand that I can probably do it manually by responding to
WM_VSCROLL messages, but I doubt it would be as effective as a pro-
made scrolling. Does anybody know (probably most do :-( ), how can I
scroll my bitmap? I'm pretty sure that a smooth way to do it exists,
but I am simply missing something and have no idea, what it might be.
Thanks for any help!

gegitor

RE: How to scroll a bitmap inside a today screen plugin? by RaduMotisan

RaduMotisan
Tue May 08 09:18:01 CDT 2007

gegitor,

First you should check the today samples on MSDN or in the SDK to make sure
your code is build in the correct way.

There are several things in the code posted that I would like to highlight:
1) the drawing code in WM_CREATE
hDC = GetDC(hwnd);
> hDCMem = CreateCompatibleDC(hDC);
> hOldBitmap = (HBITMAP) SelectObject(hDCMem,
> hBitmap);
You should do this in the WM_PAINT / WM_ERASEBKGND messages, there's no
point in taking the DC with GetDC.
2)Choose the size of your plugin: If you want to have more space for it, you
can easily set this in WM_TODAYCUSTOM_QUERYREFRESHCACHE:
TODAYLISTITEM *ptliItem;

// get the pointer to the item from the Today screen
ptliItem = (TODAYLISTITEM*)wParam;

ptliItem->cyp = iItemHeight;

3) Regarding the scrolling, if your only alternative is to keep the plugin
height small and do scrolling, then yes, you need to handle the WM_VSCROLL
messages yourself, and do something like this:

case WM_VSCROLL:
...
nVOffset = ... // get the scroll ammount

then in :
case WM_PAINT:

BitBlt(hdc, 0,0, Image_Width, Image_Height, hdcMemImage, 0, nVOffset,SRCCOPY)

This way your image would be displayed starting with the desired ammount of
pixels.

I hope this gives an idea.

--
Best regards,

Radu Motisan

http://www.teksoftco.com/forum
Windows Mobile Development Forum


"wandering_in_the_woods" wrote:

> Hello!
> I have a problem creating a window with a vertical scroll bar.
> Here's what I try to do:
>
> HWND InitializeCustomItem(....
> ........
> g_hWnd = CreateWindow(appName, appName,
> WS_VISIBLE | WS_CHILD | WS_VSCROLL,
> CW_USEDEFAULT, CW_USEDEFAULT, 240, 0,
> hwndParent, NULL, g_hInst, NULL) ;
>
> SCROLLINFO si;
> ZeroMemory(&si, sizeof(si));
> si.cbSize = sizeof(si);
>
> si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE |
> SIF_DISABLENOSCROLL;
>
> si.nPos = 50;
> si.nPage = 100;
> si.nMin = 0;
> si.nMax = appHeight;
> SetScrollInfo(g_hWnd, SB_VERT, &si, TRUE);
>
> .. SetWindowLong(g_hWnd, GWL_WNDPROC, (LONG) WndProc);
> .....
>
> }
>
> LRESULT CALLBACK WndProc (HWND hwnd, UINT uimessage, WPARAM wParam,
> LPARAM lParam)
> {
> ......
> I set appHeight to 120 at the beginning.
> In response to WM_TODAYCUSTOM_QUERYREFRESHCACHE , I set the ptli->cyp
> to appHeight and return true (only once, of course, except for
> resizes)
> Later I create a bitmap:
>
> case WM_CREATE:
> {
> if (!done_once) {
> hBitmap = Test_NewDIBSection(appWidth, /
> *appHeight*/480, (void **)
> &bitmapa);
> hDC = GetDC(hwnd);
> hDCMem = CreateCompatibleDC(hDC);
> hOldBitmap = (HBITMAP) SelectObject(hDCMem,
> hBitmap);
> done_once = true;
> }
> ....
> }
>
> which works fine, however this bitmap is limited to the appHeight
> size, while
> I would very much like to scroll it down to see more. My window's
> scroll bar appears, but it doesn't move, as if everything there is to
> see is already shown. Also, the main today screen scroll bar appears
> if necessary - and it works fine, scrolling my bitmap, but
> unfortunately I need the internal scroll bar.
> I understand that I can probably do it manually by responding to
> WM_VSCROLL messages, but I doubt it would be as effective as a pro-
> made scrolling. Does anybody know (probably most do :-( ), how can I
> scroll my bitmap? I'm pretty sure that a smooth way to do it exists,
> but I am simply missing something and have no idea, what it might be.
> Thanks for any help!
>
> gegitor
>
>

Re: How to scroll a bitmap inside a today screen plugin? by wandering_in_the_woods

wandering_in_the_woods
Fri May 11 08:49:30 CDT 2007

> There are several things in the code posted that I would like to highlight:
> 1) the drawing code in WM_CREATE
> hDC = GetDC(hwnd);
> > hDCMem = CreateCompatibleDC(hDC);
> > hOldBitmap = (HBITMAP) SelectObject(hDCMem,
> > hBitmap);
> You should do this in the WM_PAINT / WM_ERASEBKGND messages, there's no
> point in taking the DC with GetDC.
But WM_PAINT is sent after every refresh - I would be calling
CreateCompatibleDC many times instead of once. Should I destroy the
hDCMem somewhere except perhaps on the very end?


> 2)Choose the size of your plugin: If you want to have more space for it, you
> can easily set this in WM_TODAYCUSTOM_QUERYREFRESHCACHE:
> TODAYLISTITEM *ptliItem;
>
> // get the pointer to the item from the Today screen
> ptliItem = (TODAYLISTITEM*)wParam;
>
> ptliItem->cyp = iItemHeight;
>
Yes, I know that and I'm doing it.

> 3) Regarding the scrolling, if your only alternative is to keep the plugin
> height small and do scrolling, then yes, you need to handle the WM_VSCROLL
> messages yourself, and do something like this:
>
> case WM_VSCROLL:
> ...
> nVOffset = ... // get the scroll ammount
>
> then in :
> case WM_PAINT:
>
> BitBlt(hdc, 0,0, Image_Width, Image_Height, hdcMemImage, 0, nVOffset,SRCCOPY)

I was afraid of that. It's kinda strange that there's no available
function to do it, if it is already done on a today screen level. Well
I better get to work.

>
> This way your image would be displayed starting with the desired ammount of
> pixels.
>
> I hope this gives an idea.
>
> --
> Best regards,
>
> Radu Motisan
>
> http://www.teksoftco.com/forum
> Windows Mobile Development Forum
>

Thanks for your help,
gegitor