小屋創作

日誌2010-05-09 01:52

用Dev-C++寫簡單Windows介面

作者:永無止盡的昨天

Dev-C++雖然是免費的C/C++編譯器
但是Dev-C++也幫我們建立好Win32 API的相關連結
可以讓我們快速的製作出視窗介面
 
首先第一個步驟式開啟專案

接下來點選Windows Application

最後儲存編譯就可以執行底下的視窗程式
 
這些步驟雖然簡單
但是這其實是Dev-C++的作者幫我們些好的範本
如果不了解範本裡面的程式是很難繼續下一步的
 
不過本人對於範本的程式碼也還沒到完全了解的地步
因此只能做部分的解說
 
#include <windows.h>         //將windows的函式庫給呼叫近來

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);//宣告windows的程序

char szClassName[ ] = "WindowsApp";  //建立類別名稱
 
/*windows 主程式開始*/
int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* 宣告視窗類別的資料結構*/
 
    /* 視窗類別的設定 */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);
    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* 功能表的設定,目前是沒有的*/
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */  
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; //視窗的背景設定
 
    /* 註冊視窗類別,如果失敗就會跳出*/
    if (!RegisterClassEx (&wincl))
        return 0;
 
    /* 如果註冊成功,就能建立這個視窗程式*/
   /* CreateWindowEx為設定視窗的各種樣式*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* 類別名稱 */
           "Windows App",       /* 標題名稱*/
           WS_OVERLAPPEDWINDOW, /* 視窗的風格設定 */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* 寬度 */
           375,                 /* 高度 */
           HWND_DESKTOP,        /* 這個視窗程式是桌面的子視窗*/
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );
 
    /* 將此視窗秀到螢幕上 */
    ShowWindow (hwnd, nFunsterStil);
    /* 持續執行訊息回圈. 直到GetMessage傳回0時 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }
    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}

12

13

LINE 分享

相關創作

【不定時日誌】關於《鋼彈SEED FREEDOM》4DX限定特典小說場次未到先發完的後續

自介

【地球】

留言

開啟 APP

face基於日前微軟官方表示 Internet Explorer 不再支援新的網路標準,可能無法使用新的應用程式來呈現網站內容,在瀏覽器支援度及網站安全性的雙重考量下,為了讓巴友們有更好的使用體驗,巴哈姆特即將於 2019年9月2日 停止支援 Internet Explorer 瀏覽器的頁面呈現和功能。
屆時建議您使用下述瀏覽器來瀏覽巴哈姆特:
。Google Chrome(推薦)
。Mozilla Firefox
。Microsoft Edge(Windows10以上的作業系統版本才可使用)

face我們了解您不想看到廣告的心情⋯ 若您願意支持巴哈姆特永續經營,請將 gamer.com.tw 加入廣告阻擋工具的白名單中,謝謝 !【教學】