   Want to draw pixels but get nothing
  I want make a 640*480 fullscreen demo to continually draw pixels.But only a blank fullscreen appears and then disappears right away.Here is the whole codes.I don't know which part causes the problem, so sorry to trouble you reading so long codes.And besides this, I want to ask do directx9 have DirectDraw? I am reading a book using directx7 and I heard that in directx8 or later versions there is no DirectDraw. If it is true, then how to draw 2D graphics in those versions?Thanks a billion.#define WIN32_LEAN_AND_MEAN//includes#include &lt;windows.h&gt;#include &lt;windowsx.h&gt;#include &lt;stdio.h&gt;#include &lt;math.h&gt;#include &lt;mmsystem.h&gt;#include &lt;stdlib.h&gt;#include &lt;draw.h&gt;#include &lt;malloc.h&gt;#include &lt;iostream.h&gt;//defines#define WINDOW_CLASS_NAME "WINCLASS1"#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)#define SCREEN_WIDTH 640#define SCREEN_HEIGHT 480#define SCREEN_BPP 8 // bits per pixel#define MAX_COLORS 256//typedefstypedef unsigned short USHORT;typedef unsigned short WORD;typedef unsigned char UCHAR;typedef unsigned char BYTE;//globalsHWND main_window_handle = NULL;HINSTANCE hinstance_app = NULL;//directdrawLPDIRECTDRAW7 lpdd = NULL; LPDIRECTDRAWSURFACE7 lpddsprimary = NULL; LPDIRECTDRAWPALETTE lpddpal = NULL; DDSURFACEDESC2 ddsd; PALETTEENTRY palette[256]; 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_LBUTTONDBLCLK:{PostQuitMessage(0);return(0);}break;case WM_CLOSE:{int result = MessageBox(hwnd,"Do you really want to quit?","Quit",MB_YESNO|MB_ICONQUESTION);if(result == IDYES){return(DefWindowProc(hwnd,msg,wparam,lparam));}else return(0);}break;case WM_DESTROY:{PostQuitMessage(0);return(0);}break;default:break;}return(DefWindowProc(hwnd,msg,wparam,lparam));}int Game_Init(void *parms = NULL, int num_parms = 0){if(FAILED(DirectDrawCreateEx(NULL,(void**)&lpdd,IID_IDirectDraw7,NULL))){return(0);}if(FAILED(lpdd-&gt;SetCooperativeLevel(main_window_handle,DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))){return(0);}if(FAILED(lpdd-&gt;SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,0,0))){return(0);}memset(&ddsd,0,sizeof(ddsd));ddsd.dwSize = sizeof(ddsd);ddsd.dwSize = DDSD_CAPS;ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;if(FAILED(lpdd-&gt;CreateSurface(&ddsd,&lpddsprimary,NULL))){return(0);}for(int color = 1; color &lt; 255; color++){palette.peBlue = rand()%<span class="cpp-number">256</span>;palette.peGreen = rand()%<span class="cpp-number">255</span>;palette.peRed = rand()%<span class="cpp-number">255</span>;palette.peFlags = PC_NOCOLLAPSE; }palette[<span class="cpp-number">0</span>].peRed = <span class="cpp-number">0</span>;palette[<span class="cpp-number">0</span>].peBlue = <span class="cpp-number">0</span>;palette[<span class="cpp-number">0</span>].peGreen = <span class="cpp-number">0</span>;palette[<span class="cpp-number">0</span>].peFlags = PC_NOCOLLAPSE; palette[<span class="cpp-number">255</span>].peBlue = <span class="cpp-number">255</span>;palette[<span class="cpp-number">255</span>].peGreen = <span class="cpp-number">255</span>;palette[<span class="cpp-number">255</span>].peRed = <span class="cpp-number">255</span>;palette[<span class="cpp-number">0</span>].peFlags = PC_NOCOLLAPSE;<span class="cpp-keyword">if</span>(FAILED(lpdd-&amp;gt;CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 |DDPCAPS_INITIALIZE,palette,&amp;lpddpal,NULL))){<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);}<span class="cpp-keyword">if</span>(FAILED(lpddsprimary-&amp;gt;SetPalette(lpddpal))){<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);}<span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);}<span class="cpp-keyword">int</span> Game_Main(<span class="cpp-keyword">void</span> *parms = NULL, <span class="cpp-keyword">int</span> num_parms = <span class="cpp-number">0</span>){<span class="cpp-keyword">if</span>(KEYDOWN(VK_ESCAPE))SendMessage(main_window_handle,WM_CLOSE,<span class="cpp-number">0</span>,<span class="cpp-number">0</span>);memset(&amp;ddsd,<span class="cpp-number">0</span>,<span class="cpp-keyword">sizeof</span>(ddsd));ddsd.dwSize = <span class="cpp-keyword">sizeof</span>(ddsd);<span class="cpp-keyword">if</span>(FAILED(lpddsprimary-&amp;gt;Lock(NULL,&amp;ddsd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL))){<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);}<span class="cpp-keyword">int</span> mempitch = (<span class="cpp-keyword">int</span>)ddsd.lPitch; UCHAR *video_buffer = (UCHAR*)ddsd.lpSurface; <span class="cpp-keyword">for</span>(<span class="cpp-keyword">int</span> index = <span class="cpp-number">0</span>; index &amp;lt; <span class="cpp-number">1000</span>; index++){UCHAR color = rand()%<span class="cpp-number">256</span>;<span class="cpp-keyword">int</span> x = rand()%<span class="cpp-number">640</span>;<span class="cpp-keyword">int</span> y = rand()%<span class="cpp-number">480</span>;video_buffer[x+y*mempitch] = color;}<span class="cpp-keyword">if</span>(FAILED(lpddsprimary-&amp;gt;Unlock(NULL))){<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);}Sleep(<span class="cpp-number">30</span>);<span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);}<span class="cpp-keyword">int</span> Game_Shutdown(<span class="cpp-keyword">void</span> *parms = NULL, <span class="cpp-keyword">int</span> num_parms = <span class="cpp-number">0</span>){<span class="cpp-keyword">if</span>(lpddpal){lpddpal-&amp;gt;Release();lpddpal = NULL;}<span class="cpp-keyword">if</span>(lpddsprimary){lpddsprimary-&amp;gt;Release();lpddsprimary = NULL;}<span class="cpp-keyword">if</span>(lpdd){lpdd-&amp;gt;Release();lpdd = NULL;}<span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);}<span class="cpp-keyword">int</span> WINAPI WinMain( HINSTANCE hinstance,HINSTANCE hprevinstance,LPSTR lpcmdline,<span class="cpp-keyword">int</span> ncmdshow){WNDCLASSEX winclass;HWND hwnd;MSG msg;HDC hdc;winclass.cbSize = <span class="cpp-keyword">sizeof</span>(WNDCLASSEX);winclass.style = CS_DBLCLKS | CS_OWNDC |CS_HREDRAW | CS_VREDRAW;winclass.lpfnWndProc = WindowProc;winclass.cbClsExtra = <span class="cpp-number">0</span>;winclass.cbWndExtra = <span class="cpp-number">0</span>;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);hinstance_app = hinstance;<span class="cpp-keyword">if</span> (!RegisterClassEx(&amp;winclass))<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);<span class="cpp-keyword">if</span> (!(hwnd = CreateWindowEx(NULL,WINDOW_CLASS_NAME,<span class="cpp-literal">"DirectDraw Demo"</span>,WS_POPUP | WS_VISIBLE,<span class="cpp-number">0</span>,<span class="cpp-number">0</span>,SCREEN_WIDTH,SCREEN_HEIGHT,NULL,NULL,hinstance,NULL)))<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);main_window_handle = hwnd;Game_Init();<span class="cpp-keyword">while</span>(<span class="cpp-number">1</span>){<span class="cpp-keyword">if</span>(PeekMessage(&amp;msg,NULL,<span class="cpp-number">0</span>,<span class="cpp-number">0</span>,PM_REMOVE)){<span class="cpp-keyword">if</span>(msg.message = WM_QUIT)<span class="cpp-keyword">break</span>;TranslateMessage(&amp;msg);DispatchMessage(&amp;msg);}Game_Main();}Game_Shutdown();<span class="cpp-keyword">return</span>(msg.wParam);}</pre></div><!–ENDSCRIPT–><small><b>//EDIT: Added source tags to post. - Kaz</b></small><!–EDIT–><span class=editedby><!–/EDIT–>[Edited by - Kazgoroth on June 4, 2006 9:54:12 AM]<!–EDIT–></span><!–/EDIT–>
  Yeah there's no DirectDraw in 8, 9 and 10. The way a person does 2D, is boot up the directx engine and bit surfaces like DX7, and i'll take look at the code, but i'm crap worth nothing at debuging.   ;  Change your:if(msg.message = WM_QUIT)To:if(msg.message == WM_QUIT)   ;  To clarify further: There is no updated directdraw in DX8/9 and there will never be any new version. But DirectDraw7 will still be available.For pixel stuff DirectDraw is still the simplier approach, but as soon as you want to do more advanced stuff (scaling, rotating, alpha blending) you will change to Direct3d. Plan ahead.   ;  yeah, that'd do it alright.   ;  Also use [ source] and [ /source] around blocks that big please (no space after the ['s).  Thanks!So it's easier to read like this:#define WIN32_LEAN_AND_MEAN//includes#include <windows.h>#include <windowsx.h>#include <stdio.h>#include <math.h>#include <mmsystem.h>#include <stdlib.h>#include <draw.h>#include <malloc.h>#include <iostream.h>//defines#define WINDOW_CLASS_NAME "WINCLASS1"#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)#define SCREEN_WIDTH 640#define SCREEN_HEIGHT 480#define SCREEN_BPP 8 // bits per pixel#define MAX_COLORS 256//typedefstypedef unsigned short USHORT;typedef unsigned short WORD;typedef unsigned char UCHAR;typedef unsigned char BYTE;//globalsHWND main_window_handle = NULL;HINSTANCE hinstance_app = NULL;//directdrawLPDIRECTDRAW7 lpdd = NULL;LPDIRECTDRAWSURFACE7 lpddsprimary = NULL;LPDIRECTDRAWPALETTE lpddpal = NULL;DDSURFACEDESC2 ddsd;PALETTEENTRY palette[256];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_LBUTTONDBLCLK:{PostQuitMessage(0);return(0);}break;case WM_CLOSE:{int result = MessageBox(hwnd,"Do you really want to quit?","Quit",MB_YESNO|MB_ICONQUESTION);if(result == IDYES){return(DefWindowProc(hwnd,msg,wparam,lparam));}else return(0);}break;case WM_DESTROY:{PostQuitMessage(0);return(0);}break;default:break;}return(DefWindowProc(hwnd,msg,wparam,lparam));}int Game_Init(void *parms = NULL, int num_parms = 0){if(FAILED(DirectDrawCreateEx(NULL,(void**)&lpdd,IID_IDirectDraw7,NULL))){return(0);}if(FAILED(lpdd->SetCooperativeLevel(main_window_handle,DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))){return(0);}if(FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,0,0))){return(0);}memset(&ddsd,0,sizeof(ddsd));ddsd.dwSize = sizeof(ddsd);ddsd.dwSize = DDSD_CAPS;ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;if(FAILED(lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL))){return(0);}for(int color = 1; color < 255; color++){palette.peBlue = rand()%<span class="cpp-number">256</span>;<br>palette.peGreen = rand()%<span class="cpp-number">255</span>;<br>palette.peRed = rand()%<span class="cpp-number">255</span>;<br>palette.peFlags = PC_NOCOLLAPSE;<br>}<br><br>palette[<span class="cpp-number">0</span>].peRed = <span class="cpp-number">0</span>;<br>palette[<span class="cpp-number">0</span>].peBlue = <span class="cpp-number">0</span>;<br>palette[<span class="cpp-number">0</span>].peGreen = <span class="cpp-number">0</span>;<br>palette[<span class="cpp-number">0</span>].peFlags = PC_NOCOLLAPSE;<br><br>palette[<span class="cpp-number">255</span>].peBlue = <span class="cpp-number">255</span>;<br>palette[<span class="cpp-number">255</span>].peGreen = <span class="cpp-number">255</span>;<br>palette[<span class="cpp-number">255</span>].peRed = <span class="cpp-number">255</span>;<br>palette[<span class="cpp-number">0</span>].peFlags = PC_NOCOLLAPSE;<br><br><br><span class="cpp-keyword">if</span>(FAILED(lpdd-&gt;CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 |<br>DDPCAPS_INITIALIZE,<br>palette,&amp;lpddpal,NULL)))<br>{<br><span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);<br>}<br><br><span class="cpp-keyword">if</span>(FAILED(lpddsprimary-&gt;SetPalette(lpddpal)))<br>{<br><span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);<br>}<br><br><span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);<br>}<br><br><span class="cpp-keyword">int</span> Game_Main(<span class="cpp-keyword">void</span> *parms = NULL, <span class="cpp-keyword">int</span> num_parms = <span class="cpp-number">0</span>)<br>{<br><span class="cpp-keyword">if</span>(KEYDOWN(VK_ESCAPE))<br>SendMessage(main_window_handle,WM_CLOSE,<span class="cpp-number">0</span>,<span class="cpp-number">0</span>);<br><br>memset(&amp;ddsd,<span class="cpp-number">0</span>,<span class="cpp-keyword">sizeof</span>(ddsd));<br>ddsd.dwSize = <span class="cpp-keyword">sizeof</span>(ddsd);<br><br><span class="cpp-keyword">if</span>(FAILED(lpddsprimary-&gt;Lock(NULL,&amp;ddsd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL)))<br>{<br><span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);<br>}<br><br><span class="cpp-keyword">int</span> mempitch = (<span class="cpp-keyword">int</span>)ddsd.lPitch;<br>UCHAR *video_buffer = (UCHAR*)ddsd.lpSurface;<br><br><span class="cpp-keyword">for</span>(<span class="cpp-keyword">int</span> index = <span class="cpp-number">0</span>; index &lt; <span class="cpp-number">1000</span>; index++)<br>{<br>UCHAR color = rand()%<span class="cpp-number">256</span>;<br><span class="cpp-keyword">int</span> x = rand()%<span class="cpp-number">640</span>;<br><span class="cpp-keyword">int</span> y = rand()%<span class="cpp-number">480</span>;<br><br>video_buffer[x+y*mempitch] = color;<br>}<br><br><span class="cpp-keyword">if</span>(FAILED(lpddsprimary-&gt;Unlock(NULL)))<br>{<br><span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);<br>}<br><br>Sleep(<span class="cpp-number">30</span>);<br><br><span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);<br>}<br><br><span class="cpp-keyword">int</span> Game_Shutdown(<span class="cpp-keyword">void</span> *parms = NULL, <span class="cpp-keyword">int</span> num_parms = <span class="cpp-number">0</span>)<br>{<br><span class="cpp-keyword">if</span>(lpddpal)<br>{<br>lpddpal-&gt;Release();<br>lpddpal = NULL;<br>}<br><br><span class="cpp-keyword">if</span>(lpddsprimary)<br>{<br>lpddsprimary-&gt;Release();<br>lpddsprimary = NULL;<br>}<br><br><span class="cpp-keyword">if</span>(lpdd)<br>{<br>lpdd-&gt;Release();<br>lpdd = NULL;<br>}<br><br><span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);<br>}<br><br><span class="cpp-keyword">int</span> WINAPI WinMain( HINSTANCE hinstance,<br>HINSTANCE hprevinstance,<br>LPSTR lpcmdline,<br><span class="cpp-keyword">int</span> ncmdshow)<br>{<br>WNDCLASSEX winclass;<br>HWND hwnd;<br>MSG msg;<br>HDC hdc;<br><br>winclass.cbSize = <span class="cpp-keyword">sizeof</span>(WNDCLASSEX);<br>winclass.style = CS_DBLCLKS | CS_OWNDC |<br>CS_HREDRAW | CS_VREDRAW;<br>winclass.lpfnWndProc = WindowProc;<br>winclass.cbClsExtra = <span class="cpp-number">0</span>;<br>winclass.cbWndExtra = <span class="cpp-number">0</span>;<br>winclass.hInstance = hinstance;<br>winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);<br>winclass.hCursor = LoadCursor(NULL, IDC_ARROW);<br>winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);<br>winclass.lpszMenuName = NULL;<br>winclass.lpszClassName = WINDOW_CLASS_NAME;<br>winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);<br><br>hinstance_app = hinstance;<br><br><span class="cpp-keyword">if</span> (!RegisterClassEx(&amp;winclass))<br><span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);<br><br><span class="cpp-keyword">if</span> (!(hwnd = CreateWindowEx(NULL,<br>WINDOW_CLASS_NAME,<br><span class="cpp-literal">"DirectDraw Demo"</span>,<br>WS_POPUP | WS_VISIBLE,<br><span class="cpp-number">0</span>,<span class="cpp-number">0</span>,<br>SCREEN_WIDTH,SCREEN_HEIGHT,<br>NULL,<br>NULL,<br>hinstance,<br>NULL)))<br><span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);<br><br>main_window_handle = hwnd;<br><br>Game_Init();<br><br><span class="cpp-keyword">while</span>(<span class="cpp-number">1</span>)<br>{<br><span class="cpp-keyword">if</span>(PeekMessage(&amp;msg,NULL,<span class="cpp-number">0</span>,<span class="cpp-number">0</span>,PM_REMOVE))<br>{<br><span class="cpp-keyword">if</span>(msg.message = WM_QUIT)<br><span class="cpp-keyword">break</span>;<br><br>TranslateMessage(&amp;msg);<br><br>DispatchMessage(&amp;msg);<br>}<br><br>Game_Main();<br>}<br><br>Game_Shutdown();<br><br><span class="cpp-keyword">return</span>(msg.wParam);<br>}<br><br></pre></div><!–ENDSCRIPT–><br><br>It will keep your tab formatting too when you copy and paste it that way.;  Thank you. I will add the tag next time.I have corrected the '=' to '==', but it still doesn't work.   ;  I have the same problem using VC++ 2005 express and DirectX ver. 10.Im pretty sure that I have compiled and run this program successfully on earlier versions of MSVC and DirectX.Im starting to wonder if this problem has to do with the latest version of either VC++ or DX...   ;  @Pulpfist - You're using DirectX 10...? That's not released yet.   ;  Yea I guess your right. Im using the april_2006 build. Some of the headers is called xxx10 (d3d10.h) but some are still xxx9. Anyway, I think the same problem arises with version 9.   