程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> win32-關於windows7中WIN32編程下的問題

win32-關於windows7中WIN32編程下的問題

編輯:編程綜合問答
關於windows7中WIN32編程下的問題

在win7中建了一個很簡單的win32工程項目,代碼如下,為啥RegisterClass(&wndclass)會失敗呢?
#include
#pragma comment(lib, "winmm")

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, PSTR szcmdline, int icmdshow)
{
static TCHAR szAppName[] = TEXT("HelloWin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;

wndclass.style = CS_HREDRAW | CS_VREDRAW;

wndclass.lpfnWndProc = WndProc;

wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hinstance;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;

if (!RegisterClass(&wndclass))
{
    MessageBox(NULL, TEXT("this program requried windows NT!"), szAppName, MB_ICONERROR);
    return 0;
}

hwnd = CreateWindow(szAppName,
    TEXT("The Hello Program"),
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    NULL,
    NULL,
    hinstance,
    NULL);
ShowWindow(hwnd, icmdshow);
UpdateWindow(hwnd);


while (GetMessage (&msg, NULL, 0, 0))

{

TranslateMessage (&msg) ;

DispatchMessage (&msg) ;

}

return msg.wParam ;

}


LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

    HDC                 hdc ;

    PAINTSTRUCT         ps ;

    RECT                rect ;



        switch (message)

        {

        case WM_CREATE:

        PlaySound(TEXT ("sweet.mp3"), NULL, SND_FILENAME | SND_ASYNC) ;

        return 0 ;


        case   WM_PAINT:

        hdc = BeginPaint (hwnd, &ps) ;



        GetClientRect (hwnd, &rect) ;



        DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,

        DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;

        EndPaint (hwnd, &ps) ;

        return 0 ;



        case   WM_DESTROY:

        PostQuitMessage (0) ;

        return 0 ;

        }

return DefWindowProc (hwnd, message, wParam, lParam) ;

}

最佳回答:


RegisterClass失敗後,用GetLastError查看一下錯誤信息。是不是你類名等不正確

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved