- 最後登錄
- 2012-10-12
- 在線時間
- 221 小時
- 註冊時間
- 2007-10-18
- 閱讀權限
- 95
- 精華
- 3
- UID
- 2593154
- 帖子
- 802
- 積分
- 2980 點
- 潛水值
- 27720 米
| 若有安裝色情守門員,可用無界、自由門等軟件瀏覽伊莉。或使用以下網址瀏覽伊莉: http://www.eyny.com:81/index.php 本帖最後由 Force[TW] 於 2009-10-14 09:26 PM 編輯
這個程式是用 win32 寫的視窗程式碼。
說明:建立一個 win32 空的專案,在專案底下建一個空白的 cpp 檔案,直接複製下面程式碼,再編譯即可。- //This is a Win32 empty Project
- //Change to Windows Linker from Console Linker
- //Project->Properties->Linker->System->SubSystem->Windows
- //
- //Headers and Macros
- #include <Windows.h>
- #include <cstring>
- #define Wnd_Width 750
- #define Wnd_Height 250
- #define BUFFER_SIZE 1024
- static HWND hwndWnd = 0;
- static HINSTANCE hinstWnd = 0;
- class CHomework
- {
- public:
- void Table(HDC hdc)
- {
- int x = 0, y = 0;
- for ( int i = 0; i < 9; i ++)
- {
- wcscpy( this->wcStr, ((i + 1) < 10?L" ":L""));
- _itow( i + 1, this->buffer, 10);
- wcscat( this->wcStr, this->buffer);
- wcscat( this->wcStr, L" x ");
- int f = wcslen(this->wcStr);
- for ( int j = 0; j < 9; j ++)
- {
- wcscpy( (this->wcStr + f), ((j + 1) < 10?L" ":L""));
- _itow( j + 1, this->buffer, 10);
- wcscat( this->wcStr, this->buffer);
- wcscat( this->wcStr, L" = ");
- int f = wcslen(this->wcStr);
- int k = (i + 1) * (j + 1);
- wcscpy( (this->wcStr + f), (k < 10?L" ":L""));
- _itow( k, this->buffer, 10);
- wcscat( this->wcStr, this->buffer);
- ::TextOut( hdc, x, y, this->wcStr, wcslen(this->wcStr));
- y += 20;
- }
- x += 80;
- y = 0;
- }
- }
- protected:
- private:
- WCHAR buffer[BUFFER_SIZE];
- WCHAR wcStr[BUFFER_SIZE];
- };
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
- CHomework ch;
- switch (message)
- {
- case WM_PAINT:
- hdc = ::BeginPaint( hWnd, &ps);
- {
- ch.Table(hdc);
- }
- ::EndPaint( hWnd, &ps);
- break;
- case WM_KEYUP:
- switch ( wParam )
- {
- case VK_ESCAPE:
- ::DestroyWindow(hWnd);
- break;
- default:
- break;
- }
- break;
- case WM_DESTROY:
- ::PostQuitMessage(0);
- break;
- default:
- return ::DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- BOOL ProcMsg()
- {
- MSG msg;
- BOOL bPM = ::PeekMessage( &msg, NULL, NULL, NULL, PM_REMOVE);
- if ( bPM == TRUE )
- {
- ::TranslateMessage(&msg), ::DispatchMessage(&msg);
- switch ( msg.message )
- {
- case WM_QUIT:
- return FALSE;
- default:
- break;
- }
- }
- return TRUE;
- }
- BOOL BuildWnd(LPCTSTR wcTitle = L"Default")
- {
- int nX, nY, nWidth, nHeight;
- HINSTANCE hInstance = ::GetModuleHandle(NULL);
- DWORD dwWindowStyle = WS_OVERLAPPEDWINDOW;
- 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 = ::LoadIcon( hInstance, IDI_WINLOGO);
- wcex.hIconSm = wcex.hIcon;
- wcex.hCursor = ::LoadCursor( hInstance, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = NULL, wcex.lpszClassName = wcTitle;
- if ( ::RegisterClassEx(&wcex) == 0 )
- {
- return FALSE;
- }
- {
- RECT r;
- HWND hwndDesktopWnd = ::GetDesktopWindow();
- BOOL bGWR = ::GetWindowRect( hwndDesktopWnd, &r);
- if ( bGWR == TRUE )
- {
- nWidth = Wnd_Width, nHeight = Wnd_Height;
- nX = (r.right - r.left - nWidth) / 2;
- nY = (r.bottom - r.top - nHeight) / 2;
- }
- else
- {
- nX = CW_USEDEFAULT, nY = 0;
- nWidth = CW_USEDEFAULT, nHeight = 0;
- }
- }
- HWND hWnd = ::CreateWindow( wcTitle, wcTitle, dwWindowStyle,
- nX, nY, nWidth, nHeight, NULL, NULL, hInstance, NULL);
- if ( hWnd == NULL )
- {
- return FALSE;
- }
- hwndWnd = hWnd, hinstWnd = hInstance;
- ::ShowWindow( hWnd, SW_SHOWNORMAL), ::SetActiveWindow(hWnd);
- return TRUE;
- }
- //Window Entry
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nShowCmd)
- {
- //==START of WinMain==//
- BuildWnd();
- while ( ProcMsg() == TRUE );
- //==END of WinMain==//
- return 0;
- }
複製代碼 ... |
|