HBITMAP CSkin::LoadBitmap(LPCTSTR pszFile) { #ifdef _WIN32_WCE return SHLoadDIBitmap(pszFile); #else return (HBITMAP)LoadImage(NULL, pszFile, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE); #endif }
HBITMAP CControl::LoadImageFile (LPCWSTR filename) { HBITMAP hbitmap; // Use dynamically loaded function, fall back to standard function on failure hbitmap = (*pLoadImageProc) (filename); if (!hbitmap) hbitmap = SHLoadDIBitmap (filename); return hbitmap; }
LRESULT CTodayView::OnAddImage(WPARAM wp, LPARAM lp) { HBITMAP hBitMap; LPTSTR lpTarget; TCHAR szError[100]; BITMAP BitMapInfo; INLINEIMAGEINFO WebImage; LPSTR lpImageFile = (LPSTR) lp; if (lp) { lpTarget = new TCHAR[128]; if ( lpTarget ) { { LPSTR lpTemp = strchr(lpImageFile, ':'); // skip 'file' keyword if ( lpTemp ) lpImageFile = lpTemp + 1; // skip } memset(lpTarget, 0, 128); mbstowcs(lpTarget, (LPCSTR)lpImageFile, strlen(lpImageFile)); // swprintf(lpTarget, TEXT("%s"), lpImageFile); // wsprintf(lpTarget, TEXT("%s%S"), pCurrentDirectory, lpImageFile); hBitMap = SHLoadDIBitmap(lpTarget); if ( hBitMap ) { GetObject(hBitMap, sizeof(BITMAP), &BitMapInfo); WebImage.dwCookie = wp; // pass back to DTM_SETIMAGE WebImage.bOwnBitmap = TRUE; // control to destroy object; WebImage.iOrigHeight = BitMapInfo.bmHeight; WebImage.iOrigWidth = BitMapInfo.bmWidth; WebImage.hbm = hBitMap; m_ctlHtml.SendMessage(DTM_SETIMAGE, 0, (LPARAM) &WebImage); } else { wsprintf(szError, TEXT("Failed to load Image %s, error %ld"), lpTarget, GetLastError()); // MessageBox(hwnd, szError, TEXT("Load Image"), MB_OK|MB_SETFOREGROUND); m_ctlHtml.SendMessage(DTM_IMAGEFAIL, 0, (LPARAM) wp); } free(lpTarget); } else m_ctlHtml.SendMessage(DTM_IMAGEFAIL, 0, (LPARAM) wp); // free(lpImageFile); } return 0; }
bool wxDIB::Load(const wxString& filename) { #ifdef __WXWINCE__ m_handle = SHLoadDIBitmap(filename); #else // !__WXWINCE__ m_handle = (HBITMAP)::LoadImage ( wxGetInstance(), filename.fn_str(), IMAGE_BITMAP, 0, 0, // don't specify the size LR_CREATEDIBSECTION | LR_LOADFROMFILE ); #endif // __WXWINCE__ if ( !m_handle ) { wxLogLastError(wxT("Loading DIB from file")); return false; } return true; }
HWND CreateProgressDialog(TCHAR* text) { static int yFontSize, xFontSize; HDC hTempDC = NULL; if (doinitprogress) { doinitprogress=false; DWORD Style=0; Style = WS_CHILD | ES_MULTILINE | ES_CENTER | ES_READONLY | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; hStartupWindow=CreateWindow(TEXT("STATIC"), TEXT("\0"), Style, 0, 0, ScreenSizeX, ScreenSizeY, hWndMainWindow, NULL, hInst, NULL); if (hStartupWindow==NULL) { StartupStore(_T("***** CRITIC, no startup window!%s"),NEWLINE); FailStore(_T("CRITIC, no startup window!")); return NULL; } if (!(hStartupDC = GetDC(hStartupWindow))) { StartupStore(_T("------ Cannot state startup window%s"),NEWLINE); FailStore(_T("Cannot state startup window")); return(NULL); } /* SHFullScreen(hProgress, SHFS_HIDETASKBAR |SHFS_HIDESIPBUTTON |SHFS_HIDESTARTICON); SetWindowPos(hProgress,HWND_TOP,0,0,0,0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW); */ //RECT rt; //GetClientRect(hStartupWindow,&rt); //FillRect(hStartupDC,&rt,(HBRUSH)GetStockObject(BLACK_BRUSH)); //SetWindowPos(hStartupWindow,HWND_TOP,0,0,0,0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW); //SHFullScreen(hStartupWindow, SHFS_HIDETASKBAR |SHFS_HIDESIPBUTTON |SHFS_HIDESTARTICON); //SetForegroundWindow(hStartupWindow); //UpdateWindow(hStartupWindow); ShowWindow(hStartupWindow,SW_SHOWNORMAL); BringWindowToTop(hStartupWindow); // Load welcome screen bitmap HBITMAP hWelcomeBitmap=NULL; TCHAR sDir[MAX_PATH]; TCHAR srcfile[MAX_PATH]; LocalPath(sDir,TEXT(LKD_BITMAPS)); // first look for lkstart_480x272.bmp for example _stprintf(srcfile,_T("%s\\LKSTART_%s.BMP"),sDir, GetSizeSuffix() ); if ( GetFileAttributes(srcfile) == 0xffffffff ) { // no custom file, get a generic one switch(ScreenSize) { case ss800x480: case ss640x480: case ss720x408: case ss896x672: _stprintf(srcfile,_T("%s\\LKSTART_LB.BMP"),sDir); break; case ss480x272: case ss480x234: case ss400x240: case ss320x240: _stprintf(srcfile,_T("%s\\LKSTART_LS.BMP"),sDir); break; case ss480x640: case ss480x800: _stprintf(srcfile,_T("%s\\LKSTART_PB.BMP"),sDir); break; case ss240x320: case ss272x480: _stprintf(srcfile,_T("%s\\LKSTART_PS.BMP"),sDir); break; default: _stprintf(srcfile,_T("%s\\LKSTART_DEFAULT.BMP"),sDir); break; } } #if (WINDOWSPC>0) hWelcomeBitmap=(HBITMAP)LoadImage(GetModuleHandle(NULL),srcfile,IMAGE_BITMAP,0,0,LR_LOADFROMFILE); #else hWelcomeBitmap=(HBITMAP)SHLoadDIBitmap(srcfile); #endif // still nothing? use internal (poor man) resource if (hWelcomeBitmap==NULL) hWelcomeBitmap=LoadBitmap(hInst, MAKEINTRESOURCE(IDB_SWIFT)); hTempDC = CreateCompatibleDC(hStartupDC); // AA HBITMAP oldBitmap = (HBITMAP)SelectObject(hTempDC, hWelcomeBitmap); SelectObject(hTempDC, LKSTARTBOTTOMFONT); SIZE TextSize; GetTextExtentPoint(hTempDC, _T("X"),1, &TextSize); yFontSize = TextSize.cy; xFontSize = TextSize.cx; BITMAP bm; GetObject(hWelcomeBitmap,sizeof(bm), &bm); StretchBlt(hStartupDC,0,0, ScreenSizeX,ScreenSizeY-1, hTempDC, 0, 0, 2,2, BLACKNESS); if ( (bm.bmWidth >ScreenSizeX)||(bm.bmHeight>ScreenSizeY)) { StretchBlt(hStartupDC,0,0, ScreenSizeX,ScreenSizeY-NIBLSCALE(2)-(yFontSize*2)-1, hTempDC, 0, 0, bm.bmWidth,bm.bmHeight, SRCCOPY); } else { BitBlt(hStartupDC,(ScreenSizeX-bm.bmWidth)/2,0,bm.bmWidth,bm.bmHeight,hTempDC, 0, 0, SRCCOPY); } DeleteObject(hWelcomeBitmap); // AA SelectObject(hTempDC, oldBitmap); if (DeleteDC(hTempDC)==0) StartupStore(_T("**** Cannot delete hTempDC\n")); } BringWindowToTop(hStartupWindow); // we shall return here also on shutdown and file reloads // RECT is left, top, right, bottom RECT PrintAreaR; PrintAreaR.left = NIBLSCALE(2); PrintAreaR.bottom = ScreenSizeY-NIBLSCALE(2); PrintAreaR.top = PrintAreaR.bottom - (yFontSize*2); PrintAreaR.right = ScreenSizeX - NIBLSCALE(2); HFONT oldFont=(HFONT)SelectObject(hStartupDC,LKSTARTBOTTOMFONT); HBRUSH hB=LKBrush_Petrol; FillRect(hStartupDC,&PrintAreaR, hB); // Create text area // we cannot use LKPen here because they are not still initialised for startup menu. no problem HPEN hP=(HPEN) CreatePen(PS_SOLID,NIBLSCALE(1),RGB_GREEN); SelectObject(hStartupDC,hP); SelectObject(hStartupDC,hB); Rectangle(hStartupDC, PrintAreaR.left,PrintAreaR.top,PrintAreaR.right,PrintAreaR.bottom); DeleteObject(hP); hP=(HPEN) CreatePen(PS_SOLID,NIBLSCALE(1),RGB_BLACK); SelectObject(hStartupDC,hP); Rectangle(hStartupDC, PrintAreaR.left+NIBLSCALE(2),PrintAreaR.top+NIBLSCALE(2),PrintAreaR.right-NIBLSCALE(2),PrintAreaR.bottom-NIBLSCALE(2)); SetTextColor(hStartupDC,RGB_WHITE); SetBkMode(hStartupDC,TRANSPARENT); unsigned int maxchars= (ScreenSizeX/xFontSize)-1; if (_tcslen(text) <maxchars) { maxchars=_tcslen(text); } ExtTextOut(hStartupDC,PrintAreaR.left+(xFontSize/2),PrintAreaR.top + ((PrintAreaR.bottom - PrintAreaR.top)/2)-(yFontSize/2), ETO_OPAQUE,NULL,text,maxchars,NULL); SelectObject(hStartupDC,oldFont); // Sleep(300); // Slow down display of data? No because in case of important things, Sleep is set by calling part DeleteObject(hP); return hStartupWindow; }
pj_status_t GuiInit() { WNDCLASS wc; HWND hWnd = NULL; RECT r; DWORD dwStyle; enum { LABEL_HEIGHT = 30 }; enum { MENU_ID_EXIT = 50000 }; BITMAP bmp; HMENU hRootMenu; SHMENUBARINFO mbi; pj_status_t status = PJ_SUCCESS; /* Check if app is running. If it's running then focus on the window */ hWnd = FindWindow(MAINWINDOWCLASS, MAINWINDOWTITLE); if (NULL != hWnd) { SetForegroundWindow(hWnd); return status; } wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)DialogProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = g_hInst; wc.hIcon = 0; wc.hCursor = 0; wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = MAINWINDOWCLASS; if (!RegisterClass(&wc) != 0) { DWORD err = GetLastError(); return PJ_RETURN_OS_ERROR(err); } /* Create the app. window */ g_hWndMain = CreateWindow(MAINWINDOWCLASS, MAINWINDOWTITLE, WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, (HWND)NULL, NULL, g_hInst, (LPSTR)NULL); if (g_hWndMain == NULL) { DWORD err = GetLastError(); return PJ_RETURN_OS_ERROR(err); } /* Create exit menu */ hRootMenu = CreateMenu(); AppendMenu(hRootMenu, MF_STRING, MENU_ID_EXIT, L"Exit"); /* Initialize menubar */ ZeroMemory(&mbi, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = g_hWndMain; mbi.dwFlags = SHCMBF_HIDESIPBUTTON|SHCMBF_HMENU; mbi.nToolBarId = (UINT)hRootMenu; mbi.hInstRes = g_hInst; if (FALSE == SHCreateMenuBar(&mbi)) { DWORD err = GetLastError(); return PJ_RETURN_OS_ERROR(err); } /* Store menu window handle */ g_hWndMenuBar = mbi.hwndMB; /* Show the menu */ DrawMenuBar(g_hWndMain); ShowWindow(g_hWndMenuBar, SW_SHOW); /* Override back button */ SendMessage(g_hWndMenuBar, SHCMBM_OVERRIDEKEY, VK_TBACK, MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY)); /* Get main window size */ GetClientRect(g_hWndMain, &r); #if defined(WIN32_PLATFORM_PSPC) && WIN32_PLATFORM_PSPC != 0 /* Adjust the height for PocketPC platform */ r.bottom -= GetSystemMetrics(SM_CYMENU); #endif /* Create logo */ g_hBmp = SHLoadDIBitmap(LOGO_PATH); /* for jpeg, uses SHLoadImageFile() */ if (g_hBmp == NULL) { DWORD err = GetLastError(); return PJ_RETURN_OS_ERROR(err); } GetObject(g_hBmp, sizeof(bmp), &bmp); dwStyle = SS_CENTERIMAGE | SS_REALSIZEIMAGE | SS_BITMAP | WS_CHILD | WS_VISIBLE; g_hWndImg = CreateWindow(TEXT("STATIC"), NULL, dwStyle, (r.right-r.left-bmp.bmWidth)/2, (r.bottom-r.top-bmp.bmHeight)/2, bmp.bmWidth, bmp.bmHeight, g_hWndMain, (HMENU)0, g_hInst, NULL); if (g_hWndImg == NULL) { DWORD err = GetLastError(); return PJ_RETURN_OS_ERROR(err); } SendMessage(g_hWndImg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g_hBmp); /* Create label */ dwStyle = WS_CHILD | WS_VISIBLE | ES_CENTER; g_hWndLbl = CreateWindow(TEXT("STATIC"), NULL, dwStyle, 0, r.bottom-LABEL_HEIGHT, r.right-r.left, LABEL_HEIGHT, g_hWndMain, (HMENU)0, g_hInst, NULL); if (g_hWndLbl == NULL) { DWORD err = GetLastError(); return PJ_RETURN_OS_ERROR(err); } SetWindowText(g_hWndLbl, _T("Please wait..")); return status; }