当前位置: 代码迷 >> WinCE >> wince 创建了一个窗口显示图片,为啥显示不出来解决方案
  详细解决方案

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

热度:196   发布时间:2016-04-28 13:35:57.0
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);
}


// 此代码模块中包含的函数的前向声明:
ATOM MyRegisterClass(HINSTANCE, LPTSTR);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(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);
  相关解决方案