1 / 14

Windowsprogrammering

Windowsprogrammering. DOS Console Application. ”Console.lib”. 2. Skapar fönstret. Skriver ut. main(..) { }. Asd das asdlk Lasdkasld dldld Dlaieieiei ddd 01029 939333 300-0. cin. main(..) { }. 3. main(..) { }. main(..) { }. cout. 4. WinMain inuti ”console.lib” anropas

bazyli
Download Presentation

Windowsprogrammering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Windowsprogrammering CD5250 Daniel Flemström MDH/IDT

  2. DOS Console Application ”Console.lib” 2 Skapar fönstret Skriver ut main(..){} Asd das asdlk Lasdkasld dldld Dlaieieiei ddd 01029 939333 300-0 cin main(..){} 3 main(..){} main(..){ } cout 4 • WinMain inuti ”console.lib” anropas • Fönstret Skapas • Din Main anropas • Cout skrivs ut till fönstret. • Tangentinmatningar kommer till cin myMain.cpp 5 Myprog.exe CD5250 Daniel Flemström MDH/IDT

  3. Windows Application WNDCLASS windowStyleWndProchInstanceiconbackground... WinMain{ Register Class CreateWindow MessageLoop }WndProc(){ Switch.. } message dispatch ”Windows” myWinApp.EXE CD5250 Daniel Flemström MDH/IDT

  4. WinMain int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {WNDCLASSEX wcex; wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.hIcon = LoadIcon(hInstance,(LPCTSTR)IDI_KILLERAPP); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); ... RegisterClassEx(&wcex); CreateWindow(....) while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } CD5250 Daniel Flemström MDH/IDT

  5. WndProc LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){switch (message) {case WM_TIMER: game.OnTimer( wParam, lParam); break;case WM_CHAR: game.OnChar( wParam, lParam); break; . . . case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); }return 0;} CD5250 Daniel Flemström MDH/IDT

  6. Windows Messages WM_CHAR, WM_GETTEXT och så vidare. • lparam och wparam betyder olika sakerberoende på vilket meddelande. • Kommer från operativsystemet(tangent och mus)eller från program(set / get window text). • Du bestämmer vilka meddelanden ditt fönster ”förstår” och kan hitta på egna. CD5250 Daniel Flemström MDH/IDT

  7. WM_CHAR CD5250 Daniel Flemström MDH/IDT

  8. Bra Meddelanden att hantera • WM_CREATE När fönstret skapas. • WM_PAINTNär fönstret behöver ritas om (tex om någon ändrat storlek) • WM_RESIZEOm någon ändrar storlek. CD5250 Daniel Flemström MDH/IDT

  9. Rita (annat än i WM_PAINT) DC = Device Context HDC hDc = GetDC(hWnd) ... // Rita som sjutton... ReleaseDc(hWnd, hDc); GDI CD5250 Daniel Flemström MDH/IDT

  10. Rita Ett Streck MoveTo(hDc, 0,0,NULL) LineTo(hDc,10,20); CD5250 Daniel Flemström MDH/IDT

  11. Flera Bra Ritgrejjor • Ellipse(hdc, . . .); • RoundRect(hdc, . . .); • Rectangle(hdc, . . .); • DrawText(hdc, . . .); CD5250 Daniel Flemström MDH/IDT

  12. Ändra Färg Högerklicka ”Goto definition of” För att se flera alternativ! Befintliga Färger och Penslar: hOldPen = SelectObject(hDc,GetStockObject(WHITE_PEN)); hOldBrush = SelectObject(hDc,GetStockObject(WHITE_BRUSH)); Göra Egna Färger och Penslar: HPEN hPen = CreatePen(PS_SOLID,RGB(255,0,0)); SelectObject(hDc,hPen); HBRUSH hBrush = CreateSolidBrush(RGB(10,20,39)); SelectObject(hD,hBrush); OBS! Avsluta alltid med att välja stock pen och brush + delete av egna! SelectObject(hOldPen); DeleteObject(hPen); // Endast på egengjorda! CD5250 Daniel Flemström MDH/IDT

  13. Alltogether Now! HDC hDc = GetDC(hWnd) HPEN pYellowPen = CreatePen(PS_SOLID, RGB(0,255,255)); HPEN hOldPen = SelectObject(pYellowPen); SelectObject(GetStockObject(GRAY_BRUSH)); Rectangle(hDc,10,10,20,20); SelectObject(pOldPen); DeleteObject(pYellowPen); ReleaseDc(hWnd, dc); CD5250 Daniel Flemström MDH/IDT

  14. MER? • Enormt mycket mer finns att lära!!! • Alla fönster fungerar så här (Även activeXer internt) • Charles Petzold”Programming Windows, The Definitive Guide to the Win32 API”Microsoft Press; ISBN: 157 231 995 X; 5th Bk&Cd Rom edition (December 1998) • MFC Gömmer detta CD5250 Daniel Flemström MDH/IDT

More Related