2011-12-16 24 views
0

私は単純なWin32 APIプログラムをコンパイルしていますが、コンパイルは問題ありませんが、ウィンドウは表示されません。私はtaskmanagerのプロセスをチェックし、プログラムはそこにありますが、ウィンドウは表示されません。私はCodeBlocks IDE 10.05をGNU GCCコンパイラと共にWindows 7 32ビット版で使用しています。 私はそこに同様の質問がstackoverflowであることを知っているが、そこに与えられた解決策は '=='の代わりに '='でした。ここでのコードは次のとおりです。Win32プログラムはコンパイルされますが、ウィンドウは表示されません。

#include <windows.h> 
#include <tchar.h> 

/* Global Vars */ 
HINSTANCE hInst; 
HWND wndHandle; 
int winWidth = 640; 
int winHeight = 480; 

//func prototypes 
bool InitWindow(HINSTANCE hInst, int width, int height); 
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 
/******************************************************** 
* WINMAIN FUNCTION 
*********************************************************/ 
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) 
{ 
hInst = hInstance; 

//app window 

if (!InitWindow(hInst, winWidth, winHeight)) 
{ 
    return false; 
} 

// MESSAGE LOOP 
MSG msg = {0}; 
while (WM_QUIT != msg.message) 
{ 
    //window messages 
    while(PeekMessage(&msg, NULL,0,0, PM_REMOVE) == TRUE) 
    { 
     TranslateMessage(&msg); 
     DispatchMessage(&msg); 
    } 
    //additional logic 
} 
return (int)msg.wParam; 
} 

/******************************************************************* 
* InitWindow 
* Inits and creates and main app window 
* Inputs - application instance - HINSTANCE 
      Window width - int 
      Window height - int 
* Outputs - true if successful, false if failed - bool 
*******************************************************************/ 
bool InitWindow(HINSTANCE hInstance, int width, int height) 
{ 
// Register class 
WNDCLASSEX wcex; 
wcex.cbSize = sizeof(WNDCLASSEX); 
wcex.style   = CS_HREDRAW | CS_VREDRAW; 
wcex.lpfnWndProc = WndProc; 
wcex.cbClsExtra  = 0; 
wcex.cbWndExtra  = 0; 
wcex.hInstance  = hInstance; 
wcex.hIcon   = 0; 
wcex.hCursor  = LoadCursor(NULL, IDC_ARROW); 
wcex.hbrBackground = (HBRUSH) + (COLOR_WINDOW+1); 
wcex.lpszMenuName = NULL; 
wcex.lpszClassName = TEXT("DirectX 10 Example"); 
wcex.hIconSm  = 0; 

if(!RegisterClassEx(&wcex)) 
{ 
    return false; 
} 

// resize window 
RECT rect = { 0, 0, width, height }; 
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false); 

// create the window from the class above 
wndHandle = CreateWindow( TEXT("DX 10 Example"), 
          TEXT("DX10 WINDOW"), 
          WS_OVERLAPPEDWINDOW, 
          CW_USEDEFAULT, 
          CW_USEDEFAULT, 
          rect.right - rect.left, 
          rect.bottom - rect.top, 
          0, 
          0, 
          hInstance, 
          0); 
if(wndHandle == 0) 
{ 
    return false; 
} 
ShowWindow(wndHandle, SW_SHOW); 
UpdateWindow(wndHandle); 
return true; 
} 
/******************************************************************* 
* WndProc 
* The main window procedure for the application 
* Inputs - application window handle - HWND 
      message sent to the window - UINT 
      wParam of the message being sent - WPARAM 
      lParam of the message being sent - LPARAM 
* Outputs - LRESULT 
*******************************************************************/ 
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 
{ 
    switch (message) 
{ 
    // Allow the user to press the escape key to end the application 
    case WM_KEYDOWN: 
     switch(wParam) 
     { 
      // Check if the user hit the escape key 
      case VK_ESCAPE: 
       PostQuitMessage(0); 
      break; 
     } 
    break; 

     // The user hit the close button, close the application 
    case WM_DESTROY: 
      PostQuitMessage(0); 
    break; 
    } 

    return DefWindowProc(hWnd, message, wParam, lParam); 
} 
+0

使用のassert()を –

+0

私はMSVC Fを使用することをお勧めします。またはWindowsの開発 - それは間違いなく最高のWindowsコンパイラです(とエクスプレス版は無料ですが、また非常に良い) – RageD

答えて

3

あなたは wcex.lpszClassName = TEXT( "DirectX 10の例")を有します。

wndHandle =のcreateWindow(TEXT( "DX 10例")、 TEXT( "DX10 WINDOW")、あなたが使用されるようにあなたが "のcreateWindow" に同じクラス名を使用する必要が

+0

多くのありがとう、問題解決、ひどい間違い:(しかし、なぜコンパイラはこれについて不平を言っていない?それはないはずですか? –

+3

@Polizel:コンパイラは、あなたが誤植をしたことを推測することはできません。そのため、繰り返される必要がある値に対して常に定数(リテラルではない)を使用する必要があります。 – Jon

3

。 "RegisterClass" のためのソースコードで

これら二つは異なる:ミスをキャッチする

wcex.lpszClassName = TEXT("DirectX 10 Example"); 
... 
wndHandle = CreateWindow(TEXT("DX 10 Example"), ... 
関連する問題