ENIX007
高階會員
發表:28 回覆:274 積分:185 註冊:2003-11-27
發送簡訊給我
|
stone886您好
應該每一本WINDOWS專書都會以這個當第一個範例吧
class="code"> #include #define HELLOSTR "Hello Windows" char gszWndClass[] = "HELLOWINDOWS";
char gszAppName[] = "HELLOWINDOWS.cpp"; LONG FAR WINAPI WndProc(HWND hWnd, UINT mMsg, WPARAM wParam, LPARAM lParam)
{
switch (mMsg) {
case WM_ACTIVATEAPP:
break;
case WM_CREATE:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
switch (wParam) {
case VK_ESCAPE:
PostMessage(hWnd, WM_CLOSE, 0, 0);
return 0L;
}
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT Ps; hDC = BeginPaint(hWnd, &Ps);
TextOut(hDC, 0, 0, HELLOSTR, strlen(HELLOSTR));
EndPaint(hWnd, &Ps);
break;
default :
return(DefWindowProc(hWnd, mMsg, wParam, lParam));
}
return 0L;
} int WINAPI WinMain(HINSTANCE ghInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdline, int nCmdShow)
{
WNDCLASS wndclass;
HWND hWnd;
MSG msg; // 1. 設定視窗類別
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = ::GetModuleHandle(NULL);
wndclass.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = gszWndClass; // 2. 登錄視窗類別
if (!RegisterClass(&wndclass))
return FALSE; // 3. 建立視窗
hWnd = CreateWindow(gszWndClass,
gszAppName,
WS_OVERLAPPEDWINDOW,
100,
100,
640,
480,
NULL,
NULL,
::GetModuleHandle(NULL),
NULL
); // 4. 顯示視窗
ShowWindow(hWnd, nCmdShow);
// 5. 更新視窗
UpdateWindow(hWnd); // 6. 訊息處理迴圈
while (GetMessage(&msg, 0, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
} return 0;
}
其中的幾個API請自行研究囉 程式迷人之處,在於邏輯思考,然而卻也是惱人之處~~
------ 程式迷人之處,在於邏輯思考,然而卻也是惱人之處~~
|
ENIX007
高階會員
發表:28 回覆:274 積分:185 註冊:2003-11-27
發送簡訊給我
|
stone886您好
說真的WINDOWS的專書不多耶...(都是原文書)
像小弟我手邊只有一本WINDOWS2000程式設計-徹底研究,作者:Herbert Schildt
,譯者:林偉豪,麥格羅希爾(McGraw-Hill)出版,不過要先說明,我其實很少用這本書,
把它當工具書來查倒是不錯...
它對於建立視窗的步驟講解得蠻詳細的,不過每個範例都重複講一次就是了 程式迷人之處,在於邏輯思考,然而卻也是惱人之處~~
------ 程式迷人之處,在於邏輯思考,然而卻也是惱人之處~~
|