Hi,
I am trying a simple program og loading an image onto the window screen and then calculating the colour intensity(RGB value) and then plotting the deviation from the average value on the same window.The program works fine till the part of loading an an image but as soon as i add the part of extracting the colour part of the image,the program starts giving me an error stating cannot open Debug/12a.exe for writing
Error executing link.exe..Following is my code
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
#define IDC_MAIN_BUTTON 101 // Button identifier
#define IDC_MAIN_EDIT 102 // Edit box identifier
HWND hEdit;
const int row_window = 100;
const int no_of_pixels = 10000;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName [] = TEXT ("Image") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_INFORMATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Image"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient, cxSource, cySource ;
PAINTSTRUCT ps ;
HBITMAP hBitmap = NULL;
HBITMAP hbmOld = NULL;
HDC hdcMem = NULL;
HDC hdc = NULL;
BITMAP bm;
int i,j;
COLORREF color = 0;
BYTE RValue = 0;
BYTE GValue = 0;
BYTE BValue = 0;
unsigned int R_Mean_Value = 0;
unsigned int G_Mean_Value = 0;
unsigned int B_Mean_Value = 0;
unsigned int R_pixel[480][640];
unsigned int G_pixel[480][640];
unsigned int B_pixel[480][640];
HWND hwndButton = NULL;
HGDIOBJ hfDefault = NULL;
switch (message)
{
case WM_CREATE:
cxSource = GetSystemMetrics (SM_CXSIZEFRAME) +
GetSystemMetrics (SM_CXSIZE) ;
cySource = GetSystemMetrics (SM_CYSIZEFRAME) +
GetSystemMetrics (SM_CYCAPTION) ;
hfDefault=GetStockObject(DEFAULT_GUI_FONT);
// Create a push button
hwndButton=(HWND)CreateWindowEx(NULL,
"BUTTON",
"Calculate",
WS_TABSTOP|WS_VISIBLE|
WS_CHILD|BS_DEFPUSHBUTTON,
150,
550,
100,
25,
hwnd,
(HMENU)IDC_MAIN_BUTTON,
GetModuleHandle(NULL),
NULL);
SendMessage(hwndButton,
WM_SETFONT,
(WPARAM)hfDefault,
MAKELPARAM(FALSE,0));
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_KEYDOWN :
if( VK_LEFT)
{
hdc = GetDC(NULL); //get dc of whole screen
for (i = 0; i < 480; i++)
for (j = 0; j<= 640; j++)
{
color = GetPixel(hdc, i, j);
R_pixel[i][j] = GetRValue(color);
G_pixel[i][j] = GetGValue(color);
B_pixel[i][j] = GetBValue(color);
R_Mean_Value = R_Mean_Value + R_pixel[i][j];
G_Mean_Value = G_Mean_Value + G_pixel[i][j];
B_Mean_Value = B_Mean_Value + B_pixel[i][j];
}
R_Mean_Value = R_Mean_Value/no_of_pixels;
G_Mean_Value = G_Mean_Value/no_of_pixels;
B_Mean_Value = B_Mean_Value/no_of_pixels;
ReleaseDC (hwnd,hdc);
}
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
hBitmap = (HBITMAP)LoadImage(NULL,"C:\\Users\\Faro\\Desktop\ \image.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if(hBitmap == NULL)
MessageBox(hwnd, "Could not load Image!", "Error", MB_OK | MB_ICONEXCLAMATION);
hdcMem = CreateCompatibleDC(hdc);
hbmOld = (HBITMAP)SelectObject(hdcMem, hBitmap);
GetObject(hBitmap, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
DeleteObject(hBitmap);
EndPaint(hwnd, &ps);
return 0 ;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
I am trying a simple program og loading an image onto the window screen and then calculating the colour intensity(RGB value) and then plotting the deviation from the average value on the same window.The program works fine till the part of loading an an image but as soon as i add the part of extracting the colour part of the image,the program starts giving me an error stating cannot open Debug/12a.exe for writing
Error executing link.exe..Following is my code
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
#define IDC_MAIN_BUTTON 101 // Button identifier
#define IDC_MAIN_EDIT 102 // Edit box identifier
HWND hEdit;
const int row_window = 100;
const int no_of_pixels = 10000;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName [] = TEXT ("Image") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_INFORMATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Image"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient, cxSource, cySource ;
PAINTSTRUCT ps ;
HBITMAP hBitmap = NULL;
HBITMAP hbmOld = NULL;
HDC hdcMem = NULL;
HDC hdc = NULL;
BITMAP bm;
int i,j;
COLORREF color = 0;
BYTE RValue = 0;
BYTE GValue = 0;
BYTE BValue = 0;
unsigned int R_Mean_Value = 0;
unsigned int G_Mean_Value = 0;
unsigned int B_Mean_Value = 0;
unsigned int R_pixel[480][640];
unsigned int G_pixel[480][640];
unsigned int B_pixel[480][640];
HWND hwndButton = NULL;
HGDIOBJ hfDefault = NULL;
switch (message)
{
case WM_CREATE:
cxSource = GetSystemMetrics (SM_CXSIZEFRAME) +
GetSystemMetrics (SM_CXSIZE) ;
cySource = GetSystemMetrics (SM_CYSIZEFRAME) +
GetSystemMetrics (SM_CYCAPTION) ;
hfDefault=GetStockObject(DEFAULT_GUI_FONT);
// Create a push button
hwndButton=(HWND)CreateWindowEx(NULL,
"BUTTON",
"Calculate",
WS_TABSTOP|WS_VISIBLE|
WS_CHILD|BS_DEFPUSHBUTTON,
150,
550,
100,
25,
hwnd,
(HMENU)IDC_MAIN_BUTTON,
GetModuleHandle(NULL),
NULL);
SendMessage(hwndButton,
WM_SETFONT,
(WPARAM)hfDefault,
MAKELPARAM(FALSE,0));
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_KEYDOWN :
if( VK_LEFT)
{
hdc = GetDC(NULL); //get dc of whole screen
for (i = 0; i < 480; i++)
for (j = 0; j<= 640; j++)
{
color = GetPixel(hdc, i, j);
R_pixel[i][j] = GetRValue(color);
G_pixel[i][j] = GetGValue(color);
B_pixel[i][j] = GetBValue(color);
R_Mean_Value = R_Mean_Value + R_pixel[i][j];
G_Mean_Value = G_Mean_Value + G_pixel[i][j];
B_Mean_Value = B_Mean_Value + B_pixel[i][j];
}
R_Mean_Value = R_Mean_Value/no_of_pixels;
G_Mean_Value = G_Mean_Value/no_of_pixels;
B_Mean_Value = B_Mean_Value/no_of_pixels;
ReleaseDC (hwnd,hdc);
}
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
hBitmap = (HBITMAP)LoadImage(NULL,"C:\\Users\\Faro\\Desktop\ \image.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if(hBitmap == NULL)
MessageBox(hwnd, "Could not load Image!", "Error", MB_OK | MB_ICONEXCLAMATION);
hdcMem = CreateCompatibleDC(hdc);
hbmOld = (HBITMAP)SelectObject(hdcMem, hBitmap);
GetObject(hBitmap, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
DeleteObject(hBitmap);
EndPaint(hwnd, &ps);
return 0 ;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}