首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > WinCE >

wince 创建了一个窗口显示图片,为啥显示不出来解决方案

2012-02-11 
wince 创建了一个窗口显示图片,为啥显示不出来void DrawImage(HDC hdc,const void *buffer,UINT size,LPCR

wince 创建了一个窗口显示图片,为啥显示不出来
void DrawImage(HDC hdc,const void *buffer,UINT size,LPCRECT rect)
{
IImagingFactory *pImageFactory=NULL;
IImage *pImage=NULL;
CoInitializeEx(NULL,COINIT_MULTITHREADED);
if(SUCCEEDED(CoCreateInstance(CLSID_ImagingFactory,NULL,CLSCTX_INPROC_SERVER,IID_IImagingFactory,(void**)&pImageFactory)))
{
if(SUCCEEDED(pImageFactory->CreateImageFromBuffer(buffer,size,DISPOSAL_NONE,&pImage)))
{
pImage->Draw(hdc,rect,NULL);
pImage->Release();
}
pImageFactory->Release();
}
CoUninitialize();
}

//LoadResourceImage函数主要将图片导入内存,使用这个函数,只要将图片的ID,图片的类名,以及要显示图片的坐标位置输入即可.
void LoaResourceImage(HWND hwnd,LPCWSTR lpName,LPCWSTR lpType,int i,int left,int right,int bottom,int top)
{
HDC hdc;
HRSRC hr;
DWORD dwsize;
HGLOBAL hg;
LPSTR lp;
HMODULE hModule_Current=GetModuleHandle(NULL);
hr=FindResource(hModule_Current,lpName,lpType);
dwsize=SizeofResource(GetModuleHandle(NULL),hr);
hg=LoadResource(GetModuleHandle(NULL),hr);
lp=(LPSTR)LockResource(hg);
hdc=GetDC(hwnd);
RECT rect;
rect.bottom = bottom;
rect.top = top;
rect.right = right;
rect.left = left;
DrawImage(hdc,lp,dwsize,&rect);
DeleteObject(hr);
}


// 此代码模块中包含的函数的前向声明:
ATOMMyRegisterClass(HINSTANCE, LPTSTR);
BOOLInitInstance(HINSTANCE, int);
LRESULT CALLBACKWndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACKAbout(HWND, UINT, WPARAM, LPARAM);


int WINAPI WinMain(HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPTSTR lpCmdLine,
  int nCmdShow)
{
MSG msg;

WNDCLASS wc;

wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYTEST));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;

HWND hWnd = CreateWindow(szWindowClass, NULL, WS_VISIBLE,
  0,0,Screen_width, Screen_height, NULL, NULL, hInstance, NULL);
SetWindowPos(hWnd,HWND_TOPMOST,0,0,Screen_width,Screen_height,SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
LoaResourceImage(hWnd,MAKEINTRESOURCE(IDM_IMAGE),RT_BITMAP,0,0,0,412,475);

  if (!hWnd)
  {
  return FALSE;
  }

  ShowWindow(hWnd, SW_SHOW);
  UpdateWindow(hWnd);


// 主消息循环:
while (GetMessage(&msg, NULL, 0, 0)) 
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;
  static int cxChar=0,cyChar=0;
HBRUSH brush;
HWND btnhwnd1,btnhwnd2,btnhwnd3;
static int i=0;
RECT rect={10,10,30,30};
  switch (message) 
  {
  case WM_COMMAND:
  wmId = LOWORD(wParam); 
  wmEvent = HIWORD(wParam); 
  // 分析菜单选择:
  switch (wmId)
  {
  case IDM_HELP_ABOUT:
  DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
  break;
  case IDM_FILE_EXIT:
  DestroyWindow(hWnd);
  break;
case IDC_PUSHBTN3:
SendMessage(hWnd,WM_CLOSE,0,0);


memset(HWpotArr,0,MAX_POINTNUM);
break;
case IDC_PUSHBTN2:
InvalidateRect(hWnd,NULL,TRUE);
memset(HWpotArr,0,MAX_POINTNUM);
break;
  default:
  return DefWindowProc(hWnd, message, wParam, lParam);
  }

  break;
  case WM_CREATE:
LoaResourceImage(hWnd,MAKEINTRESOURCE(IDM_IMAGE),RT_BITMAP,0,0,0,Screen_height,Screen_width);break;
 case WM_DESTROY:
  CommandBar_Destroy(g_hWndCommandBar);
  PostQuitMessage(0);
  break;

  default:
  return DefWindowProc(hWnd, message, wParam, lParam);
  }
  return 0;
}

