For Programmers: Free Programming Magazines  


Home > Archive > Smartphone Developer Forum > October 2005 > How to display picture on Smartphone 2003?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to display picture on Smartphone 2003?
Aaron

2005-09-27, 7:05 pm

I have problem in displaying picture on Smartphone. I cannot see the picture.
The picture is never shown successfully. I copy my code here. It could be
great if someone can tell me where it goes wrong or give same code samples
that I can display picture on the Smartphone.

Code:
LRESULT OnCreate(
HWND hwnd,
CREATESTRUCT* lParam
)
{
// create the menu bar
SHMENUBARINFO mbi;
ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hwnd;
mbi.nToolBarId = IDR_HELLO_MENUBAR;
mbi.hInstRes = g_hInst;
if(!SHCreateMenuBar(&mbi))
{
// Couldn't create the menu bar. Fail creation of the window.
return(-1);
}

// Get our message text.
if(0 == LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage,
ARRAYSIZE(g_szMessage)))
{
// Couldn't load the string. Fail creation of the window.
return(-1);
}

// Do other window creation related things here.
PAINTSTRUCT ps = {0};
RECT rect = {0};
BITMAP bm = {0};
HDC hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
HBITMAP hBmp = SHLoadImageFile(_T("\\Storage\\Program
Files\\Pics\\test.gif"));
if(hBmp == NULL)
{
MessageBox(hwnd, _T("can't load image"), _T("Error"), MB_OK);
}

GetObject(hBmp, sizeof(bm), &bm);

HDC hdcTemp = CreateCompatibleDC(hdc);
HANDLE oldBmp = SelectObject(hdcTemp, hBmp );
//SelectObject(hdcTemp, hBmp );

//BitBlt(hdc, 0, 0,rect.right,rect.bottom, hdcTemp, 0, 0, SRCCOPY);
StretchBlt(hdc,0,0,rect.right,rect.bottom,
hdcTemp,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);

DeleteObject(hBmp);
EndPaint (hwnd, &ps);
SelectObject(hdcTemp,oldBmp);
DeleteDC(hdcTemp);
DeleteDC(hdc) ;

return(0); // continue creation of the window
}


Thanks in advance.

Aaron
Ilya Manin

2005-10-23, 3:59 am

You have to handle WM_PAINT message and draw the picture there. (don't draw
in WM_CREATE message)

"Aaron" <Aaron@discussions.microsoft.com> wrote in message
news:B8175305-9D0E-4A60-B1C6-405EE2CF268A@microsoft.com...
>I have problem in displaying picture on Smartphone. I cannot see the
>picture.
> The picture is never shown successfully. I copy my code here. It could be
> great if someone can tell me where it goes wrong or give same code samples
> that I can display picture on the Smartphone.
>
> Code:
> LRESULT OnCreate(
> HWND hwnd,
> CREATESTRUCT* lParam
> )
> {
> // create the menu bar
> SHMENUBARINFO mbi;
> ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
> mbi.cbSize = sizeof(SHMENUBARINFO);
> mbi.hwndParent = hwnd;
> mbi.nToolBarId = IDR_HELLO_MENUBAR;
> mbi.hInstRes = g_hInst;
> if(!SHCreateMenuBar(&mbi))
> {
> // Couldn't create the menu bar. Fail creation of the window.
> return(-1);
> }
>
> // Get our message text.
> if(0 == LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage,
> ARRAYSIZE(g_szMessage)))
> {
> // Couldn't load the string. Fail creation of the window.
> return(-1);
> }
>
> // Do other window creation related things here.
> PAINTSTRUCT ps = {0};
> RECT rect = {0};
> BITMAP bm = {0};
> HDC hdc = BeginPaint(hwnd, &ps);
> GetClientRect(hwnd, &rect);
> HBITMAP hBmp = SHLoadImageFile(_T("\\Storage\\Program
> Files\\Pics\\test.gif"));
> if(hBmp == NULL)
> {
> MessageBox(hwnd, _T("can't load image"), _T("Error"), MB_OK);
> }
>
> GetObject(hBmp, sizeof(bm), &bm);
>
> HDC hdcTemp = CreateCompatibleDC(hdc);
> HANDLE oldBmp = SelectObject(hdcTemp, hBmp );
> //SelectObject(hdcTemp, hBmp );
>
> //BitBlt(hdc, 0, 0,rect.right,rect.bottom, hdcTemp, 0, 0, SRCCOPY);
> StretchBlt(hdc,0,0,rect.right,rect.bottom,
> hdcTemp,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
>
> DeleteObject(hBmp);
> EndPaint (hwnd, &ps);
> SelectObject(hdcTemp,oldBmp);
> DeleteDC(hdcTemp);
> DeleteDC(hdc) ;
>
> return(0); // continue creation of the window
> }
>
>
> Thanks in advance.
>
> Aaron



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com