C编程对话框

时间:2017-07-24 11:59:51

标签: c windows winapi

当我运行我的代码时,我转到菜单点击uyu->开始,它表示当需要显示对话框时对话框失败。我已尝试perrorGetLastError()查看错误,但我无法做到。是关于rc文件还是主要代码,我说不出来..

我的资源档案

#include "mainnnnnnn.h"

IDD_IMUSTARDSOFT_DIALOG DIALOGEX 0, 0, 358, 199
STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION |
    WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "IMUSTARDSOFT"
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "Hide",ID_BUTTON_OK,238,178,50,14,BS_FLAT
    PUSHBUTTON      "Exit",ID_BUTTON_EXIT,301,178,50,14,BS_FLAT
END

我的标题

#define utur 7444
#define ErrorDialog 49997
#define IDD_WOW 8888
#define IDD_START 9999
#define IDD_OKK 7777
#define IDD_SAVE_FILE 5655
#define IDD_NEW 4333
#define IDD_IMUSTARDSOFT_DIALOG 2333
#define IDOK 1555
#define IDCANCEL 2222

我的主要代码

#include<windows.h>
#define THEICON "windowIco.ico"
#include "mainnnnnnn.h"

char *errorMsg;

INT_PTR WINAPI ABDialogProc(HWND newWindow, UINT msg, WPARAM wparam, LPARAM lparam){
    switch(msg){
        case WM_INITDIALOG:
        break;
        case WM_COMMAND:

        break;
    }
    return FALSE;
}

LRESULT CALLBACK newStartCallback(HWND newWindow, UINT msg, WPARAM wparam, LPARAM lparam){

    HMENU hmenu, hsubmenu;

    switch(msg){
        case WM_CREATE:
            hmenu= CreateMenu();
            hsubmenu = CreatePopupMenu();
            AppendMenu(hsubmenu, MF_STRING|MF_POPUP, IDD_NEW , "&New");
            AppendMenu(hsubmenu, MF_STRING|MF_POPUP, IDD_SAVE_FILE, "&Save File");
            AppendMenu(hmenu, MF_STRING|MF_POPUP,  (UINT_PTR)hsubmenu, "&File");
            hsubmenu = CreatePopupMenu();
            AppendMenu(hsubmenu, MF_STRING|MF_POPUP, IDD_START, "&Start");
            AppendMenu(hsubmenu, MF_STRING|MF_POPUP, IDD_WOW, "&wow");  //IDD_WOW
            AppendMenu(hsubmenu, MF_STRING|MF_POPUP, IDD_OKK, "&Okk");
            AppendMenu(hmenu, MF_STRING|MF_POPUP, (UINT_PTR)hsubmenu, "&uyu");
            SetMenu(newWindow, hmenu); //Forgot to add Set Menu function here


            break;
        case WM_COMMAND:
            switch(LOWORD(wparam)){  //gets low order of wparam.... LOWORD FUNCTION ONE PARAMETER INSIDE GETS ITS LOW ORDER VALUE
                case IDD_START: {
                printf(" asdaksda");
                HINSTANCE newWindowIns;
                int returnINTValue = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_IMUSTARDSOFT_DIALOG), newWindow, ABDialogProc);               
                if(returnINTValue == IDOK){
                     MessageBox(newWindow, "Dialog exited with IDOK.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
                }
                else if(returnINTValue == IDCANCEL){
                    MessageBox(newWindow, "Dialog exited with IDCANCEL.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
                }
                else if(returnINTValue == -1){
                    MessageBox(newWindow, "Dialog failed!", "Error",
                    MB_OK | MB_ICONINFORMATION);
                    GetLastError();
                }
                }
                break;
                case IDD_WOW:
                    MessageBox(newWindow, "THE NAME", "THE TITLE", MB_ICONHAND);
                    break;

                default: {
                    printf(" asda");
                    break;
                }
            }
            break;
        default:
            return DefWindowProc(newWindow, msg, wparam, lparam);
        break;
    }

}

char classNameofTheNewWnd[] = "StartNewClass";

int WINAPI WinMain(HINSTANCE newWindowIns, HINSTANCE newPREVwindowIns, LPSTR dontknowthis, int nCommandShow){
    HWND newWindow;
    WNDCLASSEX windowclass;

    windowclass.cbSize = sizeof(WNDCLASSEX);
    windowclass.style = 0;
    windowclass.lpfnWndProc = newStartCallback;
    windowclass.hIcon = (HICON)(LoadImage(GetModuleHandle(NULL), THEICON, IMAGE_ICON, LR_DEFAULTSIZE, LR_DEFAULTSIZE, LR_LOADFROMFILE));  //
    windowclass.hIconSm = LoadIcon(GetModuleHandle(NULL), THEICON);          //turned to GetModuleHandle(NULL) from plain NULL                                                                     // THESE ARE THE ICONS LETS SEE WHICH ONE WORKS NOW :))))
    windowclass.lpszMenuName = NULL;
    windowclass.lpszClassName = classNameofTheNewWnd;
    windowclass.hbrBackground = (HBRUSH)(COLOR_WINDOW-2);
    windowclass.cbWndExtra = 0;
    windowclass.cbClsExtra = 0;
    windowclass.hInstance = newWindowIns;
    windowclass.hCursor = LoadCursor(NULL, IDC_CROSS);

    if(!RegisterClassEx(&windowclass)){
        printf("no");
    }
    newWindow = CreateWindowEx(WS_EX_CLIENTEDGE, classNameofTheNewWnd, "Start Something New", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1200, 550, NULL, NULL, newWindowIns, NULL);
    ShowWindow(newWindow, nCommandShow);

    MSG message;

    printf("%d", utur);
    while(GetMessage(&message, NULL, 0, 0) > 0){ //don't forget to compare here..... if it is more than 0 then it means there is a new message!!!! :D
        DispatchMessage(&message);
    }
    printf("message.wParam");
    return message.wParam;
}

0 个答案:

没有答案