程序编译通过 为什么不显示呢

[解决办法]

C/C++ code
// Handler for drawingvoid OnDraw(HWND hWnd){    PAINTSTRUCT ps;    HDC hdc, hdcMem, hdcNew;    HBITMAP hBmp;    HBRUSH hBr;    int dstX, dstY, i, offset;    RECT rt, rtmp;    hdc = BeginPaint(hWnd, &ps);    GetClientRect(hWnd, &rt);    // First draw the colored bars in the upper part of the window that serve as    // the starting bitmap to rotate    offset = (rt.right - rt.left - 200) / 2;    rtmp.left = offset;    rtmp.right = offset + 1;    rtmp.top = 0;    rtmp.bottom = 200;    for (i = 0; i < 200; i++) {        hBr = CreateSolidBrush(RGB(i * 8 % 255, i * 5 % 255, i * 2 % 255));        FillRect(hdc, &rtmp, hBr);        DeleteObject(hBr);        rtmp.left++;        rtmp.right++;    }    // BitBlt the starting Bitmap into a memory HDC    hdcNew = CreateCompatibleDC(hdc);    hBmp = CreateCompatibleBitmap(hdc, 200,200);    SelectObject(hdcNew, hBmp);    BitBlt(hdcNew, 0, 0, 200, 200, hdc, (rt.right - rt.left - 200) / 2, 0, SRCCOPY);    // Rotate that memory HDC    RotateMemoryDC(hBmp, hdcNew, 200, 200, g_angle, hdcMem, dstX, dstY);    DeleteObject(hBmp);    DeleteDC(hdcNew);    // Create the output HDC    hdcNew = CreateCompatibleDC(hdc);    hBmp = CreateCompatibleBitmap(hdc, 400,400);    SelectObject(hdcNew, hBmp);    rtmp.left = rtmp.top = 0;    rtmp.right = rtmp.bottom = 400;    // Fill the output HDC with the window background color and BitBlt the rotated bitmap into it    FillRect(hdcNew, &rtmp, GetSysColorBrush(COLOR_WINDOW));    BitBlt(hdcNew, (400 - dstX) / 2, (400-dstY) / 2, dstX, dstY, hdcMem, 0, 0, SRCCOPY);    DeleteDC(hdcMem);    BitBlt(hdc, (rt.left + rt.right - 400) / 2, rt.bottom - 400, 400, 400, hdcNew, 0, 0, SRCCOPY);    DeleteObject(hBmp);    DeleteDC(hdcNew);    EndPaint(hWnd, &ps);}////  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)////  PURPOSE:  Processes messages for the main window.////  WM_COMMAND    - process the application menu//  WM_PAINT    - Paint the main window//  WM_DESTROY    - post a quit message and return////LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    int wmId, wmEvent;    switch (message)     {        case WM_TIMER:            // Handle the redraw with the timer            g_angle = g_angle + .05f;            RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);            break;        case WM_COMMAND:            wmId    = LOWORD(wParam);             wmEvent = HIWORD(wParam);             // Parse the menu selections:            switch (wmId)            {                case IDM_ABOUT:                   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);                   break;                case IDM_EXIT:                   DestroyWindow(hWnd);                   break;                default:                   return DefWindowProc(hWnd, message, wParam, lParam);            }            break;        case WM_PAINT:            OnDraw(hWnd);            break;        case WM_DESTROY:            PostQuitMessage(0);            break;        default:            return DefWindowProc(hWnd, message, wParam, lParam);   }   return 0;} 


[解决办法]
我也不清楚了,执行之后pImage没有值,其他都有值,就是函数执行后,结果写不进pImage

热点排行