2016-03-24 21 views
-1

Tamam, bu programda, bir yürütülebilir dosyayı derlemek için Code :: Blocks IDE ve GNU GCC derleyicisini kullanıyorum. Bir Win32 GUI projesidir. Benim sorunum, her ne kadar hepsi çalışıyor olsa da, son zamanlarda onları çalışmak için & onları kodlamak için düğmeleri tıklayarak uygulamak için çalıştı. Adam kodu/Düğme tıklandığında tespit ediliyor mu? [C++, WinAPI]

Error: ||=== Build file: Release in Agsploit (compiler: GNU GCC Compiler) ===| C:\Users\PC\Desktop\Agsploit\main.cpp||In function 'int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)':| C:\Users\PC\Desktop\Agsploit\main.cpp|14|error: expected unqualified-id before numeric constant| C:\Users\PC\Desktop\Agsploit\main.cpp|55|note: in expansion of macro 'Execute'| ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

Kod (Maalesef emin değilim burada biçimlendirmek nasıl, bu yüzden pastebin'd) çalışması gerektiğini söyledi Ancak, ben, garip bir hatayı alıyorum: http://pastebin.com/raw/r6b5NcXK

#if defined(UNICODE) && !defined(_UNICODE) 
    #define _UNICODE 
#elif defined(_UNICODE) && !defined(UNICODE) 
    #define UNICODE 
#endif 

#include <tchar.h> 
#include <windows.h> 

LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM); 

TCHAR szClassName[] = _T("WindowClass"); 

#define Execute 0 
#define RunScript 1 
#define Clear 2 
#define Help 3 
#define Credits 4 
#define Commands 5 
#define Exit 6 

