Jump to content
  • Advertisement

Archived

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

Jaxks

NEED HELP

This topic is 6935 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

I´ve done DX7 program but im just a newbie so could you point where program does wrong. // FLIPTEST.cpp : Defines the entry point for the application. // //Precompiled stuff #include "stdafx.h" #define TIMER_ID 1 #define TIMER_RATE 500 //Globals LPDIRECTDRAW7 lpdd7 =NULL; LPDIRECTDRAWSURFACE7 psurface =NULL; LPDIRECTDRAWSURFACE7 bsurface =NULL; DDSURFACEDESC2 ddSd; DDSCAPS2 ddsCaps; BOOL ErrorProc(HWND hwnd,HRESULT hret); BOOL CleanAll(); //Handles all errors messages from directdraw void DrawFrame() { static int phase=0; HDC hdc; HWND hwnd; HRESULT DxResult=NULL; DDSURFACEDESC2 ddsd; DDBLTFX ddbltfx; ddbltfx.dwSize=sizeof(ddbltfx); ddbltfx.dwFillColor=(phase==0? 0 : 123); ddsd.dwSize=sizeof(ddsd); DxResult=bsurface->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL); switch(DxResult) { case DD_OK: break; default: ErrorProc(hwnd,DxResult);break; } bsurface->Blt(NULL,NULL,NULL,DDBLT_COLORFILL,&ddbltfx); bsurface->Unlock(NULL); phase=(phase==0? phase=1 : phase=0); } BOOL ErrorProc(HWND hwnd,HRESULT hret) { switch(hret) { case DD_OK: { return 0; }break; case DDERR_ALREADYINITIALIZED: { CleanAll(); MessageBox(hwnd,"DirectX objekti on jo olemassa","DirectX Virhe",MB_OK); return(SendMessage(hwnd,WM_QUIT,0,0)); }break; default: { CleanAll(); MessageBox(hwnd,"Other Error","DirectX Error",MB_OK); return(SendMessage(hwnd,WM_QUIT,0,0)); }break; } return(1); } LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { HDC hdc; PAINTSTRUCT ps; HRESULT DxResult=NULL; switch(msg) { case WM_TIMER: { if(wparam!=TIMER_ID) break; DrawFrame(); while(1) { HRESULT hret; hret=psurface->Flip(NULL,0); if(hret==DD_OK) break; if(hret==DDERR_SURFACELOST) { hret=psurface->Restore(); if(hret!=DD_OK) break; } if(hret!=DDERR_WASSTILLDRAWING) break; } return(0); }break; case WM_PAINT: { hdc=BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps); return 0; }break; case WM_QUIT: { CleanAll(); PostQuitMessage(0); return(0); }break; case WM_SETCURSOR: { SetCursor(NULL); return TRUE; }break; case WM_KEYDOWN: // Handle any non-accelerated key commands switch (wparam) { case VK_ESCAPE: case VK_F12: PostMessage(hwnd, WM_QUIT, 0, 0); return 0; }break; default:break; } return (DefWindowProc( hwnd, msg,wparam,lparam)); } BOOL CleanAll() { if(lpdd7) { if(psurface) { psurface->Release(); psurface=NULL; } if(bsurface) { bsurface->Release(); bsurface=NULL; } lpdd7->Release(); lpdd7=NULL; } return(1); } static HWND Initialize(HINSTANCE hinst,HWND hwnd) { WNDCLASS wc; wc.cbClsExtra=NULL; wc.cbWndExtra=NULL; wc.hbrBackground=static_cast(GetStockObject(BLACK_BRUSH)); wc.hCursor=LoadCursor(hinst,IDC_ARROW); wc.hIcon=LoadIcon(hinst,MAKEINTRESOURCE(IDI_ICON1)); wc.hInstance=hinst; wc.lpszClassName="Game console"; wc.style=CS_HREDRAW/CS_VREDRAW; wc.lpfnWndProc= WindowProc; wc.lpszMenuName=NULL; if(!RegisterClass(&wc)) { CleanAll(); return(0); } if(hwnd!=CreateWindowEx(NULL,"Game console","Ddraw Program",WS_POPUPWINDOW/WS_VISIBLE,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hinst,NULL)) { CleanAll(); return(0); } HRESULT DxResult; DxResult=DirectDrawCreateEx(NULL,(VOID **)&lpdd7,IID_IDirectDraw7,NULL); if(DxResult!=DD_OK) { ErrorProc(hwnd,DxResult); return(0); } DxResult=lpdd7->SetCooperativeLevel(hwnd,DDSCL_EXCLUSIVE/DDSCL_FULLSCREEN); if(DxResult!=DD_OK) { ErrorProc(hwnd,DxResult); return(0); } DxResult=lpdd7->SetDisplayMode(800,600,8,0,NULL); if(DxResult!=DD_OK) { ErrorProc(hwnd,DxResult); return(0); } ZeroMemory(&psurface,sizeof(psurface)); ddSd.dwSize=sizeof(psurface); ddSd.dwFlags = DDSD_CAPS/DDSD_BACKBUFFERCOUNT; ddSd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE/DDSCAPS_COMPLEX/DDSCAPS_FLIP; ddSd.dwBackBufferCount = 1; DxResult=lpdd7->CreateSurface(&ddSd,&psurface,NULL); if(DxResult!=DD_OK) { ErrorProc(hwnd,DxResult); return 0; } ZeroMemory(&ddsCaps,sizeof(ddsCaps)); ddsCaps.dwCaps=DDSCAPS_BACKBUFFER; DxResult=psurface->GetAttachedSurface(&ddsCaps,&bsurface); if(DxResult!=DD_OK//DxResult==NULL) { ErrorProc(hwnd,DxResult); return(0); } if(TIMER_ID!=SetTimer(hwnd,TIMER_ID,TIMER_RATE,NULL)) return(0); return hwnd; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd=0; hwnd=Initialize(hInstance,hwnd); MSG msg; while(1) { if (PeekMessage(&msg,hwnd,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } // end if } KillTimer(hwnd,TIMER_ID); return msg.wParam; }

