大家好,這是本人寫的第一篇博客,如果沒能讓你有所收獲還望見諒,有何錯誤還望批評,下面回到正題
1.作為win32初學者如何讓自己寫的程序,能在無編譯器的電腦運行?
想必大家肯定經歷過將程序放到別人電腦上,會出現.dll庫文件缺失的情況,那么該如何解決呢?
首先確保你的程序版本是Release版本,然后你需要將項目屬性改成如下情況
代碼生成中的運行庫選擇多線程(/MT)
下面貼代碼
#include<windows.h>#include<math.h>#include"resource.h"#define Radius 30*sqrt(2)/2LRESULT CALLBACK WinPRoc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hInprestance, PSTR pCmdLine, int iCmdLine){ WNDCLASS wndcls; wndcls.cbWndExtra = 0; wndcls.cbClsExtra = 0; wndcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndcls.hInstance = hInstance; wndcls.hCursor = LoadCursor(NULL, IDC_ARROW); wndcls.hIcon = LoadIcon(hInstance, (LPSTR)IDI_ICON1); wndcls.lpfnWndProc = WinProc; wndcls.lpszClassName = TEXT("WinForm"); wndcls.lpszMenuName = NULL; wndcls.style = CS_VREDRAW | CS_HREDRAW; RegisterClass(&wndcls); HWND hwnd; hwnd = CreateWindow("WinForm", "Marco", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdLine); UpdateWindow(hwnd); MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0;}void DrawHeart(HDC hdc,int i,int cxClient,int cyClient){ //使改變窗口心自動調整改變 SetMapMode(hdc, MM_ISOTROPIC); SetWindowExtEx(hdc, 120, 90, NULL); SetViewportExtEx(hdc, cxClient, cyClient, NULL); SetWindowOrgEx(hdc, 80, 75, NULL); SetViewportOrgEx(hdc, cxClient / 2, cyClient / 2, NULL); POINT pt[4] = { 50,80,80,50,110,80,80,110 }; HPEN hpen[4]; HBRUSH hbrush[4]; COLORREF color[4] = { RGB(255,0,255),RGB(0,0,255),RGB(255,0,0),RGB(0,0,0) }; for (int j = 0; j < 4; j++) { hpen[j] = CreatePen(PS_SOLID, 0, color[j]); hbrush[j] = CreateSolidBrush(color[j]); } SelectObject(hdc, hpen[i]); SelectObject(hdc, hbrush[i]); Polygon(hdc, pt, 4); Ellipse(hdc, 65 - Radius, 65 - Radius, 65 + Radius, 65 + Radius); Ellipse(hdc, 95 - Radius, 65 - Radius, 95 + Radius, 65 + Radius); DeleteObject(hpen[i]); DeleteObject(hbrush[i]);}LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ HDC hdc; PAINTSTRUCT ps; COLORREF color[4] = { RGB(255,0,255),RGB(0,0,255),RGB(255,0,0),RGB(255,255,255) }; static HWND hwndstatic; static int cxClient, cyClient; static int i; int j; static HBRUSH hbrushstatic; static int music[3] = { 102,103,104 }; static TCHAR * speak[4] = { "自從遇見你,我們就保持曖昧的關系,雖然痛苦但是很甜蜜", "當我們互相坦露后,就像一陣幸福的風吹來,你我承諾會到永遠", "可現實中我們仍然需要自己的空間,就像這紅色的心看似相愛卻早已心生抱怨", "漸漸我們的心散去,我們選擇成全彼此,其實歲月留給我們的只是空白" }; switch (message) { case WM_CREATE : SetTimer(hwnd, 1, 1000 * 60 *4.5, NULL); PlaySound((LPSTR)IDR_WAVE1, NULL, SND_RESOURCE | SND_ASYNC); hwndstatic = CreateWindow("static", NULL, WS_CHILD |WS_VISIBLE, 0, 10, 600, 40, hwnd,(HMENU)1, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); hbrushstatic = CreateSolidBrush(RGB(255,255, 255)); return 0; case WM_TIMER: i++; if (i < 4 && i >= 1) PlaySound((LPSTR)music[i - 1], NULL, SND_ASYNC | SND_RESOURCE); InvalidateRect(hwnd, NULL, TRUE); return 0; case WM_SIZE : cxClient = LOWord(lParam); cyClient = HIWORD(lParam); return 0; case WM_PAINT : hdc = BeginPaint(hwnd, &ps); if (i < 4) { DrawHeart(hdc, i, cxClient, cyClient); SetWindowText(hwndstatic, speak[i]); } EndPaint(hwnd, &ps); return 0; case WM_CTLCOLORSTATIC : j = GetWindowLong((HWND)lParam, GWL_ID); if (j == 1) { SetTextColor((HDC)wParam, color[i]); SetBkColor((HDC)wParam, RGB(255, 255, 255)); return (LRESULT)hbrushstatic; } break; case WM_DESTROY : PostQuitMessage(0); return 0; default : return DefWindowProc(hwnd, message, wParam, lParam); } return 0;}
新聞熱點
疑難解答