(Borland bcc55 compiler, Windows XP)
I just dived back into win32 programming hoping I might be able to solve my problems... But, nope, windows still hates me :P.
I started reading forgers tutorial, I read all of it, then starting some code. Its a carbon copy from the one on the site, but it wont work. This line:
Code:
HBITMAP hbmOld = SelectObject(hdcMem, ScreenDisplay_Object); //Line 28
(ScreenDisplay_Object is a global HBITMAP.)
Code:
C:\Borland\BCC55\Bin>bcc32 -tW c:\M.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
c:\M.cpp:
Error E2034 c:\M.cpp 44: Cannot convert 'void *' to 'HBITMAP__ *' in function
__stdcall WndProc(HWND__ *,unsigned int,unsigned int,long)
*** 1 errors in Compile ***
Am I right in assuming SelectObject returns nothing? Well, based on that idea, I tried this:
Code:
HBITMAP hbmOld;
SelectObject(hdcMem, ScreenDisplay_Object); //Line 29
But, I get a resource error.
Code:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unable to open file 'BIT.RC'
C:\Borland\BCC55\Bin>
Code:
#include <windows.h>
#pragma resource "Bit.rc"
As far as I know #pragma should get the resource to open. Do I have to put it somewhere other than in the files directory?
Heres the entire program as it stands now:
Code:
#include <windows.h>
#pragma resource "Bit.rc"
HBITMAP ScreenDisplay_Object = NULL;
const char g_szClassName[] = "myWindowClass";
#define IDB_BALL 101
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) {
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
DeleteObject(ScreenDisplay_Object);
PostQuitMessage(0);
break;
case WM_CREATE:
ScreenDisplay_Object = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BALL));
if(ScreenDisplay_Object == NULL)
MessageBox(hwnd, "Could not load object!", "Error", MB_OK | MB_ICONEXCLAMATION);
break;
case WM_PAINT: {
BITMAP bm;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld;
SelectObject(hdcMem, ScreenDisplay_Object); //
GetObject(ScreenDisplay_Object, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "The title of my window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
if(hwnd == NULL) {
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Gah, working windows resource files always makes my head ache >.>. As I said, this is basicaly the forgers tutorial with some minor adjustments. Anyone else using borlands compiler figured out how to compile theyse? And, will making that alteration to the tutorial completely change how the program acts? (Seems like it would, but it doesnt compile in the first place -,-)
Thank you!