Share this post


Link to post
Share on other sites
Advertisement
Ack! You need to change the formating of that thing so its more readable! Before all the code, put the word "code" in brackets -> [ ] <- and right after all the code, put "/code" in brackets (with the /). That''ll help the formating.

Also, are you getting errors? If so, what are they? What lines? Or is it just not doing what you want it to do?

Share this post


Link to post
Share on other sites
My code isn´t readable yet. There is no errors in compiling or linking. Program should flip two surfaces and blink the screen in different colors(using DDBLTFX colorfill) I don´t know if my fillcolor selection is done wrong in Drawframe function. By the way does somebody know how to use breakpoints in VC++6 Introductory edition. Using breakpoints
should done my job easier. I´ve also thinking does my Errorcheck show messagebox if error occurs. And what is advantage using va lists.And does Blt() need Locking surface I tried to remove Lock but that doesn´t get me any further. So could tell If there are some errors in Windows or Initializing DX code if there isn´t I will get blitting work some day.

Share this post


Link to post
Share on other sites
First of all, you can''t use breakpoints in a DirectX app unless you have multiple monitors set up, to my knowledge. Although multiple monitors works great, if you have the money, or another monitor and video card (that''s compatible) laying around.

Blt should have the surface unlocked, because it''s a hardware function. If it''s locked, then it will return DDERR_SURFACEBUSY.

Your error checking will only display a messagebox if you call MessageBox() with it, so yes it should.

But listen, there''s no way I''m gonna read though all that code to debug it. If it doesn''t work, the best thing to do it to look through it yourself, review whatever source you got the knowledge from, and try to fix it yourself. Being a newbie doesn''t excuse you from knowing your code I mean, posting the whole program is a LOT of code to expect us to read.

I''m not trying to be harsh, but finding your own mistakes is the best way to learn.

Good luck

------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!