I'm trying to learn programming and I've got quite far so far, but I've run
into a few problems, the main ones involving DrawDibDraw. First, 12 bytes
seem to be missing from "bitmapinfoheader" that I see in the hex edittor.
Second, I'm puzzled about the difference with the Dst and Src values and what
they're for. Below my code is where my issues are explained in better detail. -
// First Windows app.cpp : Defines the entry point for the application.
-
/*
-
To do before making the first useful Windows application - what background
-
scaling is (or "The Supernatural Olympics" version 1.1):
-
Draw images
-
Syncronize drawing images with monitor refresh rate
-
Call a function upon pressing a key
-
*/
-
-
/* Trim fat from windows*/
-
#define WIN32_LEAN_AND_MEAN
-
#pragma comment(linker, "/subsystem:windows")
-
/* Pre-processor directives*/
-
#include "stdafx.h"
-
#include <stdio.h>
-
#include <windows.h>
-
-
// defines and global vars
-
#define x 0
-
#define y 1
-
-
short screen_size[2]; // screen resolution (e.g. 1920x1440)
-
short window_size_base[2]; // expected window size
-
short window_size[2]; // actual window size
-
short window_pos[2]; // window position
-
short title_bar_height; // height of the title bar in pixels
-
short window_border[2]; // size of the window border
-
-
int file_handle; // handle for reading/writing files
-
char bmp_image[]; // data for the bitmap image
-
-
int *img_handle; // pointer for a handle
-
int *HDC_handle; // pointer for HDC handle
-
-
BITMAPINFOHEADER bmp_head;
-
-
void draw_test_image()
-
{
-
img_handle = DrawDibOpen();
-
-
file_handle = fopen("C:\\My Documents\\My programs\\ulillilliacity.bmp",
-
"rb"); // read the source BMP file to display, binary mode
-
fseek(file_handle, 2, seek_set); // skip the first two bytes, the file
-
identifier, the string "BM"
-
// fill the struct reading from the file
-
fread(&bmp_head.biSize, 4, 1, file_handle); // actual file size
-
// 12 bytes missing here, according to what I'm seeing in the hex edittor
-
fread(&bmp_head.biWidth, 4, 1, file_handle);
-
fread(&bmp_head.biHeight, 4, 1, file_handle);
-
fread(&bmp_head.biPlanes, 2, 1, file_handle);
-
fread(&bmp_head.biBitCount, 2, 1, file_handle);
-
fread(&bmp_head.biCompression, 4, 1, file_handle);
-
fread(&bmp_head.biSizeImage, 4, 1, file_handle);
-
fread(&bmp_head.biXPelsPerMeter, 4, 1, file_handle);
-
fread(&bmp_head.biYPelsPerMeter, 4, 1, file_handle);
-
fread(&bmp_head.biClrUsed, 4, 1, file_handle);
-
fread(&bmp_head.biClrImportant, 4, 1, file_handle);
-
fread(&bmp_head.biClrImportant, 4, 1, file_handle);
-
fread(&bmp_image, 1, bmp_head.biSizeImage, file_handle); // read the
-
remainder of the bits, the image data part
-
fclose(file_handle);
-
-
DrawDibDraw(img_handle, hDC, 64, 48, 512, 384, bmp_head, bmp_image, 64, 48,
-
512, 384, 0); // still not sure about the first group of numbers
-
DrawDibClose(img_handle); // free the resources
-
}
-
-
/* Windows Procedure Event Handler*/
-
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
-
lParam)
-
{
-
PAINTSTRUCT paintStruct;
-
/* Device Context*/
-
HDC hDC; // is this the DC declaration?
-
/* Text for display*/
-
char string[] = "Image test - there should be an image below";
-
/* Switch message, condition that is met will execute*/
-
switch(message)
-
{
-
/* Window is being created*/
-
case WM_CREATE:
-
return 0;
-
break;
-
/* Window is closing*/
-
case WM_CLOSE:
-
PostQuitMessage(0);
-
return 0;
-
break;
-
/* Window needs update*/
-
case WM_PAINT:
-
hDC = BeginPaint(hwnd,&paintStruct);
-
/* Set txt color to blue*/
-
SetTextColor(hDC, COLORREF(0x00FF8040));
-
/* Display text in middle of window*/
-
TextOut(hDC,0,2,string,sizeof(string)-1);
-
EndPaint(hwnd, &paintStruct);
-
return 0;
-
break;
-
default:
-
break;
-
}
-
return (DefWindowProc(hwnd,message,wParam,lParam));
-
}
-
/* Main function*/
-
int APIENTRY WinMain(HINSTANCE hInstance,
-
HINSTANCE hPrevInstance,
-
LPSTR lpCmdLine,
-
int nCmdShow)
-
{
-
WNDCLASSEX windowClass; //window class
-
HWND hwnd; //window handle
-
MSG msg; //message
-
bool done; //flag saying when app is complete
-
/* Fill out the window class structure*/
-
windowClass.cbSize = sizeof(WNDCLASSEX);
-
windowClass.style = CS_HREDRAW | CS_VREDRAW;
-
windowClass.lpfnWndProc = WndProc;
-
windowClass.cbClsExtra = 0;
-
windowClass.cbWndExtra = 0;
-
windowClass.hInstance = hInstance;
-
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
-
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
-
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
-
windowClass.lpszMenuName = NULL;
-
windowClass.lpszClassName = "MyClass";
-
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
-
/* Register window class*/
-
if (!RegisterClassEx(&windowClass))
-
{
-
return 0;
-
}
-
-
/* SM_CXBORDER is 1
-
SM_CYBORDER is 1
-
SM_CXEDGE is 2
-
SM_CYEDGE is 2
-
SM_CXFIXEDFRAME is 3
-
SM_CYFIXEDFRAME is 3
-
SM_CXSIZEFRAME is 4
-
SM_CYSIZEFRAME is 4
-
SM_CYCAPTION is 18
-
*/
-
-
window_border[x] = GetSystemMetrics(SM_CXSIZEFRAME); // obtain border
-
sizes, title bar height, and operating resolution
-
window_border[y] = GetSystemMetrics(SM_CYSIZEFRAME);
-
title_bar_height = GetSystemMetrics(SM_CYCAPTION); // obtain height of the
-
title bar
-
screen_size[x] = GetSystemMetrics(SM_CXSCREEN); // operating resolution
-
screen_size[y] = GetSystemMetrics(SM_CYSCREEN);
-
window_size_base[x] = 640; // interior window size
-
window_size_base[y] = 480;
-
window_size[x] = window_size_base[x]+window_border[x]*2; // full window
-
size, including borders and title bar
-
window_size[y] = window_size_base[y]+window_border[y]*2+title_bar_height;
-
window_pos[x] = (screen_size[x]/2)-(window_size[x]/2); // center the window
-
window_pos[y] = (screen_size[y]/2)-(window_size[y]/2);
-
-
/* Class registerd, so now create window*/
-
hwnd = CreateWindowEx(NULL, //extended style
-
"MyClass", //class name
-
"First Windows app", //app name
-
WS_OVERLAPPEDWINDOW | //window style
-
WS_VISIBLE |
-
WS_SYSMENU,
-
window_pos[x],window_pos[y], //x/y coords
-
window_size[x],window_size[y], //width,height
-
NULL, //handle to parent
-
NULL, //handle to menu
-
hInstance, //application instance
-
NULL); //no extra parameter's
-
/* Check if window creation failed*/
-
if (!hwnd)
-
return 0;
-
done = false; //initialize loop condition variable
-
/* main message loop*/
-
-
draw_test_image();
-
-
while(!done)
-
{
-
PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);
-
if (msg.message == WM_QUIT) //check for a quit message
-
{
-
free(*img_handle);
-
done = true; //if found, quit app
-
}
-
else
-
{
-
/* Translate and dispatch to event queue*/
-
TranslateMessage(&msg);
-
DispatchMessage(&msg);
-
}
-
}
-
return msg.wParam;
-
}
-
These are my issues:
1. While reading from the BMP file, there seems to be an extra 12 bytes in
the file, as seen in my hex edittor (XVI32). The location of the missing
bytes is commented where it is found. I saved the 24-bit uncompressed BMP
file with "The GIMP".
2. I don't know if I set up the DrawDibDraw function properly, the pointers
and handles especially. I'm still confused about the Dst and Src values.
3. I want the interior part of the window to be 640x480, which excludes
borders, menus, and the title bar. I don't have any menus at the moment
though. I also want the window itself to be centered. The method I have works
fine, but seems awfully complicated so I'm wondering if there's a better way.
4. Without the bitmap reading stuff, my program is using 100% of the CPU
when all other windows programs barely use any of the CPU. Why is this and
how do I fix it? I suspect it has something to do with the while loop in the
WinMain function.
--
Some programming:
void bluewater() {while(game_runs == 1)
{if fox.position == in_blue_water) {fox.health -= 1;}
else {fox.wants_to_get_wet = true;} wait_frames(1);}} 1 3985
1. While reading from the BMP file, there seems to be an extra 12 bytes in
the file, as seen in my hex edittor (XVI32). The location of the missing
bytes is commented where it is found. I saved the 24-bit uncompressed BMP
file with "The GIMP".
It is not "extra". It is the BITMAPFILEHEADER structure.
2. I don't know if I set up the DrawDibDraw function properly, the
pointers
and handles especially. I'm still confused about the Dst and Src values.
The Src refers to a rectangle that defines that portion of your bitmap that
you wish to render.
You may choose the entire bitmap or part of the bitmap to render(e.g., crop
your bitmap).
The Dst refers to a rectangle that defines that portion of your window that
you wish to render to.
Again, you may choose to render to the entire window or some part of the
window.
The DrawDibDraw API is antiquated. However, there are many examples
included in the Platform SDK and/or online at MSDN's website.
You may wish to investigate the gdiplus API. It allows your to load and
draw a bitmap with a few lines of code.
"ulillillia" <ul********@discussions.microsoft.comwrote in message
news:20**********************************@microsof t.com...
I'm trying to learn programming and I've got quite far so far, but I've
run
into a few problems, the main ones involving DrawDibDraw. First, 12 bytes
seem to be missing from "bitmapinfoheader" that I see in the hex edittor.
Second, I'm puzzled about the difference with the Dst and Src values and
what
they're for. Below my code is where my issues are explained in better
detail.
-
// First Windows app.cpp : Defines the entry point for the application.
-
/*
-
To do before making the first useful Windows application - what background
-
scaling is (or "The Supernatural Olympics" version 1.1):
-
Draw images
-
Syncronize drawing images with monitor refresh rate
-
Call a function upon pressing a key
-
*/
-
/* Trim fat from windows*/
-
#define WIN32_LEAN_AND_MEAN
-
#pragma comment(linker, "/subsystem:windows")
-
/* Pre-processor directives*/
-
#include "stdafx.h"
-
#include <stdio.h>
-
#include <windows.h>
-
// defines and global vars
-
#define x 0
-
#define y 1
-
short screen_size[2]; // screen resolution (e.g. 1920x1440)
-
short window_size_base[2]; // expected window size
-
short window_size[2]; // actual window size
-
short window_pos[2]; // window position
-
short title_bar_height; // height of the title bar in pixels
-
short window_border[2]; // size of the window border
-
int file_handle; // handle for reading/writing files
-
char bmp_image[]; // data for the bitmap image
-
int *img_handle; // pointer for a handle
-
int *HDC_handle; // pointer for HDC handle
-
BITMAPINFOHEADER bmp_head;
-
void draw_test_image()
-
{
-
img_handle = DrawDibOpen();
-
file_handle = fopen("C:\\My Documents\\My programs\\ulillilliacity.bmp",
-
"rb"); // read the source BMP file to display, binary mode
-
fseek(file_handle, 2, seek_set); // skip the first two bytes, the file
-
identifier, the string "BM"
-
// fill the struct reading from the file
-
fread(&bmp_head.biSize, 4, 1, file_handle); // actual file size
-
// 12 bytes missing here, according to what I'm seeing in the hex edittor
-
fread(&bmp_head.biWidth, 4, 1, file_handle);
-
fread(&bmp_head.biHeight, 4, 1, file_handle);
-
fread(&bmp_head.biPlanes, 2, 1, file_handle);
-
fread(&bmp_head.biBitCount, 2, 1, file_handle);
-
fread(&bmp_head.biCompression, 4, 1, file_handle);
-
fread(&bmp_head.biSizeImage, 4, 1, file_handle);
-
fread(&bmp_head.biXPelsPerMeter, 4, 1, file_handle);
-
fread(&bmp_head.biYPelsPerMeter, 4, 1, file_handle);
-
fread(&bmp_head.biClrUsed, 4, 1, file_handle);
-
fread(&bmp_head.biClrImportant, 4, 1, file_handle);
-
fread(&bmp_head.biClrImportant, 4, 1, file_handle);
-
fread(&bmp_image, 1, bmp_head.biSizeImage, file_handle); // read the
-
remainder of the bits, the image data part
-
fclose(file_handle);
-
DrawDibDraw(img_handle, hDC, 64, 48, 512, 384, bmp_head, bmp_image, 64,
-
48,
-
512, 384, 0); // still not sure about the first group of numbers
-
DrawDibClose(img_handle); // free the resources
-
}
-
/* Windows Procedure Event Handler*/
-
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
-
lParam)
-
{
-
PAINTSTRUCT paintStruct;
-
/* Device Context*/
-
HDC hDC; // is this the DC declaration?
-
/* Text for display*/
-
char string[] = "Image test - there should be an image below";
-
/* Switch message, condition that is met will execute*/
-
switch(message)
-
{
-
/* Window is being created*/
-
case WM_CREATE:
-
return 0;
-
break;
-
/* Window is closing*/
-
case WM_CLOSE:
-
PostQuitMessage(0);
-
return 0;
-
break;
-
/* Window needs update*/
-
case WM_PAINT:
-
hDC = BeginPaint(hwnd,&paintStruct);
-
/* Set txt color to blue*/
-
SetTextColor(hDC, COLORREF(0x00FF8040));
-
/* Display text in middle of window*/
-
TextOut(hDC,0,2,string,sizeof(string)-1);
-
EndPaint(hwnd, &paintStruct);
-
return 0;
-
break;
-
default:
-
break;
-
}
-
return (DefWindowProc(hwnd,message,wParam,lParam));
-
}
-
/* Main function*/
-
int APIENTRY WinMain(HINSTANCE hInstance,
-
HINSTANCE hPrevInstance,
-
LPSTR lpCmdLine,
-
int nCmdShow)
-
{
-
WNDCLASSEX windowClass; //window class
-
HWND hwnd; //window handle
-
MSG msg; //message
-
bool done; //flag saying when app is complete
-
/* Fill out the window class structure*/
-
windowClass.cbSize = sizeof(WNDCLASSEX);
-
windowClass.style = CS_HREDRAW | CS_VREDRAW;
-
windowClass.lpfnWndProc = WndProc;
-
windowClass.cbClsExtra = 0;
-
windowClass.cbWndExtra = 0;
-
windowClass.hInstance = hInstance;
-
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
-
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
-
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
-
windowClass.lpszMenuName = NULL;
-
windowClass.lpszClassName = "MyClass";
-
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
-
/* Register window class*/
-
if (!RegisterClassEx(&windowClass))
-
{
-
return 0;
-
}
-
/* SM_CXBORDER is 1
-
SM_CYBORDER is 1
-
SM_CXEDGE is 2
-
SM_CYEDGE is 2
-
SM_CXFIXEDFRAME is 3
-
SM_CYFIXEDFRAME is 3
-
SM_CXSIZEFRAME is 4
-
SM_CYSIZEFRAME is 4
-
SM_CYCAPTION is 18
-
*/
-
window_border[x] = GetSystemMetrics(SM_CXSIZEFRAME); // obtain border
-
sizes, title bar height, and operating resolution
-
window_border[y] = GetSystemMetrics(SM_CYSIZEFRAME);
-
title_bar_height = GetSystemMetrics(SM_CYCAPTION); // obtain height of the
-
title bar
-
screen_size[x] = GetSystemMetrics(SM_CXSCREEN); // operating resolution
-
screen_size[y] = GetSystemMetrics(SM_CYSCREEN);
-
window_size_base[x] = 640; // interior window size
-
window_size_base[y] = 480;
-
window_size[x] = window_size_base[x]+window_border[x]*2; // full window
-
size, including borders and title bar
-
window_size[y] = window_size_base[y]+window_border[y]*2+title_bar_height;
-
window_pos[x] = (screen_size[x]/2)-(window_size[x]/2); // center the
-
window
-
window_pos[y] = (screen_size[y]/2)-(window_size[y]/2);
-
/* Class registerd, so now create window*/
-
hwnd = CreateWindowEx(NULL, //extended style
-
"MyClass", //class name
-
"First Windows app", //app name
-
WS_OVERLAPPEDWINDOW | //window style
-
WS_VISIBLE |
-
WS_SYSMENU,
-
window_pos[x],window_pos[y], //x/y coords
-
window_size[x],window_size[y], //width,height
-
NULL, //handle to parent
-
NULL, //handle to menu
-
hInstance, //application instance
-
NULL); //no extra parameter's
-
/* Check if window creation failed*/
-
if (!hwnd)
-
return 0;
-
done = false; //initialize loop condition variable
-
/* main message loop*/
-
draw_test_image();
-
while(!done)
-
{
-
PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);
-
if (msg.message == WM_QUIT) //check for a quit message
-
{
-
free(*img_handle);
-
done = true; //if found, quit app
-
}
-
else
-
{
-
/* Translate and dispatch to event queue*/
-
TranslateMessage(&msg);
-
DispatchMessage(&msg);
-
}
-
}
-
return msg.wParam;
-
}
-
These are my issues:
1. While reading from the BMP file, there seems to be an extra 12 bytes in
the file, as seen in my hex edittor (XVI32). The location of the missing
bytes is commented where it is found. I saved the 24-bit uncompressed BMP
file with "The GIMP".
2. I don't know if I set up the DrawDibDraw function properly, the
pointers
and handles especially. I'm still confused about the Dst and Src values.
3. I want the interior part of the window to be 640x480, which excludes
borders, menus, and the title bar. I don't have any menus at the moment
though. I also want the window itself to be centered. The method I have
works
fine, but seems awfully complicated so I'm wondering if there's a better
way.
4. Without the bitmap reading stuff, my program is using 100% of the CPU
when all other windows programs barely use any of the CPU. Why is this and
how do I fix it? I suspect it has something to do with the while loop in
the
WinMain function.
--
Some programming:
void bluewater() {while(game_runs == 1)
{if fox.position == in_blue_water) {fox.health -= 1;}
else {fox.wants_to_get_wet = true;} wait_frames(1);}}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Murat Aykut |
last post by:
I want to write Video Grabber program. For this purpose, I'm using VFW
capCapture structure, and DrawDibDraw on printing to screen. I wrote
that code, but it has no action (for frame rate). Plaese...
|
by: Qindong Zhang |
last post by:
I get my memory address (Pointer) from an API call, and then pass this
address to DrawDibDraw function, it works fine on Windows 2000, but
not works on Windows XP (get green screen).
Here...
|
by: Qindong Zhang |
last post by:
I get my memory address (Pointer) from an API call, and then pass this
address to DrawDibDraw function, it works fine on Windows 2000, but
not works on Windows XP (get green screen).
Here...
|
by: Qindong Zhang |
last post by:
I get my memory address (Pointer) from an API call, and then pass this
address to DrawDibDraw function, it works fine on Windows 2000, but
not works on Windows XP (get green screen).
Here...
|
by: Iwanow |
last post by:
Hello!
My goal is to develop a program that opens a bitmap, copies its pixels
to an ArrayList in order to perform some complex calculations (edge
detection, Hough transform etc.), and save...
|
by: =?Utf-8?B?dWxpbGxpbGxpYQ==?= |
last post by:
My code compiles without any errors and the only warnings are irrelevant to
the function used to load and display the image with. The file loads
properly, but DrawDibDraw isn't displaying anything...
|
by: kentgorrell |
last post by:
I had a wonderful time working out how to read and write BLOBs using GetChunk until I found the new streaming object in ADO 2.6 very easy.
Now I am confronted with DIBs
The code I have is VB6 but...
|
by: kentgorrell |
last post by:
Further to an earlier post I have made progress and can now display a DIB (Device Independent Bitmap) on a VB6 form using this code.
Set Field = Adodc1.Recordset.Fields.Item("Student_Photo")
...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |