Code:
#include <windows.h>
#include <tchar.h>
#include <math.h>
#include <stdio.h>
#include "resource.h"
BOOL GetBitmapFileName(TCHAR *filename, int len, HWND hWnd)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = _T("Bitmap Files (*.bmp)\0*.bmp\0All Files (*.*)\0*.*\0\0");
ofn.lpstrFile = filename;
ofn.nMaxFile = len;
ofn.lpstrTitle = _T("Browse");
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
return GetOpenFileName(&ofn);
}
HBITMAP LoadBitmapFile(const TCHAR *filename)
{
return (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
}
BOOL MainDialog_OnCommand(HWND hWnd, WORD wCommand, WORD wNotify, HWND hControl);
BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hDC;
switch (uMsg)
{
case WM_COMMAND:
return MainDialog_OnCommand(hWnd, LOWORD(wParam),
HIWORD(wParam), (HWND)lParam);
case WM_PAINT:
hDC = BeginPaint(hWnd, &ps);
MainDialog_OnPaint(hWnd, hDC);
EndPaint(hWnd, &ps);
return TRUE;
case WM_CLOSE:
EndDialog(hWnd, 0);
return TRUE;
}
return FALSE;
}
TCHAR szBitmapFilename[_MAX_PATH];
HBITMAP hBitmap;
BOOL MainDialog_OnCommand(HWND hWnd, WORD wCommand, WORD wNotify, HWND hControl)
{
switch (wCommand)
{
case IDC_BROWSE:
if (GetBitmapFileName(szBitmapFilename,
sizeof(szBitmapFilename) / sizeof(TCHAR), hWnd))
SetDlgItemText(hWnd, IDC_FILENAME, szBitmapFilename);
// fall through into OK handler
case IDOK:
if (hBitmap != NULL)
DeleteObject(hBitmap);
GetDlgItemText(hWnd, IDC_FILENAME, szBitmapFilename,
sizeof(szBitmapFilename) / sizeof(TCHAR));
hBitmap = LoadBitmapFile(szBitmapFilename);
RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
break;
case IDCANCEL:
EndDialog(hWnd, wCommand);
break;
}
return TRUE;
}
void MainDialog_OnPaint(HWND hWnd, HDC hDC)
{
if (hBitmap == NULL)
return;
RECT r;
POINT p;
GetClientRect(GetDlgItem(hWnd, IDC_VIEW), &r);
p.x = r.left;
p.y = r.top;
ClientToScreen(GetDlgItem(hWnd, IDC_VIEW), &p);
ScreenToClient(hWnd, &p);
DrawState(hDC, NULL, NULL, (LPARAM)hBitmap, 0, p.x, p.y, 0, 0, DST_BITMAP | DSS_NORMAL);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nCmdShow)
{
DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1),
NULL, (DLGPROC)MainDialogProc, 0);
return 0;
}
When I go to compile this with my code it comes back with two errors can someone please help me solve them: