• Advertisement

Archived

This topic is now archived and is closed to further replies.

MY WINDOW!! WHAT?

This topic is 6549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I ran this program, no window came up. Why? Here''s the code(long) #define WIN32_LEAN_AND_MEAN #include #include #include #include #include #include HWND windowh = NULL; HINSTANCE instance= NULL; int GameInit(); int GameMain(); int GameEnd(); LPDIRECTDRAW lpdd = NULL; LPDIRECTDRAWSURFACE pbuff= NULL; LPDIRECTDRAWSURFACE bbuff= NULL; DDSCAPS ddcap; DDSURFACEDESC ddsd; DDBLTFX bltfx; HBITMAP hbm; HDC imagedc =NULL; HDC surfacedc =NULL; LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; switch(msg) { case WM_CREATE: { return(0); }break; case WM_PAINT: { hdc = BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); return(0); }break; case WM_DESTROY: { PostQuitMessage(0); } default:break; } return(DefWindowProc(hwnd, msg, wparam, lparam)); } int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd) { HDC hdc; HWND hwnd; WNDCLASSEX wc; PAINTSTRUCT ps; MSG msg; wc.style =CS_DBLCLKS/CS_OWNDC/ CS_HREDRAW/CS_VREDRAW; wc.cbSize =sizeof(WNDCLASSEX); wc.cbClsExtra =0; wc.cbWndExtra =0; wc.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH); wc.hCursor =LoadCursor(NULL, IDC_ARROW); wc.hIcon =LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm =LoadIcon(NULL, IDI_APPLICATION); wc.hInstance =hinstance; wc.lpfnWndProc =WindowProc; wc.lpszClassName ="wc"; wc.lpszMenuName =NULL; if(!RegisterClassEx(&wc)) return(0); if(!(CreateWindowEx(NULL, "WINDOWCLASS", "BLTEX", WS_OVERLAPPEDWINDOW/WS_VISIBLE, 0, 0,640, 480, NULL, NULL, hinstance, NULL))) { return(0); } ShowCursor(FALSE); instance = hinstance; windowh = hwnd; GameInit(); while(1) { if(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) break; GameMain(); TranslateMessage(&msg); DispatchMessage(&msg); } } GameEnd(); return(msg.wParam); } int GameInit() { if(FAILED(DirectDrawCreate(NULL, &lpdd, NULL))) { return(0); } if(FAILED(lpdd->SetCooperativeLevel(windowh, DDSCL_EXCLUSIVE/ DDSCL_FULLSCREEN/ DDSCL_ALLOWREBOOT))) { return(0); } if(FAILED(lpdd->SetDisplayMode(640, 480, 16))) { return(0); } memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize =sizeof(ddsd); ddsd.dwFlags =DDSD_CAPS; ddsd.ddsCaps.dwCaps =DDSCAPS_PRIMARYSURFACE/DDSCAPS_FLIP; if(FAILED(lpdd->CreateSurface(&ddsd, &pbuff, NULL))) { return(0); } ddsd.dwSize =sizeof(ddsd); ddsd.dwFlags =DDSD_CAPS/DDSD_BACKBUFFERCOUNT; ddsd.dwBackBufferCount =1; ddsd.ddsCaps.dwCaps =DDSCAPS_BACKBUFFER; if(FAILED(pbuff->GetAttachedSurface(&ddcap, &bbuff))) { return(0); } return(1); } int GameMain() { if(FAILED(bbuff->GetSurfaceDesc(&ddsd))) { return(0); } hbm =(HBITMAP)LoadImage(NULL, "Image.bmp", IMAGE_BITMAP, ddsd.dwWidth, ddsd.dwHeight, LR_LOADFROMFILE/LR_CREATEDIBSECTION); imagedc = CreateCompatibleDC(NULL); SelectObject(imagedc, hbm); if(FAILED(bbuff->GetDC(&surfacedc))) { return(0); } if(BitBlt(surfacedc,0,0,ddsd.dwHeight, ddsd.dwWidth, imagedc, 0, 0, SRCCOPY) == FALSE) { return(0); } if(FAILED(pbuff->Flip(NULL, DDFLIP_WAIT))) { return(0); } return(1); } int GameEnd() { if(imagedc) { bbuff->ReleaseDC(imagedc); } if(imagedc) { DeleteDC(imagedc); } if(hbm) { DeleteObject(hbm); } if(pbuff) { pbuff->Release(); } if(bbuff) { bbuff->Release(); } if(lpdd) { lpdd->Release(); } return(1); } Games are the path to another dimension.

Share this post


Link to post
Share on other sites
Advertisement
I believe your missing a call to ShowWindow (put it right before ShowCursor).

--TheGoop

Share this post


Link to post
Share on other sites
now I have another problem, my window shows, but now, the bitmap doesn''t show, what''s wrong? Here''s the code(long and the includes are in quotes for HTML:


#define WIN32_LEAN_AND_MEAN

#include "windows.h"
#include "windowsx.h"
#include "stdio.h"
#include "conio.h"
#include "memory.h"
#include "ddraw.h"



HWND windowh = NULL;
HINSTANCE instance= NULL;

int GameInit();
int GameMain();
int GameEnd();

LPDIRECTDRAW lpdd = NULL;
LPDIRECTDRAWSURFACE pbuff= NULL;
LPDIRECTDRAWSURFACE bbuff= NULL;
DDSCAPS ddcap;
DDSURFACEDESC ddsd;
DDBLTFX bltfx;
HBITMAP hbm;
HDC imagedc =NULL;
HDC surfacedc =NULL;

LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{

PAINTSTRUCT ps;
HDC hdc;
char buffer[80];


switch(msg)
{
case WM_CREATE:
{

return(0);
} break;

case WM_PAINT:
{

hdc = BeginPaint(hwnd,&ps);


EndPaint(hwnd,&ps);


return(0);
} break;

case WM_DESTROY:
{


PostQuitMessage(0);


return(0);
} break;

default:break;

}


return (DefWindowProc(hwnd, msg, wparam, lparam));

}
int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{

WNDCLASSEX winclass;
HWND hwnd;
MSG msg;
HDC hdc;


winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS / CS_OWNDC /
CS_HREDRAW / CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = "WINDOW_CLASS_NAME";
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);


instance = hinstance;


if (!RegisterClassEx(&winclass))
return(0);


if (!(hwnd = CreateWindowEx(NULL,
"WINDOW_CLASS_NAME",
"BlitEx",
WS_POPUP / WS_VISIBLE,
0,0,
480,640,
NULL,
NULL,
hinstance,
NULL)))


windowh = hwnd;


GameInit();


while(TRUE)
{

if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{

if (msg.message == WM_QUIT)
break;


TranslateMessage(&msg);


DispatchMessage(&msg);
}


GameMain();

}


GameEnd();


return(msg.wParam);

}

int GameInit()
{
if(FAILED(DirectDrawCreate(NULL, &lpdd, NULL)))
{
return(0);
}

if(FAILED(lpdd->SetCooperativeLevel(windowh,
DDSCL_EXCLUSIVE/
DDSCL_FULLSCREEN/
DDSCL_ALLOWREBOOT)))
{
return(0);
}

if(FAILED(lpdd->SetDisplayMode(640, 480, 16)))
{
return(0);
}

memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize =sizeof(ddsd);
ddsd.dwFlags =DDSD_CAPS;
ddsd.ddsCaps.dwCaps =DDSCAPS_PRIMARYSURFACE/DDSCAPS_FLIP;

if(FAILED(lpdd->CreateSurface(&ddsd, &pbuff, NULL)))
{
return(0);
}

return(1);
}

int GameMain()
{


hbm =(HBITMAP)LoadImage(NULL, "Image.bmp", IMAGE_BITMAP,
ddsd.dwWidth, ddsd.dwHeight,
LR_LOADFROMFILE/LR_CREATEDIBSECTION);

imagedc = CreateCompatibleDC(NULL);
SelectObject(imagedc, hbm);

if(FAILED(pbuff->GetDC(&surfacedc)))
{
return(0);
}

if(BitBlt(surfacedc,0,0,ddsd.dwHeight, ddsd.dwWidth,
imagedc, 0, 0, SRCCOPY) == FALSE)
{
return(0);
}

return(1);
}

int GameEnd()
{

if(imagedc)
{
pbuff->ReleaseDC(imagedc);
}
if(imagedc)
{
DeleteDC(imagedc);
}
if(hbm)
{
DeleteObject(hbm);
}
if(pbuff)
{
pbuff->Release();
}

if(lpdd)
{
lpdd->Release();
}
return(1);
}

Share this post


Link to post
Share on other sites
Hey! I''ve read 3 books on the subject, so don''t give me that! I don''t know what''s wrong, I''ve done it before, but this time, I have no Idea what''s wrong! I find that comment extremely offensive!

Share this post


Link to post
Share on other sites
I''m not entirely sure why it doesn''t display your bitmap, but I can make a few suggestions (other than "lose the attitude", which seems to apply to your last post).

GameMain is called repeatedly, isn''t it? It certainly looks like it will be caused each time the program polls the message loop. If thats the case, why are you loading a bitmap from a file for every single frame??? Even if there is nothing wrong with your code, thats amazingly inefficient. It would make more sense to load the bitmap into a surface in GameInit, and then use DirectDraw''s Blt command to put it into the back buffer.

You spend quite a bit of time returning different values from GameMain - but you never even check them. You could make your debugging a whole lot easier if you actually trap the error codes you are generating........

Share this post


Link to post
Share on other sites

  • Advertisement