int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { 
    HWND hwnd; 
    MSG messages; 
    WNDCLASSEX wincl; 
    wincl.hInstance = hThisInstance; 
    wincl.lpszClassName = szClassName; 
    wincl.lpfnWndProc = WindowProcedure; 
    wincl.style = CS_DBLCLKS; 
    wincl.cbSize = sizeof (WNDCLASSEX); 
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); 
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); 
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW); 
    wincl.lpszMenuName = NULL; 
    wincl.cbClsExtra = 0; 
    wincl.cbWndExtra = 0; 
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; 
    if (!RegisterClassEx (&wincl)) { 
     return 0; 
    }; 
    hwnd = CreateWindowEx(
      0, 
      szClassName, 
      _T("LightNinG || v1 || By: [Team AzuL]"), 
      WS_OVERLAPPEDWINDOW^WS_THICKFRAME, 
      400, 
      200, 
      740, 
      390, 
      HWND_DESKTOP, 
      NULL, 
      hThisInstance, 
      NULL 
    ); 
    HWND Execute = CreateWindow(
     "BUTTON", 
     "Execute", 
     WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 
     250, 
     315, 
     235, 
     50, 
     hwnd, 
     (HMENU)Execute, 
     (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 
     NULL 
    ); 
    HWND ScriptButton = CreateWindow(
     "BUTTON", 
     "Run script", 
     WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 
     485, 
     315, 
     250, 
     50, 
     hwnd, 
     (HMENU)RunScript, 
     (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 
     NULL 
    ); 
    HWND Clear = CreateWindow(
     "BUTTON", 
     "Clear", 
     WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 
     0, 
     315, 
     250, 
     50, 
     hwnd, 
     (HMENU)Clear, 
     (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 
     NULL 
    ); 
    HWND Help = CreateWindow(
     "BUTTON", 
     "Help", 
     WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 
     400, 
     0, 
     85, 
     84, 
     hwnd, 
     (HMENU)Help, 
     (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 
     NULL 
    ); 
    HWND Credits = CreateWindow(
     "BUTTON", 
     "Credits", 
     WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 
     400, 
     84, 
     85, 
     84, 
     hwnd, 
     (HMENU)Credits, 
     (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 
     NULL 
    ); 
    HWND Commands = CreateWindow(
     "BUTTON", 
     "Commands", 
     WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 
     400, 
     168, 
     85, 
     84, 
     hwnd, 
     (HMENU)Commands, 
     (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 
     NULL 
    ); 
    HWND Exit = CreateWindow(
     "BUTTON", 
     "Exit", 
     WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 
     400, 
     252, 
     85, 
     64, 
     hwnd, 
     (HMENU)Exit, 
     (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 
     NULL 
    ); 
    HWND OutputWindow = CreateWindow("Edit", "Hello, and welcome to LightNinG by Team AzuL.\r\nCurrent version: 1\r\nCurrent # of commands: 0", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_MULTILINE | ES_READONLY, 0, 0, 400, 290, hwnd, NULL, NULL, NULL); 
    HWND InputBar = CreateWindow("Edit", "Input commands here.", WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 290, 400, 25, hwnd, NULL, NULL, NULL); 
    HWND ScriptBox = CreateWindow("Edit", "Script(s) go here {client-sided}.", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_MULTILINE, 485, 0, 250, 314, hwnd, NULL, NULL, NULL); 
    ShowWindow (hwnd, nCmdShow); 
    while (GetMessage(&messages, NULL, 0, 0)) { 
     TranslateMessage(&messages); 
     DispatchMessage(&messages); 
    }; 
    return messages.wParam; 
}; 

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { 
    switch (message) { 
     case WM_COMMAND: 
      switch(LOWORD(wParam)) { 
       case Execute: 

       break; 
       case RunScript: 

       break; 
       case Clear: 

       break; 
       case Help: 

       break; 
       case Credits: 
        MessageBox(NULL, (LPCWSTR)L"Created by team AzuL.", (LPCWSTR)L"Credits", MB_OK); 
       break; 
       case Commands: 

       break; 
       case Exit: 

       break; 
      } 
     break; 
     case WM_DESTROY: 
      PostQuitMessage(0); 
      break; 
     default: 
      return DefWindowProc(hwnd, message, wParam, lParam); 
    }; 
    return 0; 
}; 
+0

Teşekkürler mah, bana bunu nasıl yaptığını söyleyebilir misin? –

+0

Kodu yapıştırdım, hepsini seçtim ve K tuşuna basıyorum. Bu, her satırın başına sadece 4 alan ekleyen bir kısayoldur. – mah

+0

Ah teşekkürler, biçimlendirmememin sebebi, bir seferde nasıl yapılacağının farkında olmamamdı. Bir süreliğine olurdu. –

cevap

2

Hat 14 (aynı zamanda hata iletisinde işaret) olan (hata mesajında ​​belirttiği)

#define Execute 0 

Hat 55'tir:

geçerli C olmadığı ...

HWND 0 = CreateWindow(

: genişletilmiş alır

HWND Execute = CreateWindow(

. Mümkün olduğunca az

  1. Kullanım önişlemci:

    uzmanlar şiddetle tavsiye bir sebep yoktur.

  2. Kullanmanız gerekiyorsa, makrolar için ALL_UPPER_CASE kullanın (ve başka hiçbir şey için).

tercih çözüm gibi bir şey olacaktır:

enum class Command : int 
{ 
    Execute = 1, // I'd always reserve 0 for "no such command". 
    RunScript, 
    Clear, 
    Help, 
    Credits, 
    Commands, 
    Exit, 
}; 

ve sonra (HMENU)Command::Execute ile düğme oluşturabilirsiniz.

+0

Hmm .. bu yüzden onları farklı bir şekilde tanımlamanız gerektiği anlamına mı geliyor? Execute yerine DEFINED_EXE gibi? –

+0

Tüm büyük harfleri kullanmanız bile sizi sıkıntıya sokabilir. İçinde #define FILE 1 olan hata ayıklama kodunun talihsizliğini yaşadım. Sorun şu ki, 'FILE'' ''de kullanılır. – PaulMcKenzie

+0

Benim çözüm Z_VARIABLE koymaktır çünkü Z_ pencereler tarafından kullanılmamalıdır (eğer ew ise). –

İlgili konular